Skip to main content

Use AI gateway with coding agents Early availability

Point your coding agent like Claude Code or Codex at the AI gateway to send requests using your API key.

Required roles or permissions:project:ai_gateway_keys:write, project:ai_gateway_keys:read, role:project:admin, or role:project:manager

Prerequisites​

Use Claude Code with AI gateway models​

To use Claude Code with the AI Gateway, set the gateway address, your API key, and the model names in the terminal or in Claude Code's configuration file.

VariableValue
ANTHROPIC_BASE_URLhttps://ai.aiven.io
ANTHROPIC_AUTH_TOKENYour AI Gateway API key
ANTHROPIC_MODELaiven-model
ANTHROPIC_DEFAULT_OPUS_MODELclaude-opus-5
ANTHROPIC_DEFAULT_SONNET_MODELclaude-sonnet-5
ANTHROPIC_DEFAULT_HAIKU_MODELclaude-haiku-4-5

aiven-model is the Aiven router, and usage on it is free. To use a specific model, set ANTHROPIC_MODEL to that model's name. Named models are billed at the rates shown in the model list.

Claude Code sends smaller jobs, such as session titles and some subagent work, to its Opus, Sonnet, and Haiku aliases. Those aliases default to the model you pin.

Export the variables for the session. Exports last for that terminal session and for programs you start from it.

export ANTHROPIC_BASE_URL="https://ai.aiven.io"
export ANTHROPIC_AUTH_TOKEN="API_KEY"
export ANTHROPIC_MODEL="aiven-model"
export ANTHROPIC_DEFAULT_OPUS_MODEL="claude-opus-5"
export ANTHROPIC_DEFAULT_SONNET_MODEL="claude-sonnet-5"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="claude-haiku-4-5"

Test Claude Code with AI Gateway​

  1. To start Claude Code, run claude.
Note

If you exported the variables, run all commands in the same terminal where you exported the variables.

  1. To confirm the gateway is configured, run /status. The Auth token is the variable ANTHROPIC_AUTH_TOKEN and the Anthropic base URL is https://ai.aiven.io.

  2. Close the status and send a test prompt.

  3. To verify the request was sent to the AI Gateway, go to the Aiven Console.

  4. Click AI Gateway.

  5. To see the request, view the usage metrics on the page for the API key you used. A new request can take about 15 minutes to appear.

Use Codex with AI gateway models​

  1. Export the API key.

    export AIVEN_AI_GATEWAY_KEY="API_KEY"
  2. Add a provider to the ~/.codex/config.toml file.

    model = "aiven-model"
    model_provider = "aiven"

    [model_providers.aiven]
    name = "Aiven AI Gateway"
    base_url = "https://ai.aiven.io/v1"
    env_key = "AIVEN_AI_GATEWAY_KEY"
    wire_api = "responses"

aiven-model is the Aiven router, and usage on it is free. To use a specific model, set model to that model's name. Named models are billed at the rates shown in the model list.

Test Codex with AI Gateway​

In the same terminal where you exported the API key:

  1. To start Codex, run codex.

  2. To confirm the active model is aiven-model, run /status.

  3. Send a test prompt.

  4. To verify the request was sent to the AI Gateway, go to the Aiven Console.

  5. Click AI Gateway.

  6. To see the request, view the usage metrics on the page for the API key you used. A new request can take about 15 minutes to appear.