Amazon Ergo in opencode
opencode talks to any OpenAI-compatible endpoint through the @ai-sdk/openai-compatible package, which is how Amazon Ergo plugs in. Below is a working opencode.json for our hosted ergo-1.0 endpoint, the limit block you should not leave out, and a short note on the OpenRouter route.
Every example needs an ergo_live_ API key with prepaid credit (from $5). Get an API key →
Amazon describes Ergo as an open-weight model built for agentic coding and long-running tasks, and a terminal agent is the obvious place to try it. For opencode the setup is a custom provider entry: AWS documents the same @ai-sdk/openai-compatible package for its Bedrock endpoint, and it works unchanged against ours. You need three values: the base URL https://ergomodel.net/api/v1, an ergo_live_ key and the model id ergo-1.0.
Ergo Model is an independent hosted API, not run by Amazon or AWS. You get one key, card payment and no AWS account; pricing is $1.50 per 1M input tokens and $4.50 per 1M output tokens, prepaid from $5.
1. Get a key
Create a key at /get-api-key, add credit, and export it. The config below reads it from the environment, so the secret stays out of your repo.
export ERGO_API_KEY=ergo_live_...2. Add the provider to opencode.json
Put this in opencode.json in your project root, or in your global opencode config:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"ergo": {
"npm": "@ai-sdk/openai-compatible",
"name": "Ergo Model",
"options": {
"baseURL": "https://ergomodel.net/api/v1",
"apiKey": "{env:ERGO_API_KEY}"
},
"models": {
"ergo-1.0": {
"name": "Amazon Ergo 1.0",
"limit": { "context": 1048576, "output": 131072 }
}
}
}
},
"model": "ergo/ergo-1.0"
}Restart opencode. The model appears as ergo/ergo-1.0 and every request goes to POST https://ergomodel.net/api/v1/chat/completions.
Keep the limit block
opencode cannot look up the limits of a custom model it has never heard of. Without the limit block it assumes a much smaller context window, starts compacting the session far too early and never uses the space the model has. Setting context to 1048576 and output to 131072 tells it the real numbers: a 1M-token window and up to 131,072 output tokens.
Reasoning and output budget
Ergo always reasons before it answers; this cannot be turned off. Reasoning tokens are taken from max_tokens and billed as output. opencode sets the output budget itself from the limit block, so inside the agent you rarely need to think about it. If you script against the same endpoint, set max_tokens to at least 2,048: a small cap such as 300 comes back with empty content and finish_reason "length".
Working with it in opencode
- Load more of the repo. With a 1,048,576-token window the agent can keep many files in view at once. Input is billed per token, so a 100,000-token prompt costs $0.15 each time it is sent.
- Text only. The model has no image input, so screenshots attached in opencode are not read.
- Tool calls and structured outputs are forwarded as-is, which is what opencode's edit and shell tools rely on.
- The rate limit is 30 requests per minute per key. If a fast loop reaches it, the API returns 429 with a Retry-After header.
- When the balance reaches zero the API returns 402 insufficient_credits with a top-up link. There is no subscription.
Alternative: opencode through OpenRouter
opencode also has a built-in OpenRouter provider. If you already hold an OpenRouter key, run opencode auth login, choose OpenRouter and select amazon/ergo-1.0. That route is cheaper per token (about $1 in / $3 out per 1M) but one provider there caps context at 262K, so check which provider serves your requests before relying on the full window. The OpenRouter guide covers the details.
Which route to pick
Bedrock and OpenRouter cost less per token and we say so plainly. The hosted key on this site is for people who want Amazon Ergo in opencode within a couple of minutes: no AWS account, no provider routing to tune, and requests pinned to providers that serve the full 1M context.
FAQ
How do I set up Amazon Ergo in opencode?
Add a custom provider to opencode.json with npm "@ai-sdk/openai-compatible", baseURL https://ergomodel.net/api/v1, apiKey "{env:ERGO_API_KEY}" and a model named ergo-1.0 with limit { context: 1048576, output: 131072 }. Then set "model": "ergo/ergo-1.0".
Why does opencode need the limit block?
For an unknown custom model opencode cannot discover the context window, so it assumes a much smaller one and compacts early. The limit block gives it the real figures: 1,048,576 tokens of context and 131,072 tokens of output.
What is the model id?
ergo-1.0 on our endpoint (written ergo/ergo-1.0 inside opencode, because the provider id comes first). On OpenRouter the id is amazon/ergo-1.0.
What does Amazon Ergo cost in opencode?
Through our hosted API it is $1.50 per 1M input tokens and $4.50 per 1M output tokens, prepaid from $5, with reasoning tokens counted as output. OpenRouter and Amazon Bedrock list lower per-token prices but need their own accounts.
Can it read images in opencode?
No. The model is text in, text out.
See also: Get an API key · OpenRouter guide · Context window · How to call the API
Start using Amazon Ergo
Try the model in the free browser playground first, then create a key and add it to your setup.