June 24, 20264 min readSetupOpenCode

How to use OpenCode through one API

OpenCode is a fast, terminal-based AI coding agent that lives where you already work — your shell. The catch is that great agentic coding needs the right model for the job, and juggling separate accounts, billing pages, and API keys for every provider gets old quickly. AnyModel fixes that: one OpenAI-compatible endpoint and one key give OpenCode access to GPT, Claude, Gemini, DeepSeek, GLM, Kimi, Qwen, and Grok. Want a different model? Change the model id. Nothing else moves.

Why route OpenCode through one API

OpenCode talks to OpenAI-compatible servers out of the box, so it doesn't need to know — or care — which underlying provider answers. That makes a gateway the natural fit:

  • One key, every model. No per-provider signup or separate dashboards.
  • Model switching is a one-field change. The model string is the only thing that varies between, say, a reasoning-heavy refactor and a quick docstring pass.
  • One bill, pay-per-token. No subscription, no minimums, no credit card to start.

You also get a generous free tier: 1,000,000 tokens on signup, rising to a total of 6,000,000 tokens if you link Telegram. That's plenty to wire up OpenCode and run real tasks before spending anything.

The fast path: one-line install

OpenCode is one of the tools AnyModel can configure for you automatically. Grab your key from the dashboard, then run:

bash <(curl -fsSL "https://anymodel.org/i?tool=opencode") <YOUR_API_KEY>

That script points OpenCode at https://anymodel.org/v1 and stores your key in the right place. Open OpenCode afterward and you're ready to pick a model.

The same installer works for other terminal agents — swap the tool name to codex, claude, or hermes if you use those too. They all share the single endpoint and key.

What changed under the hood

If you prefer to understand or verify the config, the setup is just a standard OpenAI-compatible provider:

Setting Value
Base URL https://anymodel.org/v1
API key your AnyModel key
Model any supported id, e.g. a GPT, Claude, or DeepSeek model

Because it's plain OpenAI-compatible config, the same two values (base URL + key) also drop into Cursor, Windsurf, Zed, Cline, Aider, Continue, or the Gemini CLI if you work across several editors. Those clients use the manual setup rather than the one-line installer.

Picking the right model for the task

Half the value of a gateway is being able to experiment cheaply. In practice, teams mix models within a single OpenCode session:

  • A strong reasoning model for architecture decisions and tricky multi-file refactors.
  • A fast, inexpensive model for boilerplate, renames, and test scaffolding.
  • A long-context model when you're feeding in large files or whole directories.

To compare capabilities and pricing before you commit, browse the full model list or put two options side by side on the compare page. Switching is free — just edit the model field in OpenCode's settings and run your next prompt.

A note on privacy

Coding agents send your source code to a model, so it's fair to ask where it goes. AnyModel offers Ghost Mode: opt-in, zero-retention API keys where prompts and responses are not stored on our side — only a token counter for billing. Be clear-eyed about the limit, though: the upstream model provider still receives your prompt to generate a response, so this isn't "100% privacy." It removes our copy, not theirs. For sensitive repositories, Ghost Mode plus a provider you trust is a reasonable combination.

Quick troubleshooting

  • Auth errors? Re-check that the key in OpenCode's config matches your dashboard and that the base URL ends in /v1.
  • Model not found? Copy the exact id from the model list; ids are case- and format-sensitive.
  • Want to confirm it's working? Run a tiny prompt first ("explain this function") before a large agentic task, so you can see the connection succeed cheaply.

For deeper walkthroughs and tips on other tools, the blog has more setup guides.

Get started

Connecting OpenCode to every major model takes about two minutes and zero credit cards. Create your free AnyModel account, copy your key, run the one-liner, and start coding with whichever model fits the task.

Read next