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
The agent sends requests to a model provider. Your authentication method determines which account handles those requests. A paid chat plan and an API account can have separate billing.
Subscription and API keys in each tool
Claude Code
Claude Code supports signing in through a Claude account or the Claude Console. It also accepts an ANTHROPIC_API_KEY environment variable, with approval when prompted. Check which account you selected before starting a long task. See Authentication.
OpenAI Codex
For local work, Codex supports ChatGPT sign-in for subscription access and API keys for usage-based access. Codex cloud requires ChatGPT sign-in. The authentication method also affects which organization’s data-handling settings apply. See Authentication.
Cursor
Cursor lets you add provider keys in Settings, under Models. Custom keys work with chat models; Tab completion uses Cursor’s built-in models. Individual and team plans treat own-key usage differently, so read the plan-specific rules. See 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 can change data handling too. Cursor says its Zero Data Retention policy does not apply to requests using your own keys; the chosen provider’s policy applies.
Related on flaviocopes.com
- Sign in with ChatGPT in other apps explains supported subscription connections.
- Coding without another subscription walks through 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.
Want me to talk about your product? You can sponsor this site.