Skip to navigation

Coding agent API key: Cline, Cursor, Codex, Aider

In short: Set up one coding agent API key for Cline, Cursor, Codex CLI, Aider, OpenCode, Zed and Claude Code, with base URLs, spend caps and a cost check.

Published 18 min read
On this page

A coding agent API key is an ordinary key plus a base URL: the agent sends its requests to your gateway instead of the vendor, and every token is billed against the balance behind that key. On One AI API Key that means the same key works in Cline, Cursor, Codex CLI, Aider, OpenCode, Kilo Code, Zed and, through the Anthropic format, Claude Code. The part that takes judgment is not the setup, which is about five minutes per tool, but how you cap what an agent can spend.

What does a coding agent actually need from an API?

Four things, and none of them is exotic. A base URL it can be told to use. A key that authorizes the call. A model id the endpoint recognizes. And, for agents, tool calling, which is how the model asks the editor to read a file or run a command. If the model you pick does not support tool calls, the agent may run but cannot act, so the capabilities listed on each model page matter more here than they do in chat.

Agents also behave differently from chat in cost. A chat message is one request. A single agent task is a loop of many: read files, plan, edit, run tests, read the output, edit again, and each turn resends a growing context. That is why the token total of an agent session is often far larger than the text you typed would suggest, and why prompt caching, covered in the prompt caching reference, is worth understanding before a long session. The glossary of tokens, context windows and caching defines the terms used below.

Last, an agent is a program that holds your key and runs unattended for minutes. That changes the security question from “who can see my screen” to “what can this process spend”. The rest of this guide is organised around that: connect the tool, cap the key, watch the spend.

How does the agent reach the gateway?

The diagram is the same for every tool. The only things that change from one tool to the next are the field names where you type the base URL and key.

Agent, key, gateway, model

Agent reads its settingsbase URL, key and model idRequest carries your keysent as a Bearer tokenGateway applies key limitsspend cap, allowlist, rate limitModel provider answersstreamed back to the agent
The agent never needs to know which provider answers. The gateway retries the named model up to twice, and if it still fails, fallback rules, presets and automatic routing move the request to a similar model. Only the attempt that answers is billed.

Two details are worth keeping in mind. First, the key is the only thing the agent holds, so the key’s limits are your real safety net: a spend limit is enforced before the call is sent upstream, not after. Second, the model id you type is the whole routing instruction. If it is misspelled, you get a model-not-found error, and the errors reference shows the exact code. A third detail helps agents specifically: when the model you named fails, the gateway retries it up to twice, and if it is still failing, fallback rules, presets and automatic routing switch the request to another similar model, so a brief provider fault does not end your task. Most coding tools cannot send custom headers, so set a fallback model for every request in the console under Models and Routing; the uptime and fallback guide explains the order and what it does to your odds.

How do you set up each tool?

The tabs below show the minimum for the tools that use a config file or environment variable. Replace your-model-id with a real id from the models page or the free ids list. Each tool also has a longer guide with troubleshooting: Claude Code, Codex CLI, Cursor, Cline, Kilo Code, OpenCode, Aider and Zed.

// ~/.claude/settings.json  (user file, never the committed project file)
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.oneaiapikey.com",
    "ANTHROPIC_AUTH_TOKEN": "sk-your-key-here"
  }
}
// no trailing /v1 on this one: Claude Code adds /v1/messages itself
# ~/.codex/config.toml
model = "your-model-id"
model_provider = "oneaiapikey"

[model_providers.oneaiapikey]
name = "One AI API Key"
base_url = "https://api.oneaiapikey.com/v1"
env_key = "ONEAIAPIKEY_API_KEY"
wire_api = "responses"
# the key itself lives in the ONEAIAPIKEY_API_KEY environment variable, never in this file
export OPENAI_API_BASE=https://api.oneaiapikey.com/v1
export OPENAI_API_KEY=sk-your-key-here

# the openai/ prefix makes Aider send OpenAI-format calls to the base above
aider --model openai/your-model-id
{
  "$schema": "https://opencode.ai/config.json",
  "model": "oneaiapikey/your-model-id",
  "provider": {
    "oneaiapikey": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "One AI API Key",
      "options": {
        "baseURL": "https://api.oneaiapikey.com/v1",
        "apiKey": "{env:ONEAIAPIKEY_API_KEY}"
      },
      "models": { "your-model-id": { "name": "Your model" } }
    }
  }
}
Cline (VS Code)
  API Provider:  OpenAI Compatible
  Base URL:      https://api.oneaiapikey.com/v1
  API Key:       sk-your-key-here
  Model ID:      your-model-id

Cursor (Settings > Models)
  OpenAI API Key:           on, paste sk-your-key-here
  Override OpenAI Base URL: on, https://api.oneaiapikey.com/v1
  Add Custom Model:         your-model-id

Kilo Code (Settings > Providers > Custom provider)
  Provider API:  OpenAI Compatible
  Base URL:      https://api.oneaiapikey.com/v1
  API key:       sk-your-key-here
{
  "language_models": {
    "openai_compatible": {
      "One AI API Key": {
        "api_url": "https://api.oneaiapikey.com/v1",
        "available_models": [
          { "name": "your-model-id", "display_name": "Your model", "max_tokens": 128000 }
        ]
      }
    }
  }
}

A few lines in those samples are traps worth naming.

  • The /v1 rule differs by format. OpenAI-format tools want /v1 in the base URL. Claude Code wants none, because it appends /v1/messages itself. Getting this wrong is the top cause of a 404 on first run.
  • Codex needs the Responses format. The wire_api = "responses" line selects it. Older write-ups still show a chat setting that current Codex releases have retired, so copy from the Codex guide, which tracks the current config.
  • Aider needs the openai/ prefix. Without it Aider tries to reach a vendor directly instead of your base URL.
  • Cursor’s override is global. Bring-your-own-key in Cursor covers local Chat and Agent requests. Tab completion and Cursor’s own cloud features keep using Cursor’s infrastructure, and the base URL override is one switch for every OpenAI-family request, so turn it off when you want your Cursor plan’s models again.
  • Claude Code serves Claude models only. On the Anthropic route you get Claude ids, which are priced models, and no free ids. Everything else on this page can use any model the gateway serves.

Each tool’s own documentation is the authority on its field names, and they do change between releases: see the Cline docs, the Cursor docs, the Codex CLI repository, Aider’s page on OpenAI-compatible APIs and OpenCode’s provider setup. If a field in the tool no longer matches the sample above, trust the tool’s docs for the name and keep our base URL and key.

The config generator writes several of these files for you from a model id and key name, which saves typing the same block into each tool. For the underlying API shape behind them all, see the OpenAI versus Anthropic compatibility guide, and for a single SDK app rather than an agent, the base URL switch guide.

Which tools use which format?

A short table helps when you are setting up several at once. The format decides the base URL, and the base URL is where most mistakes happen.

Tool Kind Format Base URL to enter Key goes in
Claude Code CLI Anthropic Messages https://api.oneaiapikey.com ANTHROPIC_AUTH_TOKEN
Codex CLI CLI OpenAI Responses https://api.oneaiapikey.com/v1 env var named in env_key
Aider CLI OpenAI chat https://api.oneaiapikey.com/v1 OPENAI_API_KEY
OpenCode CLI OpenAI chat (AI SDK) https://api.oneaiapikey.com/v1 /connect or apiKey env reference
Cline VS Code extension OpenAI chat https://api.oneaiapikey.com/v1 provider settings field
Kilo Code VS Code and CLI OpenAI chat https://api.oneaiapikey.com/v1 provider settings or env reference
Cursor Editor OpenAI chat https://api.oneaiapikey.com/v1 OpenAI API Key setting
Zed Editor OpenAI chat https://api.oneaiapikey.com/v1 environment variable

The Anthropic Messages reference and the Responses reference describe the two less common formats, and the chat completions reference covers the common one. If a tool is not on the list but lets you set an OpenAI base URL, it will almost certainly work the same way as Aider or Cline.

How many requests does an agent really use?

This is the question the free lane makes concrete. Free ids work with a $0 balance: no top-up, no card, and they keep working after the sign-up credit is spent. The only limit is the shared allowance of 100 requests and 3,000,000 tokens a day, refilled at 00:00 UTC, and an agent task is many requests. Enter your own pattern and see whether it fits, and what it costs if you move to a priced model. The two rate fields start at $1 and $3 per million tokens as placeholders: replace them with the real rates from the models page for the model you plan to use, because this calculator invents no price.

Agent usage and cost check

Requests per day
150
Tokens per day
2,805,000
Fits the free lane today?
No, over the request cap
Cost per day on a priced model
$3.02
Cost per 22 working days
$66.33
Days the $10 credit lasts
3.3 days

The defaults are an example pattern, not a measurement of any tool. Real agents vary widely with context size and task type; read your own usage page after a day and enter what you see. Prompt caching can lower the input side, see the caching reference.

With the defaults, six tasks of 25 requests is 150 requests a day, which is over the free lane’s request cap before tokens even matter. That is the typical result, and it is why we describe the free lane as a way to learn a tool and test models, not as a free workday. Light use, like a few small edits and some questions, fits comfortably. An agent that works all day will exhaust the 100 requests fast and then wait for the 00:00 UTC refill, since free ids need no balance but have no way past the cap. Heavy agent use needs a balance on a priced model, and the pricing page says how credit is added today (by email, from $1). If the other free tiers interest you, the free LLM API comparison sets our cap against theirs. The monthly cost guide turns the same token counts into a budget, and the cost calculator does it for any model in the list.

Daily request budget, free lane against the example pattern

  • Free lane daily cap100shared by 47 models
  • Light use: 2 tasks of 10 requests20
  • Example pattern: 6 tasks of 25 requests150
  • Heavy use: 10 tasks of 40 requests400
Request counts per task are illustrative. Measure your own on the usage page: it shows one row per request, so a day of work tells you the real number.

How do you cap what an agent can spend?

The most useful five minutes in this whole setup is on the key page, not in the tool. The console key page lets you set limits per key, described in the cost control reference.

  1. A spend limit. Set it to what you would be comfortable losing to a bug: five or ten dollars for a new tool, more for one you trust. When the key reaches it, requests stop.
  2. A model allowlist. Restrict the key to the ids you chose. A misconfigured tool cannot fall back to an expensive model you did not pick.
  3. A requests-per-minute limit. A runaway loop usually shows up as a burst, and a rate limit turns a burst into a slow trickle you can notice.
  4. An expiry date. Keys for a trial, a contractor or a demo should die on schedule.
  5. Low-balance alerts. Email and signed webhooks warn you before the balance runs out mid-task, see the alerts guide.

These caps matter more than usual because of how money works here. Credit is for an online product, and our policy is plain: once a key is created and usage is consumed we do not give money back, and an agent loop that runs away is consumed usage. The exception is a key that does not work or a technical problem on our side: write to support at somdutt777@gmail.com with a genuine concern, and exceptions are decided case by case. The terms are the policy page, and the guide to money-back policies says what to compare anywhere you pay. A spend limit is the protection you control, and the prepaid credits guide explains how balances, reservations and caps interact while a long request is running. If you add credit, the gateway fee comparison shows what other services charge on top.

Then use one key per tool. If Cline misbehaves, you revoke the Cline key and Cursor keeps working. The usage page shows spend per key, which also answers the question every team eventually asks: which tool costs the most? The one key per project guide goes into the layout.

How do you keep the key out of git?

Agents make this easy to get wrong because their config files sit in project folders. Three habits cover most of it, and they match the twelve-factor rule of keeping credentials in the environment, not in code.

Keep the key in an environment variable or in the tool’s user-level settings file. Claude Code’s guide is explicit: never put the key in a project’s committed settings file, use the user-level file instead. Aider’s guide says the same about .aider.conf.yml. Codex avoids the problem by design, since config.toml names an environment variable instead of holding the key. OpenCode stores a /connect credential outside the project in its own auth file.

Add the config files that could hold a key to .gitignore before you create them. And turn on secret scanning where your code lives: GitHub’s secret scanning detects many token formats in pushed commits, and it is a backstop, not a plan. If a key does leak, delete it in the console and create another; the key security guide lists the steps in order. Account-level protections are in account security.

Is the code an agent sends stored?

An agent sends file contents and command output as part of every request, so this is a fair question. By default what you send is not stored: prompts and answers pass through and are not kept. We keep counts (tokens, cost, timing, model, key name, request id), never content, we do not train on your data, and protecting it is our top priority. The qualifiers matter too. Prompt logging is an opt-in per key, X-No-Log: true opts one call out, content is captured only if you ask us to troubleshoot a request or we investigate abuse, and the upstream provider that runs the model processes the request under its own terms. The privacy guide lists what to ask any gateway, and the honest review of One AI API Key shows how we apply the same questions to ourselves.

Which model should an agent use?

Pick by task, not by habit. A strong model plans well and needs fewer retries. A cheap model is fine for bulk edits, renames and test fixes. Most people end up with two: a stronger one for planning and hard bugs, and a cheaper one for routine work. Cline and Kilo Code let you set a different model per mode, Aider has a separate weak model for chores, and Claude Code has three model slots.

The model choice guide for coding agents goes through the trade-offs in detail, and the best frontier models post compares the current top models. If you are watching cost, the cheap open model prices post lists the lower-cost end, and the cost reduction guide covers caching and routing tactics that matter more for agents than for chat. The models comparison page lines up capabilities side by side, and the rankings page shows what other people actually call. If an agent’s answers suddenly get worse on a cheap route, run the six tests in the guide to verifying an API serves the real model, and read the reseller risks guide before you trust a price that looks too good.

If you want to try before you spend, the free lane works well for learning a tool’s workflow, and you can try a prompt first in the browser chat (see the chat guide). Send the same small task to two or three of the 47 free ids from the free ids list, compare how each handles tool calls, and then decide what is worth paying for. The free model guide sorts the ids by capability.

What goes wrong most often?

The same handful of problems cause most failed setups, in this order.

A 401 after setup. The key has a stray space or quote, was revoked, or sits in a variable the tool process cannot see. Editors launched from a dock or start menu often miss variables you exported in a terminal, so put the value in the tool’s own settings when a terminal export is not enough.

A 404 on every request. The /v1 rule above. Compare your base URL with the table in this guide.

Model not found. The id has a typo or a case difference. Copy it from the models page rather than retyping, and note that free ids end in :free.

A 429 that will not clear. If it clears after a minute, you hit a burst limit. If it persists until tomorrow, you hit the daily cap. The 429 guide shows both, and the rate limits reference says where each limit comes from.

A stalled stream. Agents stream by default, which keeps long generations alive. If you call the API yourself, send "stream": true for long outputs, as the streaming guide explains.

A bill larger than expected. Open Usage, sort by tokens, and look at the biggest requests. A huge context sent on every turn is the usual cause. The fix is a tighter context, a cached prefix or a cheaper model for that step, in that order.

A checklist before you let an agent run unattended

Tick what is true for your setup. It is a short list because each line prevents a specific, common failure.

Agent safety check

0 of 8 done

Not ready

Do the first three lines before anything else. They take under five minutes and cover most of the risk.

When the checklist is green, the main risk left is the choice of model, not the setup. The 12-point provider checklist covers the questions to ask before you depend on any provider, ours included, and the LLM gateway explainer describes what sits between your agent and the model. The transparency page says what we monitor and what we cannot promise, including that there is no uptime guarantee. The gateway’s retries and automatic switching help, but for work you cannot pause also keep a second path ready. If you are comparing services first, the OpenRouter alternatives post lines up seven gateways, and the LiteLLM comparison shows what self-hosting your own gateway for agents would cost in time.

Create a key and connect your first agent

Sign in with Google, create a key, and set a spend limit. You get $10 of sign-up credit for priced models and 47 free models sharing 100 requests and 3,000,000 tokens a day, with no card.

Frequently asked questions

Can I use one API key for Cline, Cursor, Codex CLI and Aider at the same time?
You can, but one key per tool is better. Every key can carry its own spend limit, expiry and model allowlist, so a loop in one tool cannot spend the balance the others need. The one key per project guide shows the layout, and the key page is where you set the limits.
Do the free models work in coding agents?
Some do, within limits. Free ids work with a $0 balance, with no top-up and no card, and they keep working after the sign-up credit is spent. The 47 free ids share 100 requests and 3,000,000 tokens a day, and an agent sends many requests per task, so the daily request cap is usually the first wall. Tool calling also differs by model, so check the capabilities on the free models page before pointing an agent at one. The free model guide sorts them by capability.
Which base URL does each tool need?
OpenAI-format tools (Cline, Cursor, Codex CLI, Aider, OpenCode, Kilo Code, Zed) use https://api.oneaiapikey.com/v1, with /v1. Claude Code uses the Anthropic format at https://api.oneaiapikey.com, without /v1. The tool guides give each tool's exact field names, and the migration guide covers the usual base URL mistakes.
Why does my agent get a 404 right after setup?
Almost always a doubled or missing /v1. OpenAI-format tools add /chat/completions or /responses to the base you give them, so a base that already ends in an endpoint path is wrong, and a base without /v1 points at a path that does not exist. The error reference lists the codes, and the quickstart shows a working call to compare against.
How do I stop an agent from spending too much?
Give it its own key with a spend limit, set a requests-per-minute limit, and turn on low-balance alerts. A key that hits its limit stops, and the rest of your balance is untouched. See cost control and the guide to reducing LLM API costs for the tactics that cut agent bills most.
What happens when I hit a 429 in the middle of an agent task?
The agent usually retries, and a daily-cap 429 will keep failing until the counter refills at 00:00 UTC. A burst 429 clears after a short wait. The 429 guide shows how to tell them apart and how to set a sensible retry schedule.
Is it safe to paste an API key into a coding agent?
It is as safe as the place the key is stored. Keep it in an environment variable or the tool's user-level settings, never in a file that is committed to git, and rotate it if it leaks. The key security guide covers storage and rotation, and account security covers the account itself.
Can I run Claude Code against this gateway?
Yes, through the Anthropic format. Set ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN as the Claude Code guide describes. That route serves Claude models only and they are priced models, not part of the free lane. The older custom base URL post has the background.
More in Blog

Try it

One API key for GPT, Grok, DeepSeek, Kimi, GLM, MiniMax, Qwen, Step, Beam, Nemotron, ERNIE, Hunyuan, Gemma, Laguna, LFM, LongCat, Llama, Solar, Jais, Mistral, K2 and Roleplay.

One AI API Key speaks the OpenAI and Anthropic formats, so you change the base URL and the key, not your code. Credit packs start at $10, and every model has a published per-token rate.

New accounts$10 credit on sign-up
  • 100requests
    per day
  • 3Mtokens
    per day
  • 47free
    models
  • $0per
    token
  • No card
  • No end date
Claim $10 credit →