← Home

How to use Amazon Ergo: an API quickstart

This guide shows how to use Amazon Ergo from your own code through the Ergo Model hosted API. The endpoint follows the OpenAI Chat Completions shape, so existing OpenAI code needs three changes: the base URL, the API key, and the model name ergo-1.0. The one thing that differs from most models is the reasoning budget, covered below.

Ergo Model is an independent service. It is not affiliated with, endorsed by or operated by Amazon, AWS or OpenRouter. If you only want to see how the model answers, the free playground runs in the browser with no signup.

1. Get a key

Sign in, add credit, and create a key in the dashboard. Signing up and creating a key is free; calls need a balance, and the smallest top-up is $5. Keys start with ergo_live_ and go in the Authorization: Bearer header. Store the key in an environment variable such as ERGO_API_KEY and keep it on the server.

All the ways to get an Amazon Ergo API key →

2. Send a first request

Base URL: https://ergomodel.net/api/v1. Chat requests go to POST /chat/completions with the model set to ergo-1.0.

curl

The raw HTTP request, useful as a smoke test for a new key.

curl https://ergomodel.net/api/v1/chat/completions \
  -H "Authorization: Bearer ergo_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "model": "ergo-1.0",
    "messages": [
      { "role": "user", "content": "Explain what a mutex is in two sentences." }
    ],
    "max_tokens": 2048
  }'

Python (openai SDK)

Install with pip install openai, then point the client at the base URL.

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://ergomodel.net/api/v1",
    api_key=os.environ["ERGO_API_KEY"],  # ergo_live_...
)

resp = client.chat.completions.create(
    model="ergo-1.0",
    messages=[
        {"role": "user", "content": "Explain what a mutex is in two sentences."},
    ],
    # Ergo always reasons first, and reasoning comes out of max_tokens.
    max_tokens=2048,
)

print(resp.choices[0].message.content)
print(resp.usage)

TypeScript (openai SDK)

Install with npm install openai. Set baseURL and apiKey; nothing else changes. A longer walkthrough is at /integrations/typescript.

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://ergomodel.net/api/v1",
  apiKey: process.env.ERGO_API_KEY, // ergo_live_...
});

const resp = await client.chat.completions.create({
  model: "ergo-1.0",
  messages: [
    { role: "user", content: "Explain what a mutex is in two sentences." },
  ],
  // Ergo always reasons first, and reasoning comes out of max_tokens.
  max_tokens: 2048,
});

console.log(resp.choices[0].message.content);
console.log(resp.usage);

3. Stream the response

Pass stream: true to receive Server-Sent Events as tokens are produced. The gateway always sends a final frame with usage before data: [DONE], so you can record token counts for streamed calls too. Because the model reasons first, there is a pause before the first content token.

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://ergomodel.net/api/v1",
  apiKey: process.env.ERGO_API_KEY,
});

const stream = await client.chat.completions.create({
  model: "ergo-1.0",
  messages: [
    { role: "user", content: "Write a binary search in Go, with a short explanation." },
  ],
  max_tokens: 4096,
  stream: true,
});

for await (const chunk of stream) {
  // The last frame carries usage and has no choices.
  if (chunk.usage) console.error("\n", chunk.usage);
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}

4. Budget for reasoning

Ergo reasons before every answer, and this cannot be switched off. A request that asks to disable reasoning is rejected with HTTP 400. Three consequences follow:

To control the budget, send the reasoning field: either { "effort": "low" | "medium" | "high" } or { "max_tokens": N }. Low effort suits lookups and classification; keep it higher for multi-step coding work.

curl https://ergomodel.net/api/v1/chat/completions \
  -H "Authorization: Bearer ergo_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "model": "ergo-1.0",
    "messages": [
      { "role": "user", "content": "Is 2027 a prime number? Answer yes or no." }
    ],
    "reasoning": { "effort": "low" },
    "max_tokens": 2048
  }'

The reasoning text is returned next to the answer in choices[0].message.reasoning (and in delta.reasoning when streaming). Do not show it to end users as the answer; read content for that.

5. Tool calling

tools and tool_choice are forwarded unchanged and use the OpenAI function-calling format. The model replies with tool_calls; run the function, append a tool message with the result, and call again.

resp = client.chat.completions.create(
    model="ergo-1.0",
    messages=[{"role": "user", "content": "What is the weather in Lagos right now?"}],
    tools=[{
        "type": "function",
        "function": {
            "name": "get_weather",
            "description": "Current weather for a city",
            "parameters": {
                "type": "object",
                "properties": {"city": {"type": "string"}},
                "required": ["city"],
            },
        },
    }],
    max_tokens=4096,
)

call = resp.choices[0].message.tool_calls[0]
print(call.function.name, call.function.arguments)

6. Structured output

response_format is forwarded too. Pass a JSON Schema and parse content as JSON. Leave room in max_tokens: a reply cut off by the limit is not valid JSON.

resp = client.chat.completions.create(
    model="ergo-1.0",
    messages=[{"role": "user", "content": "Extract the invoice number and total from: INV-2041, total due 318.50 USD."}],
    response_format={
        "type": "json_schema",
        "json_schema": {
            "name": "invoice",
            "strict": True,
            "schema": {
                "type": "object",
                "properties": {
                    "invoice_number": {"type": "string"},
                    "total": {"type": "number"},
                },
                "required": ["invoice_number", "total"],
                "additionalProperties": False,
            },
        },
    },
    max_tokens=4096,
)

print(resp.choices[0].message.content)  # a JSON string matching the schema

7. Load a long context

The context window is 1,048,576 tokens, enough for a large codebase or a long set of documents in one request. Put the material in the message, put the question after it, and stream the reply so the connection stays active while the model reads. The model is text only, so convert PDFs and images to text first. More detail is on the context window page.

with open("repo_dump.txt", encoding="utf-8") as f:
    source = f.read()

stream = client.chat.completions.create(
    model="ergo-1.0",
    messages=[
        {"role": "system", "content": "You are reviewing a codebase. Cite file paths."},
        {"role": "user", "content": source + "\n\nList the three riskiest modules and why."},
    ],
    max_tokens=8192,
    stream=True,
)

for chunk in stream:
    if chunk.choices:
        print(chunk.choices[0].delta.content or "", end="")

8. Know what it costs

The rate is $1.50 per 1M input tokens and $4.50 per 1M output tokens. Reasoning counts as output, and cached input is billed at the normal input rate.

RequestCost
100,000-token prompt (input only)$0.15
2,000 output tokens, reasoning included$0.009
Full 1,000,000-token prompt, before output$1.50

Credits are prepaid in packs from $5 and never expire. There is no subscription. Amazon Bedrock and OpenRouter charge less per token for the same model; what this service adds is one key and card payment with no AWS account. See pricing and the provider comparison.

Common errors

What you seeCause and fix
Empty content, finish_reason: "length"The reasoning used the whole budget. Raise max_tokens to 2048 or more, or lower reasoning.effort.
400Malformed request, or the model rejected it. Check that messages is a non-empty array, that the prompt fits the context window, and that you are not trying to disable reasoning.
401 missing_api_key / invalid_api_keyThe header must read Authorization: Bearer ergo_live_.... A revoked key returns the same error.
402 insufficient_creditsThe balance is zero. Top up in the dashboard; the error message includes the link.
429 rate_limit_exceededMore than 30 requests in a minute on one key. Wait for the number of seconds in the Retry-After header. See rate limits.
503The upstream is busy. Retry after a few seconds.
502The upstream is unavailable. Retry with backoff.

Use it in a coding agent

Any tool that accepts an OpenAI-compatible endpoint can use the same base URL, key and model name. Setup guides: OpenCode, Cline, Cursor, Claude Code, and the full list.

Read the full API reference →

How to use Amazon Ergo — API quickstart with curl, Python, TypeScript · Ergo Model