My AI agents burn through API credits

Short answerMove the routine agent steps to cheaper open models. Lyceum serves them through one OpenAI-compatible API, billed per token with no base fee, and repeated prompt starts are billed at a cached input price where one is listed. A gateway with budgets per key adds a second brake. Free basics: a hard spend limit, a max-steps cap, smaller models for sub-agents and shorter tool outputs.

01

Point your agent framework at Lyceum's OpenAI-compatible API

Lyceum serves open models through one OpenAI-compatible API, billed per token with no base fee. Any agent framework that accepts an OpenAI-compatible base URL can use it: you set the base URL, your API key and a model ID, and n8n is among the tools Lyceum lists. The model library shows an input, cached input and output price per model, and repeated prompt starts are billed at the cached input price where one is listed, which suits agents that resend the same context on every step.

Good if your agents run routine steps that do not need a premium closed model

Skip if a task only works on the model you use today

Serverless and dedicated inference · Model library and inference pricing

Tool
Cost€
EffortLow
HelpsToday
02

Run Claude Code on open models through Lyceum

If your agent is Claude Code, point it at Lyceum's Anthropic-compatible endpoint and choose a supported open model. You set the base URL, your Lyceum API key and the model ID as environment variables, and Claude Code works as before. The same key also works for Codex and OpenCode through the OpenAI-compatible API.

Good if most of your agent spend comes from coding sessions

Lyceum

Tool
Cost€
EffortLow
HelpsToday
03

Put a gateway with budgets in front of your agents

LiteLLM is an open-source gateway that tracks spend per key, user and team and can stop requests once a budget is used up. Give each agent or workflow its own key with its own budget, and set a reset period such as 30 days. Budgets only work with a connected database, without one they cap nothing.

Good if several agents or workflows share one provider account

Skip if you run a single agent with one key

Budgets, Rate Limits · Spend Tracking

Tool
CostFree
EffortMedium
HelpsThis week
04

Set a hard spend limit with your provider

Anthropic lets you set your own monthly spend limit below your tier's cap on the Billing page in the Claude Console. Requests stop when the limit is reached, so a runaway agent cannot keep spending. Put agents in their own workspace and give that workspace its own limits.

Good if an agent runs unattended overnight or on a schedule

Anthropic

Do it yourself
CostFree
EffortLow
HelpsToday
05

Stop loops with a max-steps limit

Cap how often the model may run in one task. In n8n's AI Agent node it is called Max Iterations and defaults to 10. In the OpenAI Agents SDK you pass max_turns, and the run ends with a MaxTurnsExceeded error when the agent goes past it. Set the cap low and raise it only for tasks that really need more steps.

Good if an agent sometimes calls the same tool again and again

n8n Docs · OpenAI Agents SDK

Do it yourself
CostFree
EffortLow
HelpsToday
06

Give sub-agents a smaller model than the planner

Let the planning agent use the strong model and hand searches, lookups and summaries to sub-agents on a smaller one. In Claude Code you set a model field per subagent, and Anthropic names routing tasks to faster, lower-cost models like Haiku as a way to control costs. Run the same tasks both ways and keep the cheaper setup where the results hold.

Good if one premium model does every step, including simple lookups

Claude Code Docs

Do it yourself
CostFree
EffortMedium
HelpsThis week
07

Shorten tool outputs before they go back into context

In an agent loop, tool results are appended to the input and the model runs again, so a long result travels along on every following step. Anthropic suggests pagination, range selection, filtering or truncation with sensible defaults for any tool response that could use up lots of context, and Claude Code limits tool responses to 25,000 tokens by default. Return only the fields the agent needs, not the full API response or page.

Good if your tools return whole web pages, files or database dumps

Anthropic Engineering · OpenAI Agents SDK

Do it yourself
CostFree
EffortMedium
HelpsThis week
08

Put the context that repeats at the start and cache it

Agents send the same system prompt and tool definitions on every step. Put that stable part first and anything that changes at the end, then turn on prompt caching. On Anthropic you mark the cached part with cache_control, and cache hits are billed at a fraction of the normal input price.

Good if every step starts with the same long instructions and tool list

Skip if your prompts are short and change every time

Anthropic

Do it yourself
CostFree
EffortMedium
HelpsThis week
09

Log tokens per task to find the expensive step

Give each agent or workflow its own API key, then split usage by key. Anthropic's Usage and Cost API filters and groups by API key, workspace and model, and tracks uncached input, cached input and output tokens. In LiteLLM, a separate key per workflow step shows the spend of that step.

Good if you know the monthly total but not which agent or step drives it

Anthropic · LiteLLM

Do it yourself
CostFree
EffortLow
HelpsThis week

When it's bigger than a quick fix

Get help when the spend still grows after these limits, or when nobody can say which agent or workflow drives it. Bring the usage split by key and model to whoever owns the budget, and agree a monthly limit per agent.

If spend jumps with no new traffic, treat it as a runaway loop or a leaked key. Stop the workflow, deactivate the key, create a new one and set a spend limit with your provider today.

Rate limits · Usage and Cost API · API key best practices, keep your keys safe and secure

Questions people ask

What is the cheapest LLM for agents?

It depends on the model and on how much context your agent resends, and prices change often. Compare input, cached input and output prices on each provider's own pricing page on the day you decide, and test the model on a sample of your real tasks.

Why do AI agents use so many tokens?

An agent runs in a loop: after every tool call the result is appended to the context and the model runs again. Long tool outputs use up context on every step that follows.

How do I limit how much an AI agent can spend?

Set a monthly spend limit with your provider, give each agent its own key with a budget in a gateway, and cap the number of steps per task.

How many iterations should an AI agent get?

n8n's AI Agent node defaults to 10. Start low and raise the limit only for tasks that fail because they run out of steps.

Does prompt caching work for agents?

Yes, when every step starts with the same system prompt and tool definitions. Keep that part first and stable, and put what changes at the end.

Sources

  1. Lyceum: Serverless and dedicated inference
  2. Lyceum: Model library and inference pricing
  3. LiteLLM: Budgets, Rate Limits
  4. LiteLLM: Spend Tracking
  5. Anthropic: Rate limits
  6. n8n Docs: Tools Agent node
  7. OpenAI Agents SDK: Running agents
  8. Claude Code Docs: Create custom subagents
  9. Anthropic Engineering: Writing effective tools for AI agents
  10. Anthropic: Prompt caching
  11. Anthropic: Usage and Cost API
  12. Anthropic: API key best practices, keep your keys safe and secure