Amazon Ergo runs on Amazon Bedrock from launch day, and the coding agents you already use can drive it. OpenCode and Codex CLI talk to Bedrock’s OpenAI-compatible endpoint directly, while Claude Code needs a small LiteLLM proxy in front, since Ergo has no Anthropic Messages API. We gave all three the same Python repo with two failing tests, and each one fixed both bugs in about 20 seconds for a couple of cents of Bedrock time.
The model was the easy part. AWS’s own IAM policy fails with a Bedrock API key, Codex refuses to start without a region variable, and opencode run hangs over SSH. You get the fix for each below, plus a reasoning-effort test and the Converse API quirks. Every command was run from an Ubuntu 26.04 VM against Ergo 1.0’s global inference profile in eu-west-1 in December 2026.
What you need
Bedrock serves Ergo only through cross-region inference profiles. You pick the region your requests enter through, and AWS routes them to wherever it has capacity. The global.amazon.ergo-1.0 profile works from most commercial regions; us.amazon.ergo-1.0 keeps traffic inside the US at a 10% higher price. Before you start, have these ready:
- An AWS account and an IAM identity that can create users and policies
- The AWS CLI v2 on the machine where you create the key
- Node.js and npm for Codex CLI (we used the Node 22 package Ubuntu 26.04 ships)
- Claude Code and uv for the LiteLLM route, and Python with a current
boto3for the Converse section - A git repository to point the agents at
Ergo costs $1.00 per million input tokens and $3.00 per million output tokens on the global profile, with cached input at $0.03 and cache writes at $1.25. Output is where the money goes, because Ergo always reasons and every reasoning token is billed as output. Amazon’s Ergo model card lists the full price table and the regions that are excluded.
Create a Bedrock API key for Ergo
All three agents authenticate with a Bedrock API key passed as a bearer token, not with SigV4 credentials, so you want a dedicated IAM user whose only job is calling Ergo. The Bedrock console can generate a key too, but the CLI route below lets you scope it to Ergo and nothing else. Create the user first:
aws iam create-user --user-name ergo-coder --query User.Arn --output text
The ARN comes back with your account ID in it:
arn:aws:iam::123456789012:user/ergo-coder
Next comes the policy, and this is where AWS’s own page trips you up twice. The policy on the Ergo coding-tools page grants bedrock:InvokeModel on the Ergo profiles, but a request made with an API key also needs bedrock:CallWithBearerToken, and without it every call fails with an AccessDenied on that action. Fix that and curl works, yet Codex and the LiteLLM proxy still fail, because the Responses API they use checks InvokeModel against a project/default resource the documented policy never lists. Open a policy file:
vim ergo-invoke-policy.json
Paste the two statements below. The first limits invocation to the two Ergo profiles, the base model they route to and the default Responses API project, and the second allows the bearer-token call:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"bedrock:InvokeModel",
"bedrock:InvokeModelWithResponseStream"
],
"Resource": [
"arn:aws:bedrock:*:*:inference-profile/us.amazon.ergo-1.0",
"arn:aws:bedrock:*:*:inference-profile/global.amazon.ergo-1.0",
"arn:aws:bedrock:*::foundation-model/amazon.ergo-1.0",
"arn:aws:bedrock:*:*:project/default"
]
},
{
"Effect": "Allow",
"Action": "bedrock:CallWithBearerToken",
"Resource": "*"
}
]
}
Attach it as an inline policy, then generate the key. A Bedrock API key is an IAM service-specific credential, and --credential-age-days sets when it expires. The secret is shown only once, so write it straight to a file that only your user can read:
aws iam put-user-policy --user-name ergo-coder --policy-name ergo-invoke --policy-document file://ergo-invoke-policy.json
aws iam create-service-specific-credential --user-name ergo-coder --service-name bedrock.amazonaws.com --credential-age-days 30 --query 'ServiceSpecificCredential.ServiceCredentialSecret' --output text > ~/.bedrock-token
chmod 600 ~/.bedrock-token
Every tool in this guide reads your key from AWS_BEARER_TOKEN_BEDROCK, and Codex also insists on AWS_REGION. Export both in your shell profile so new terminals pick them up. Change the region to the one closest to you; the global profile accepts requests from most commercial regions:
echo 'export AWS_BEARER_TOKEN_BEDROCK="$(cat ~/.bedrock-token)"' >> ~/.bashrc
echo 'export AWS_REGION=eu-west-1' >> ~/.bashrc
source ~/.bashrc
Treat that file like a password, because anyone holding the key can run up an Ergo bill until it expires. The scoped policy limits the damage to Ergo. When we asked for Nova Micro with the same key, Bedrock answered not authorized to perform: bedrock:InvokeModel.
Call Ergo with curl
A plain HTTP call proves the key, the policy and the region before any agent adds its own layer of errors. Bedrock exposes Chat Completions at /openai/v1 on the runtime endpoint, and the model name is the inference profile ID, never the bare amazon.ergo-1.0:
curl -s "https://bedrock-runtime.${AWS_REGION}.amazonaws.com/openai/v1/chat/completions" \
-H "Authorization: Bearer ${AWS_BEARER_TOKEN_BEDROCK}" \
-H "Content-Type: application/json" \
-d '{"model":"global.amazon.ergo-1.0","max_tokens":8192,"messages":[{"role":"user","content":"Write a one-line bash command that prints the 5 largest files under /var/log."}]}' | python3 -m json.tool
Look at reasoning_tokens before the answer. Our call returned in 6.5 seconds:
{
"choices": [
{
"finish_reason": "stop",
"index": 0,
"message": {
"annotations": [],
"content": "```bash\nfind /var/log -type f -exec du -h {} + 2>/dev/null | sort -rh | head -n 5\n```",
"refusal": null,
"role": "assistant"
}
}
],
"model": "amazon.ergo-1.0",
"object": "chat.completion",
"service_tier": "default",
"usage": {
"completion_tokens": 1652,
"completion_tokens_details": {
"accepted_prediction_tokens": 0,
"audio_tokens": 0,
"reasoning_tokens": 1616,
"rejected_prediction_tokens": 0
},
"prompt_tokens": 87,
"prompt_tokens_details": {
"audio_tokens": 0,
"cache_write_tokens": 0,
"cached_tokens": 0
},
"total_tokens": 1739
}
}
The answer is 36 tokens long, and Ergo spent 1,616 tokens thinking before it wrote them. That ratio drives your bill. You pay $3 per million for reasoning you never see, so a one-line question costs about half a cent and a real coding turn costs several times that. The reasoning itself is not returned on this endpoint, only its token count. It also means max_tokens has to leave room for that reasoning. At 300 tokens our same prompt came back with "finish_reason": "length" and "content": null, because the budget ran out before the answer started, which is why AWS tells you to set 8,192 or more.
Connect OpenCode to Ergo
OpenCode reaches Bedrock through its generic OpenAI-compatible provider, so the whole setup is one config file. If you have not installed OpenCode yet, the OpenCode install guide for Linux covers it. Open the global config:
mkdir -p ~/.config/opencode
vim ~/.config/opencode/opencode.json
Add the provider. Put your own region in baseURL. We lowered limit.output from the 131,072 on AWS’s page to 32,768, because Bedrock reserves each request’s full output limit against your tokens-per-minute quota, and a fresh account has little quota to spare:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"bedrock-runtime": {
"npm": "@ai-sdk/openai-compatible",
"name": "Amazon Bedrock",
"options": {
"baseURL": "https://bedrock-runtime.eu-west-1.amazonaws.com/openai/v1",
"apiKey": "{env:AWS_BEARER_TOKEN_BEDROCK}"
},
"models": {
"global.amazon.ergo-1.0": {
"name": "Ergo 1.0",
"limit": { "context": 1048568, "output": 32768 },
"options": { "reasoningEffort": "medium" }
}
}
}
},
"model": "bedrock-runtime/global.amazon.ergo-1.0"
}
Our test repo holds a ten-line parse_duration() function with two bugs: it ignores day units and it accepts trailing junk like 5m!!. Two of its four pytest cases fail. Run OpenCode headless against it from inside the repo. The < /dev/null matters if you script this or run it over SSH, because opencode run reads standard input when it isn’t a terminal and our first attempt sat silently for ten minutes waiting for input that never came:
opencode run "Run the test suite with python3 -m pytest -q. Two tests fail. Fix durations.py so all tests pass, without editing the tests, then run the suite again to confirm." < /dev/null
OpenCode ran the tests, read both files, made one edit and re-ran the suite. The whole session took 20.6 seconds:
Fixed `durations.py`: added day support (`d` = 86400s) and full-string validation so trailing junk raises `ValueError`.
`python3 -m pytest -q` now passes: **4 passed**.
The fix was the right one: a d entry in the units table plus a re.fullmatch guard, so 5m!! now raises instead of quietly returning 300. Interactive use works the same way; start opencode in the repo and pick Ergo from /models. The OpenCode CLI cheat sheet lists the other session commands.
Connect Codex CLI to Ergo
Codex talks to Bedrock over the Responses API rather than Chat Completions, which AWS also serves at the same /openai/v1 base URL. Install it from npm, then open its config file:
sudo npm install -g @openai/codex
mkdir -p ~/.codex
vim ~/.codex/config.toml
Add the provider block. Two lines are not optional: web_search = "disabled", because Codex otherwise sends its built-in web search tool and Bedrock rejects it, and wire_api = "responses":
model = "global.amazon.ergo-1.0"
model_provider = "bedrock-runtime"
model_reasoning_effort = "medium"
web_search = "disabled"
model_context_window = 1048568
[model_providers.bedrock-runtime]
name = "Amazon Bedrock"
base_url = "https://bedrock-runtime.eu-west-1.amazonaws.com/openai/v1"
env_key = "AWS_BEARER_TOKEN_BEDROCK"
wire_api = "responses"
Codex reads the region from the environment, not from the URL or your AWS CLI profile. With AWS_REGION unset it dies before sending anything:
ERROR: Fatal error: Amazon Bedrock bearer token auth requires `model_providers.amazon-bedrock.aws.region`, `AWS_REGION`, or `AWS_DEFAULT_REGION`
With the export from earlier in place, run the same task. The current Codex release no longer accepts the --full-auto flag that older guides still show (ours answered error: unexpected argument '--full-auto' found), so give it a workspace-write sandbox instead:
codex exec -s workspace-write "Run the test suite with python3 -m pytest -q. Two tests fail. Fix durations.py so all tests pass, without editing the tests, then run the suite again to confirm." < /dev/null
The header confirms the provider, then Codex warns about missing model metadata. That warning is harmless; Codex has no built-in profile for Ergo and falls back to generic settings:
OpenAI Codex v0.172.0
--------
workdir: /home/josphat/projects/cx-run
model: global.amazon.ergo-1.0
provider: bedrock-runtime
approval: never
sandbox: workspace-write [workdir, /tmp, $TMPDIR]
reasoning effort: medium
reasoning summaries: none
--------
warning: Model metadata for `global.amazon.ergo-1.0` not found. Defaulting to fallback metadata; this can degrade performance and cause issues.
Codex ran pytest, read both files, applied one patch and re-ran the suite, finishing in 22.2 seconds with tokens used 11,362. It chose a different guard from OpenCode, rebuilding the input from the matched parts and rejecting anything left over, which git diff shows:
git diff
The patch adds a compiled pattern and a check that the matched pieces join back into the original string:
diff --git a/durations.py b/durations.py
index 6f7f464..07ebda9 100644
--- a/durations.py
+++ b/durations.py
@@ -1,11 +1,12 @@
import re
-UNITS = {"h": 3600, "m": 60, "s": 1}
+UNITS = {"d": 86400, "h": 3600, "m": 60, "s": 1}
+PART = re.compile(r"(\d+)([dhms])")
def parse_duration(text):
"""Convert strings like 1h30m or 45s to seconds."""
- parts = re.findall(r"(\d+)([hms])", text)
- if not parts:
+ parts = PART.findall(text)
+ if not parts or "".join(n + u for n, u in parts) != text:
raise ValueError(f"bad duration: {text!r}")
return sum(int(n) * UNITS[u] for n, u in parts)
Both guards pass all four tests. More flags and shortcuts are in the Codex CLI cheat sheet.
Run Claude Code on Ergo through LiteLLM
Claude Code speaks only the Anthropic Messages API, and Bedrock does not offer that for Ergo, so a local LiteLLM proxy translates between the two. It runs on 127.0.0.1 and nothing else on your network sees it. Make a folder for the proxy config:
mkdir -p ~/ergo-claude-code
vim ~/ergo-claude-code/litellm.yaml
The model is addressed through LiteLLM’s openai/ provider pointed at Bedrock’s endpoint. drop_params strips Anthropic-only parameters Ergo would reject, and master_key is a local string Claude Code will send back as its token, not an AWS secret:
model_list:
- model_name: global.amazon.ergo-1.0
litellm_params:
model: openai/global.amazon.ergo-1.0
api_base: https://bedrock-runtime.eu-west-1.amazonaws.com/openai/v1
api_key: os.environ/AWS_BEARER_TOKEN_BEDROCK
extra_body:
reasoning:
effort: medium
litellm_settings:
drop_params: true
general_settings:
master_key: sk-ergo-local
Start the proxy in its own terminal. uv fetches LiteLLM into a throwaway environment on the first run, which took 39 seconds here, and later starts are a few seconds:
uv tool run --from 'litellm[proxy]' litellm --config ~/ergo-claude-code/litellm.yaml --host 127.0.0.1 --port 4000
It is ready when Uvicorn reports the port:
INFO: Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:4000 (Press CTRL+C to quit)
Rather than exporting Anthropic variables into your normal shell, where they would hijack every Claude Code session you run, put them in a launcher script. Every model slot points at Ergo, so subagents and the background model do not try to reach Anthropic:
vim ~/ergo-claude-code/claude-ergo
Add the launcher:
#!/usr/bin/env bash
export ANTHROPIC_BASE_URL="http://127.0.0.1:4000"
export ANTHROPIC_AUTH_TOKEN="sk-ergo-local"
export ANTHROPIC_MODEL="global.amazon.ergo-1.0"
export ANTHROPIC_DEFAULT_OPUS_MODEL="global.amazon.ergo-1.0"
export ANTHROPIC_DEFAULT_SONNET_MODEL="global.amazon.ergo-1.0"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="global.amazon.ergo-1.0"
export CLAUDE_CODE_SUBAGENT_MODEL="global.amazon.ergo-1.0"
export CLAUDE_CODE_MAX_CONTEXT_TOKENS="1048568"
unset CLAUDE_CODE_USE_BEDROCK
exec claude "$@"
Make it executable and run the task in print mode. --allowedTools lets it run pytest and edit files without stopping to ask, and nothing else. Keep the prompt before that flag, because --allowedTools takes every argument after it as another tool name:
chmod +x ~/ergo-claude-code/claude-ergo
~/ergo-claude-code/claude-ergo -p "Run the test suite with python3 -m pytest -q. Two tests fail. Fix durations.py so all tests pass, without editing the tests, then run the suite again to confirm." --allowedTools "Bash(python3 -m pytest:*)" "Read" "Edit"
Claude Code finished in 18.9 seconds over six turns and reported all four tests passing; a retest of the exact command above with the scoped key took 16.9 seconds and passed too. Its edit landed on the same re.fullmatch guard OpenCode chose:
diff --git a/durations.py b/durations.py
index 6f7f464..3ca501f 100644
--- a/durations.py
+++ b/durations.py
@@ -1,11 +1,11 @@
import re
-UNITS = {"h": 3600, "m": 60, "s": 1}
+UNITS = {"d": 86400, "h": 3600, "m": 60, "s": 1}
def parse_duration(text):
- """Convert strings like 1h30m or 45s to seconds."""
- parts = re.findall(r"(\d+)([hms])", text)
- if not parts:
+ """Convert strings like 1h30m, 2d4h, or 45s to seconds."""
+ if not re.fullmatch(r"(?:\d+[dhms])+", text):
raise ValueError(f"bad duration: {text!r}")
+ parts = re.findall(r"(\d+)([dhms])", text)
return sum(int(n) * UNITS[u] for n, u in parts)
Ignore the cost Claude Code prints. With --output-format json it reported total_cost_usd: 0.1377, but it has no price for a model it does not recognise (stderr says [claude-code:unrecognized_model]) and charges the tokens at Anthropic rates. The same usage at Ergo’s Bedrock rates (12,932 cache-write tokens, 47,429 cache-read, 1,324 output) comes to about $0.02. Your hooks, subagents and settings carry over, so the Claude Code cheat sheet applies unchanged, but if ~/.claude/settings.json sets ANTHROPIC_MODEL in its env block, that wins over the launcher.
Compare the three agents on Ergo
All three fixed both bugs on the first attempt without touching the tests. Wall time includes tool execution, and token figures are what each agent reports about itself:
| Agent | Path to Bedrock | Wall time | Tool calls or turns | Tokens reported |
|---|---|---|---|---|
| OpenCode | Chat Completions, direct | 20.6 s | 3 bash, 2 read, 1 edit | 8.5K input, 31.2K cache read, 495 output |
| Codex CLI | Responses API, direct | 22.2 s | 3 shell runs, 1 patch | 11,362 total |
| Claude Code | LiteLLM proxy | 18.9 s | 6 turns | 12.9K cache write, 47.4K cache read, 1,324 output |
Speed is a wash, so you should choose on workflow:
- OpenCode for the shortest setup: one JSON file, no proxy
- Codex CLI if your team already scripts
codex execin CI - Claude Code to keep existing hooks, subagents and skills
Claude Code sends the most context, about 60K input tokens across its six turns for a two-file repo, which prompt caching makes cheap: cache reads cost $0.03 per million against $1.00 for fresh input. OpenCode’s cache reads show the same caching works through plain Chat Completions with no extra setting. Claude Code is also the only one with an extra moving part, since the proxy is one more process to keep running. For the money, Bedrock’s CloudWatch metrics for the whole lab (43 calls including the effort test below) showed 73,554 output tokens, 115,641 cache-read tokens and 31,690 cache-write tokens, about $0.27 in total.
Check whether reasoning effort matters
It barely does. Bedrock accepts five effort values for Ergo and rejects none, but the Hugging Face model card says Ergo uses a fixed reasoning effort, and our numbers agree. We sent one coding prompt (a duration parser plus five pytest tests) three times at each level, all 15 requests in parallel:
| Effort | Reasoning tokens (3 runs) | Median | Seconds per call |
|---|---|---|---|
| low | 3,073 / 8,908 / 2,231 | 3,073 | 8.5 to 23.8 |
| medium | 2,344 / 3,533 / 3,542 | 3,533 | 9.9 to 12.9 |
| high | 5,160 / 4,311 / 2,497 | 4,311 | 10.8 to 16.1 |
| xhigh | 3,228 / 4,601 / 3,058 | 3,228 | 10.7 to 14.0 |
| max | 4,819 / 4,820 / 2,876 | 4,819 | 8.9 to 14.5 |
For most levels the spread between runs is wider than the gap between level medians, and low produced both the fewest reasoning tokens of the 15 runs (2,231) and the most (8,908). No setting makes Ergo cheaper per question, so you should leave the configs at medium and control cost through max_tokens and prompt caching instead. Those runs also give a fair speed figure for the hosted model: 280 to 400 output tokens per second end to end, including time to the first token.
Call Ergo from Python with the Converse API
Boto3 reads AWS_BEARER_TOKEN_BEDROCK too, so the same key works with the native Converse API, but two habits from other Bedrock models break on Ergo. The first is content[0]["text"]: Ergo’s reply puts a reasoningContent block ahead of the text block, so the first block has no text key. Our test printed the block order and then tripped on exactly that:
block types: ['reasoningContent', 'text']
usage: {'inputTokens': 77, 'outputTokens': 374, 'totalTokens': 451, 'cacheReadInputTokens': 0, 'cacheWriteInputTokens': 0}
KeyError: 'text'
Pick the first block that actually has text instead of indexing by position:
blocks = resp["output"]["message"]["content"]
answer = next(b["text"] for b in blocks if "text" in b)
The second is the reasoning itself. In a default Converse call the reasoningContent block holds only redactedContent (3,988 opaque bytes when we asked for 17 times 23) and no readable reasoningText. The model card lists summarized reasoning as supported, which we did not test, but with default settings an app that displayed Claude’s thinking through Converse shows nothing for Ergo.
Amazon Ergo Bedrock error messages and fixes
Every error below came back from our lab with the text shown. You are likely to meet most of them in your first hour with Ergo, and none is obvious from the message alone.
“Invocation of model ID amazon.ergo-1.0 with on-demand throughput isn’t supported”
You used the base model ID. Ergo has no in-region endpoint, so the model name must be an inference profile: global.amazon.ergo-1.0 or us.amazon.ergo-1.0. Bedrock returns this as HTTP 400 in under a second.
“not authorized to perform: bedrock:CallWithBearerToken on resource: *”
The IAM user behind your API key has InvokeModel rights but not the bearer-token action. This is the policy from AWS’s coding-tools page used as is. Add the second statement from the policy above, give IAM a few seconds to propagate, and retry.
“not authorized to perform: bedrock:InvokeModel on resource: arn:aws:bedrock:eu-west-1:123456789012:project/default”
Codex printed this as unexpected status 401 Unauthorized on /openai/v1/responses, and Claude Code showed the same text wrapped in a LiteLLM AuthenticationError. The policy covers the Ergo profiles but not the project resource the Responses API checks. Add arn:aws:bedrock:*:*:project/default to the InvokeModel statement, as in the policy above.
“Unsupported value: ‘none’ is not supported with this model”
Some clients send reasoning_effort: none to switch thinking off. Ergo cannot stop reasoning, so Bedrock lists the accepted values in the same message: 'low', 'medium', 'high', 'xhigh', and 'max'. Set one of them in the client config.
Empty answer with “finish_reason”: “length”
No error at all, just "content": null. The output limit was used up by reasoning before the answer began; our 300-token limit produced this on a one-line question. Raise max_tokens to at least 8,192.
“Too many strict tools: a request allows at most 20, this one has 21”
Bedrock caps strict tool definitions at 20 per request on Ergo. Agents with large MCP tool sets hit this first. On Chat Completions the message states the limit plainly; through Converse the same request fails with a vaguer ValidationException ... The provided request is not valid. Turn strict off on the tools that do not need guaranteed schemas, or load fewer MCP servers for the session.
“Too many requests, please wait before trying again”
An HTTP 429 from the account’s tokens-per-minute quota. Our fresh test account hit it during the lab. Bedrock deducts each request’s full max_tokens from that quota when the request starts. Lower the output limit in your agent config before you request a quota increase, because the reservation is what fills the quota, not the tokens Ergo actually writes.
“Invalid API Key format: Delimiter ‘:’ not found”
An HTTP 401 meaning the bearer value isn’t a Bedrock API key at all: usually an empty variable, an IAM access key pasted by mistake, or a token file with a stray newline. Check that the variable is set and starts with ABSK, the prefix every Bedrock API key in our lab carried.
If you are weighing Ergo against other hosted models, our Bedrock vs Azure AI Foundry vs Vertex AI comparison covers the platform side. The Kimi K3.1 Pro API setup is the strongest open-weights rival in Amazon’s own benchmark table, and our open source LLM comparison ranks Ergo against every other open model on license, size and benchmarks. When you are done testing, remove the key, the policy and the user, because expiry only deactivates the key:
KEY_ID=$(aws iam list-service-specific-credentials --user-name ergo-coder --service-name bedrock.amazonaws.com --query 'ServiceSpecificCredentials[0].ServiceSpecificCredentialId' --output text)
aws iam delete-service-specific-credential --user-name ergo-coder --service-specific-credential-id "$KEY_ID"
aws iam delete-user-policy --user-name ergo-coder --policy-name ergo-invoke
aws iam delete-user --user-name ergo-coder
After delete-user succeeds, nothing from this setup remains in the account.