Error reference

OpenRouter billing and quota errors

The answers OpenRouter gives when an organization cannot pay for a request, and the ones that look similar but are not about money. For each: the status, the body, and what keyover does with it.

Rejections about money or the key

402Your account or API key has insufficient credits

Moves to the next key: out of credit

{
  "error": {
    "code": 402,
    "metadata": {
      "limit_source": "openrouter_credits"
    }
  }
}

Documented by OpenRouter: openrouter.ai. The body shows the fields the source establishes.

403Key reached the limit set on it

Moves to the next key: your own spend limit

{
  "error": {
    "code": 403,
    "metadata": {
      "limit_source": "openrouter_key_limit"
    }
  }
}

Documented by OpenRouter: openrouter.ai. The body shows the fields the source establishes.

403Workspace budget reached

Moves to the next key: your own spend limit

{
  "error": {
    "code": 403,
    "metadata": {
      "limit_source": "openrouter_workspace_budget"
    }
  }
}

Documented by OpenRouter: openrouter.ai. The body shows the fields the source establishes.

401Invalid or disabled API key

Moves to the next key: key not accepted

{
  "error": {
    "code": 401
  }
}

Documented by OpenRouter: openrouter.ai. The body shows the fields the source establishes.

Answers that are not a reason to change key

402This request's estimated cost is larger than the whole in-flight budget

Stays with your SDK

The in-flight budget has a ceiling OpenRouter sets. Lower max_tokens or the prompt size.

{
  "error": {
    "code": 402,
    "metadata": {
      "limit_source": "openrouter_credits",
      "reason": "weight_exceeds_budget"
    }
  }
}

Documented by OpenRouter: openrouter.ai. The body shows the fields the source establishes.

402In-flight budget reserved by other requests

Stays with your SDK

A reservation that frees itself. It carries retry-after, and your SDK waits.

{
  "error": {
    "code": 402,
    "metadata": {
      "limit_source": "openrouter_in_flight_budget",
      "reason": "in_flight_budget_exhausted"
    }
  }
}

Sent with the header retry-after: 2.

Documented by OpenRouter: openrouter.ai. The body shows the fields the source establishes.

403Moderation flag or guardrail block

Stays with your SDK

A policy decision. Never routed around.

{
  "error": {
    "code": 403
  }
}

Documented by OpenRouter: openrouter.ai. The body shows the fields the source establishes.

Keep serving through it

Give the pool a second key that bills another organization you are authorized to use. When OpenRouter refuses the first for one of the rejections above, the same request is sent again on the second, inside the same call. Your code gets a normal response, and an event tells you which organization needs attention.

import OpenAI from "openai"
import { createKeyPool, OPENROUTER } from "keyover"

const pool = createKeyPool({
  provider: OPENROUTER,
  keys: {
    primary: process.env.OPENROUTER_API_KEY,
    spare: process.env.OPENROUTER_API_KEY_SPARE,
  },
})

const client = new OpenAI({ ...pool.clientOptions, baseURL: "https://openrouter.ai/api/v1" })

See it fail over in the playground, or read the README.