Subscription vs API key for coding agents
By Flavio
A subscription includes an allowance; an API key connects usage to a provider account. See how coding agents handle the two and avoid billing surprises.
A subscription gives you access under a plan’s usage rules. An API key is a secret credential that connects requests to a provider account, where usage-based billing can apply.
For the setup walkthrough, read How to use a coding agent without another subscription. This entry explains the billing choice before you connect an account.
How the choice works
Your authentication method decides which account handles model requests, since a paid chat subscription and a pay-as-you-go API account can bill separately.
Subscription and API keys in each tool
Claude Code
Claude Code authenticates via a Claude account, Claude Console, or ANTHROPIC_API_KEY (with approval when prompted), so verify the active account before long runs. See Authentication.
OpenAI Codex
Locally, Codex accepts ChatGPT subscription sign-in or usage-billed API keys (Codex cloud requires ChatGPT sign-in), and your auth choice also determines which org’s data settings apply. See Authentication.
Cursor
Add custom provider keys under Settings -> Models for chat models (Tab still runs on Cursor’s models), checking individual vs team rules in Bring your own API key.
Grok Build
Grok Build opens a browser for authentication on first launch. Its overview also documents XAI_API_KEY for environments without a browser. Check the billing rules for your sign-in method. See Grok Build.
Details checked against each vendor’s documentation in November 2026.
A real example
Before connecting Codex to this site’s repository, give the agent this bounded request:
Explain the difference between ChatGPT sign-in and API-key access
for local Codex work. Link the official authentication documentation.
Do not read credentials or change my authentication settings.
Then select the method yourself in the tool’s sign-in flow. Keep the key out of the prompt, source files, and screenshots.
When to use each
Use a supported subscription sign-in when you want tasks charged against that plan’s allowance. Use API access when you need a provider account’s usage billing and controls. Compare actual task usage before deciding which costs less.
Pitfalls
An API key authorizes requests within its permissions. Store it through the tool’s credential setup and revoke it if exposed.
A key changes data handling too: Cursor’s Zero Data Retention policy doesn’t cover requests sent with your own keys, so the chosen provider’s policy applies instead.
Related on flaviocopes.com
- Sign in with ChatGPT in other apps covers supported subscription connections.
- Coding without another subscription compares hosted and local models.
- Searchglass uses its own Google login for Search Console. A coding agent’s model key doesn’t grant access to your analytics.
Related glossary entries
- Tokens and usage limits: A token is the unit a model reads and writes. A usage limit is how much of that work a plan includes. How Claude Code, Codex, Cursor and Grok count it.
- Coding agent: A coding agent uses a model and tools to read a repo, edit files and run commands in a loop. How Claude Code, Codex, Cursor and Grok Build each do that job.
All AI glossary entries → · AI for coding hub →
Want me to talk about your product? You can sponsor this site.