How an agent calls any model through the account, puts a ceiling on what a call can cost, gets large answers as files, and how you read what was used. What the service is and what it costs is on Services.
Ask a small model to summarise this page in three sentences.From an AI client the tool is stack_call_openrouter. It reaches any model and endpoint OpenRouter has. From code or the terminal:
const answer = await stack.llm.openrouter.chat.completions.create({
model: 'openai/gpt-4o-mini',
messages: [{ role: 'user', content: 'Summarise this page in three sentences.' }],
}, { passport, maxCostCents: 5 });npx @getstackrun/cli llm openrouter chat-completions \
'{"model":"openai/gpt-4o-mini","messages":[{"role":"user","content":"Hi"}]}'Before a call, STACK holds the most it could cost from your credit. Afterwards it charges what the provider reports and gives the rest back. A ceiling lowers what is held:
Through the tool, an answer that is a file, or text over 256 KB, is saved to the agent's drive, and the tool returns the file's id in place of the content. Over the API, send the header X-Stack-Save-Output: drive for the same. From code, stack.llm.openrouter.requestBytes() returns a file directly.
What a model returns is content from outside, and so is a file it makes.
An agent without an account, or a call to Anthropic or OpenAI directly, runs on a key you connect in the Console. The provider bills you, and STACK counts the call as one action.
await stack.llm.anthropic.messages.create(
{ model, max_tokens: 256, messages }, { passport });
await stack.llm.openai.chat.completions.create({ model, messages }, { passport });There is no tool for these two routes. On your own key the cost ceiling is ignored, because STACK holds nothing.
npx @getstackrun/cli llm usage summarystack_llm_usage_list and stack_llm_usage_summary read calls by agent, model and period. From code: stack.llm.usage.list() and stack.llm.usage.summary(). Reading usage is free.
Each call is one action. On STACK's key the model's cost is charged from credit at the provider's price, with no fee from STACK.
Every route is on LLM Gateway. A first call from the terminal is in Make a model call.