{
  "openapi": "3.1.0",
  "info": {
    "title": "altrouter API",
    "version": "1.0.0",
    "description": "OpenAI-compatible gateway. Point any OpenAI SDK at the base URL below with your altrouter key (ar-…) - no other change needed. One key, one balance, every model."
  },
  "servers": [
    {
      "url": "https://api.altrouter.ai/v1",
      "description": "Production"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "Chat",
      "description": "Text & multimodal chat completions."
    },
    {
      "name": "Images",
      "description": "Image generation and editing - blocking by default, or as a job to poll (`\"async\": true`)."
    },
    {
      "name": "Videos",
      "description": "Video generation - asynchronous: create, then poll."
    },
    {
      "name": "Catalog",
      "description": "Models and account balance."
    },
    {
      "name": "Billing",
      "description": "Top up the balance over the API: open an invoice, hand its URL to the payer, poll until finished."
    }
  ],
  "paths": {
    "/chat/completions": {
      "post": {
        "tags": [
          "Chat"
        ],
        "summary": "Create a chat completion",
        "description": "OpenAI-compatible chat completions, with optional SSE streaming and tool calling.",
        "operationId": "createChatCompletion",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "model": {
                    "type": "string",
                    "description": "A model id from the catalog, e.g. \"gpt-5.4\". See GET /v1/models.",
                    "enum": [
                      "gemini-3.1-flash-lite",
                      "gemini-2.5-flash",
                      "gemini-3-flash",
                      "gemini-3.5-flash",
                      "gemini-3.6-flash",
                      "gemini-3.7-flash",
                      "gemini-3.8-flash",
                      "gemini-4-argon",
                      "gemini-2.5-pro",
                      "gemini-3.1-pro",
                      "gemini-3-pro",
                      "gpt-5.4",
                      "gpt-5",
                      "gpt-5-mini",
                      "gpt-5.4-mini",
                      "gpt-5.4-nano",
                      "o3",
                      "gpt-4o",
                      "gpt-4o-mini",
                      "gpt-5.5",
                      "gpt-5.2",
                      "gpt-6-astra",
                      "gpt-6-sol",
                      "gpt-6.1-sol",
                      "gpt-6.1-terra",
                      "gpt-6-luna",
                      "gpt-5.6",
                      "gpt-5.6-pro",
                      "gpt-5.6-mini",
                      "claude-haiku-4-5",
                      "claude-sonnet-4-5",
                      "claude-opus-4-5",
                      "claude-opus-4-8",
                      "claude-opus-4-7",
                      "claude-sonnet-4-6",
                      "claude-sonnet-5",
                      "claude-opus-4-6",
                      "claude-fable-5",
                      "claude-opus-5",
                      "claude-opus-5.5",
                      "claude-sonnet-5.5",
                      "claude-haiku-5.5",
                      "claude-fable-5.1",
                      "claude-fable-5.2",
                      "grok-4.6",
                      "grok-4.7",
                      "grok-4.5",
                      "grok-4.3",
                      "kimi-k3",
                      "kimi-k3.1-pro",
                      "deepseek-v4.1-flash",
                      "deepseek-v4-pro",
                      "minimax-m3.1-flash",
                      "gemini-3.5-flash-lite"
                    ]
                  },
                  "messages": {
                    "type": "array",
                    "items": {},
                    "description": "The conversation: an array of messages with roles system / user / assistant / tool. Supports multimodal content (text + image_url)."
                  },
                  "stream": {
                    "type": "boolean",
                    "description": "If true, the reply streams as OpenAI-compatible server-sent events (SSE). The stream ends with data: [DONE]."
                  },
                  "max_tokens": {
                    "type": "integer",
                    "description": "Maximum tokens to generate. The alias max_completion_tokens is also accepted. Defaults to a server-side cap."
                  },
                  "temperature": {
                    "type": "number",
                    "description": "Sampling randomness. Higher is more creative, lower is more deterministic."
                  },
                  "top_p": {
                    "type": "number",
                    "description": "Nucleus sampling - the probability mass to sample tokens from."
                  },
                  "stop": {
                    "type": "array",
                    "items": {},
                    "description": "A string or array of strings at which generation stops."
                  },
                  "tools": {
                    "type": "array",
                    "items": {},
                    "description": "Function-calling tool definitions in OpenAI format."
                  },
                  "tool_choice": {
                    "type": "object",
                    "description": "Controls tool use: auto / required / none / a specific function."
                  },
                  "reasoning_effort": {
                    "type": "string",
                    "description": "Thinking budget for reasoning models. Reasoning content is returned in message.reasoning_content."
                  },
                  "response_format": {
                    "type": "object",
                    "description": "Structured output: { \"type\": \"json_object\" } or { \"type\": \"json_schema\", \"json_schema\": … }. See the Structured outputs guide."
                  },
                  "web_search": {
                    "type": "boolean",
                    "description": "Server-side web search: the model answers with live data from the web."
                  },
                  "seed": {
                    "type": "integer",
                    "description": "Seed for reproducible sampling where the model supports it."
                  },
                  "frequency_penalty": {
                    "type": "number",
                    "description": "Penalizes tokens by their existing frequency."
                  },
                  "presence_penalty": {
                    "type": "number",
                    "description": "Penalizes tokens that have already appeared."
                  }
                },
                "required": [
                  "model",
                  "messages"
                ]
              },
              "example": {
                "model": "gemini-3.1-flash-lite",
                "messages": [
                  {
                    "role": "user",
                    "content": "Hello!"
                  }
                ],
                "stream": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A chat completion (or an SSE stream when stream=true).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChatCompletion"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Insufficient credits, or the key’s spending cap is exhausted.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The surface is outside the key’s scopes.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Model not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal gateway error.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Model-side error.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "The model is temporarily unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "504": {
            "description": "Request exceeded the allowed time.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/images/generations": {
      "post": {
        "tags": [
          "Images"
        ],
        "summary": "Create an image",
        "description": "Generate or edit an image. Results are re-hosted on our CDN and returned as URLs. By default the call blocks until the image is ready. A slow render can outlast a client or proxy timeout (ours drops a silent connection at ~100 s), so a caller may ask for a job instead: `\"async\": true` in the body or the `Prefer: respond-async` header returns 202 with an `image.generation` object in `queued`; poll `GET /images/generations/{id}` until `status` is `completed` (the images arrive in `data`) or `failed`. Credit is reserved at create time and charged only for delivered images. `Idempotency-Key` works in both modes: an async replay returns the same job.",
        "operationId": "createImage",
        "parameters": [
          {
            "name": "Prefer",
            "in": "header",
            "required": false,
            "description": "`respond-async` - same as `\"async\": true`.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "A retry with the same key gets the first result (or, async, the same job) instead of a second render.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "model": {
                    "type": "string",
                    "description": "An image model id from the catalog, e.g. \"nano-banana-pro\".",
                    "enum": [
                      "nano-banana-fast",
                      "nano-banana",
                      "nano-banana-2",
                      "nano-banana-2.1",
                      "nano-banana-pro",
                      "gpt-image-2",
                      "seedream-v4",
                      "flux-2-pro",
                      "qwen-image",
                      "z-image",
                      "seedream-4.5",
                      "seedream-5-lite",
                      "seedream-5-pro",
                      "grok-imagine",
                      "wan-2.7",
                      "qwen-image-3",
                      "qwen-image-3-pro",
                      "nano-banana-2-lite",
                      "grok-imagine-2",
                      "gpt-image-1.5",
                      "flux-kontext-pro",
                      "flux-kontext-max",
                      "midjourney-v7",
                      "midjourney-v8",
                      "qwen-image-2",
                      "qwen-image-2.1",
                      "wan-2.7-pro",
                      "gpt-image-2.5",
                      "gpt-image-2.5-flare",
                      "gpt-image-2.5-sunburst",
                      "ideogram-v3",
                      "ideogram-v3-edit",
                      "ideogram-character",
                      "flux-2-flex",
                      "flux-2-max",
                      "seedream-3",
                      "imagen-4-fast",
                      "imagen-4-ultra",
                      "recraft-crisp-upscale",
                      "recraft-remove-background"
                    ]
                  },
                  "prompt": {
                    "type": "string",
                    "description": "A text description of the desired image."
                  },
                  "image": {
                    "type": "array",
                    "items": {},
                    "description": "Reference images (URL or base64) for editing. The router picks the model’s edit variant automatically."
                  },
                  "resolution": {
                    "type": "string",
                    "description": "Resolution tier - selects the model variant and price (quality:\"hd\" ⇒ 4K)."
                  },
                  "response_format": {
                    "type": "string",
                    "description": "Result shape. Defaults to url: the image is re-hosted on our CDN and the link is permanent."
                  },
                  "async": {
                    "type": "boolean",
                    "default": false,
                    "description": "Return 202 with a job to poll instead of blocking until the image is ready."
                  }
                },
                "required": [
                  "model",
                  "prompt"
                ]
              },
              "example": {
                "model": "nano-banana-fast",
                "prompt": "A red panda coding at a laptop, studio lighting"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The generated image(s).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ImageResponse"
                }
              }
            }
          },
          "202": {
            "description": "Async only: the generation was accepted and queued.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ImageJob"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request or content moderation rejection.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Insufficient credits, or the key’s spending cap is exhausted.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The surface is outside the key’s scopes.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Model not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal gateway error.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Model-side error.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "The model is temporarily unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "504": {
            "description": "Request exceeded the allowed time.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/images/generations/{id}": {
      "get": {
        "tags": [
          "Images"
        ],
        "summary": "Retrieve an async image generation",
        "description": "The current state of a job created with `\"async\": true`. Poll until `status` is `completed` or `failed`. Only the org that created it can read it.",
        "operationId": "retrieveImageGeneration",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The image generation job.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ImageJob"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No such image generation.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/videos": {
      "post": {
        "tags": [
          "Videos"
        ],
        "summary": "Create a video",
        "description": "Starts a render and returns immediately with a `video` object in `queued`. A render takes minutes, so poll `GET /videos/{id}` until `status` is `completed` (the re-hosted mp4 arrives in `url`) or `failed`. Credit is reserved at create time and charged only on a completed render.",
        "operationId": "createVideo",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "model": {
                    "type": "string",
                    "description": "A video model id from the catalog, e.g. \"veo-3.1-fast\".",
                    "enum": [
                      "veo-3.1",
                      "veo-3.1-fast",
                      "veo-3.1-lite",
                      "seedance-2.0",
                      "kling-3.0",
                      "kling-2.6",
                      "kling-2.6-motion-control",
                      "kling-3.0-motion-control",
                      "hailuo-2.3",
                      "wan-2.7-video",
                      "kling-3.0-turbo",
                      "seedance-2.5",
                      "seedance-2.0-mini",
                      "wan-3.0-video",
                      "wan-3.0-video-prime",
                      "minimax-h3",
                      "pixverse-v6",
                      "happyhorse-1.1",
                      "grok-imagine-video-1.5",
                      "grok-imagine-video",
                      "vidu-q3-turbo",
                      "vidu-q3",
                      "gemini-omni-1.1",
                      "minimax-h3-max",
                      "happyhorse-1.0",
                      "flux-3-video",
                      "seedance-2.0-fast",
                      "seedance-1.5-pro",
                      "seedance-1.0-pro",
                      "seedance-1.0-pro-fast",
                      "kling-o3",
                      "kling-2.5-turbo",
                      "kling-2.1-standard",
                      "wan-2.6-video",
                      "wan-2.2-video",
                      "hailuo-02",
                      "runway-gen-4-turbo"
                    ]
                  },
                  "prompt": {
                    "type": "string",
                    "description": "A text description of the scene."
                  },
                  "seconds": {
                    "type": "integer",
                    "description": "Clip length in seconds. The allowed values are the model’s own (see its page); out-of-range values are clamped. `duration` is accepted as an alias."
                  },
                  "image": {
                    "type": "array",
                    "items": {},
                    "description": "A reference frame (URL or base64) - its presence routes the request to the model’s image-to-video variant. `input_reference` is accepted for a single frame."
                  }
                },
                "required": [
                  "model",
                  "prompt"
                ]
              },
              "example": {
                "model": "veo-3.1",
                "prompt": "A red panda skateboarding through neon-lit Tokyo streets at night",
                "seconds": 8
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "The render was accepted and queued.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Video"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request or content moderation rejection.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Insufficient credits, or the key’s spending cap is exhausted.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The surface is outside the key’s scopes.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Model not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal gateway error.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Model-side error.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "The model is temporarily unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "504": {
            "description": "Request exceeded the allowed time.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "Videos"
        ],
        "summary": "List videos",
        "description": "The most recent renders for the org that owns the API key, newest first.",
        "operationId": "listVideos",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The video list.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "type": "string",
                      "const": "list"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Video"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/videos/{id}": {
      "get": {
        "tags": [
          "Videos"
        ],
        "summary": "Retrieve a video",
        "description": "The current state of one render. Poll this until `status` is `completed` or `failed`.",
        "operationId": "retrieveVideo",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The video.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Video"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No such video.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/videos/{id}/content": {
      "get": {
        "tags": [
          "Videos"
        ],
        "summary": "Download the video",
        "description": "Redirects (302) to the re-hosted mp4 once the render is `completed`. The same URL is in the video object’s `url`.",
        "operationId": "downloadVideo",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "302": {
            "description": "Redirect to the mp4."
          },
          "400": {
            "description": "The render has not completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No such video.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/models": {
      "get": {
        "tags": [
          "Catalog"
        ],
        "summary": "List models",
        "description": "The catalog of callable models, with per-model pricing (USD) and tunable params. Takes no query parameters.",
        "operationId": "listModels",
        "responses": {
          "200": {
            "description": "The model list.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ModelList"
                },
                "example": {
                  "object": "list",
                  "data": [
                    {
                      "id": "gemini-3.1-flash-lite",
                      "object": "model",
                      "created": 1735689600,
                      "owned_by": "altrouter",
                      "surface": "chat",
                      "context_length": 200000,
                      "pricing": {
                        "prompt_per_1m_usd": 1,
                        "completion_per_1m_usd": 4,
                        "approximate": false
                      },
                      "params": [
                        {
                          "key": "temperature",
                          "type": "slider",
                          "min": 0,
                          "max": 2,
                          "step": 0.1,
                          "default": 1
                        },
                        {
                          "key": "max_tokens",
                          "type": "number",
                          "min": 1,
                          "max": 32000
                        }
                      ]
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/credits": {
      "get": {
        "tags": [
          "Catalog"
        ],
        "summary": "Get credit balance",
        "description": "The remaining balance for the org that owns the API key. Takes no query parameters.",
        "operationId": "getCredits",
        "responses": {
          "200": {
            "description": "The current balance.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Credits"
                },
                "example": {
                  "object": "credits",
                  "available_usd": 42.5,
                  "balance_usd": 50,
                  "held_usd": 7.5
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/generation": {
      "get": {
        "tags": [
          "Usage"
        ],
        "summary": "Get the cost of a request",
        "description": "What one request cost: the usage row it left, with `cost_usd` — the amount that left the balance. `id` is the `x-request-id` header every response carries (a video’s `vid_…` id works too). Scoped to the org that owns the API key; a streamed chat is recorded a moment after `[DONE]`.",
        "operationId": "getGeneration",
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "req_mupii6w5aosvfxt9"
          }
        ],
        "responses": {
          "200": {
            "description": "The request’s usage and cost.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UsageEvent"
                },
                "example": {
                  "object": "generation",
                  "id": "6f1c2a8e-0000-4000-8000-000000000000",
                  "request_id": "req_mupii6w5aosvfxt9",
                  "created_at": "2026-10-01T12:00:00.000Z",
                  "surface": "chat",
                  "model": "gpt-5.6",
                  "outcome": "success",
                  "error_code": null,
                  "http_status": null,
                  "prompt_tokens": 1000,
                  "completion_tokens": 500,
                  "total_tokens": 1500,
                  "cost_usd": 0.008501,
                  "image_urls": null
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No usage recorded under this id for the key’s org.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/usage": {
      "get": {
        "tags": [
          "Usage"
        ],
        "summary": "List usage",
        "description": "The org’s requests, newest first, each with its `cost_usd` (failed and canceled requests appear with 0). Page with `next_cursor`.",
        "operationId": "listUsage",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "`next_cursor` of the previous page, passed back as is."
          }
        ],
        "responses": {
          "200": {
            "description": "One page of usage.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "type": "string",
                      "const": "list"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/UsageEvent"
                      }
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/billing/checkout": {
      "post": {
        "tags": [
          "Billing"
        ],
        "summary": "Create a top-up invoice",
        "description": "Opens an invoice with a payment provider for the org that owns the API key and returns its hosted `invoice_url`. Credits land automatically once paid; poll `GET /billing/payments/{id}` until `status` is `finished`. Send `Idempotency-Key` so a retry returns the same invoice instead of opening another (24 h, per API key; a different amount or method under the same key is 409).",
        "operationId": "createCheckout",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 255
            },
            "description": "Any unique string, e.g. your order id. A replay returns the original 201 body."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "amount_usd": {
                    "type": "number",
                    "minimum": 5,
                    "maximum": 10000,
                    "description": "Whole cents. Takes precedence over package_usd."
                  },
                  "package_usd": {
                    "type": "integer",
                    "enum": [
                      15,
                      50,
                      150,
                      500,
                      1500,
                      3000
                    ]
                  },
                  "method": {
                    "type": "string",
                    "enum": [
                      "crypto",
                      "crypto_platega",
                      "sbp",
                      "card"
                    ],
                    "default": "crypto",
                    "description": "Which are on right now: GET /billing/packages → methods."
                  },
                  "pay_currency": {
                    "type": "string",
                    "description": "With method crypto only: return a deposit address and exact amount in this coin+network instead of a hosted page (usdttrc20, usdtbsc, usdtton, usdterc20, usdtsol, usdtmatic, …). Below the network minimum or a coin that is off → 400 pay_currency_unavailable.",
                    "example": "usdtbsc"
                  }
                }
              },
              "example": {
                "amount_usd": 50,
                "method": "crypto_platega"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The invoice.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Payment"
                },
                "example": {
                  "object": "payment",
                  "id": "5c47e990-b3e2-454d-b307-671d89e4246a",
                  "status": "waiting",
                  "method": "crypto_platega",
                  "amount_usd": 50,
                  "invoice_url": "https://pay.platega.io/p/..."
                }
              }
            }
          },
          "400": {
            "description": "Bad amount, package, method or pay_currency (payment_method_unavailable, payment_method_limit, pay_currency_unavailable).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "idempotency_conflict: the key was used for a different checkout, or the same one is in flight.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many unpaid invoices (20) or checkouts this hour (20) for the org.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/billing/payments": {
      "get": {
        "tags": [
          "Billing"
        ],
        "summary": "List payments",
        "description": "The org’s payments, newest first. Page with `next_cursor`.",
        "operationId": "listPayments",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "`next_cursor` of the previous page, passed back as is."
          }
        ],
        "responses": {
          "200": {
            "description": "One page of payments.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "type": "string",
                      "const": "list"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Payment"
                      }
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/billing/payments/{id}": {
      "get": {
        "tags": [
          "Billing"
        ],
        "summary": "Get a payment",
        "description": "One payment with its live status. Another org’s id reads as 404.",
        "operationId": "getPayment",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The payment.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Payment"
                }
              }
            }
          },
          "400": {
            "description": "Not a uuid.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Payment not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Your altrouter key, e.g. `Authorization: Bearer ar-…`."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "message": {
                "type": "string"
              },
              "type": {
                "type": "string",
                "enum": [
                  "invalid_request_error",
                  "authentication_error",
                  "permission_error",
                  "not_found_error",
                  "rate_limit_error",
                  "insufficient_quota",
                  "content_policy_violation",
                  "api_error",
                  "service_unavailable"
                ]
              },
              "param": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "code": {
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "required": [
              "message",
              "type"
            ]
          }
        },
        "required": [
          "error"
        ]
      },
      "ChatCompletion": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "object": {
            "type": "string",
            "const": "chat.completion"
          },
          "created": {
            "type": "integer"
          },
          "model": {
            "type": "string"
          },
          "choices": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "index": {
                  "type": "integer"
                },
                "message": {
                  "type": "object",
                  "properties": {
                    "role": {
                      "type": "string"
                    },
                    "content": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "reasoning_content": {
                      "type": "string"
                    },
                    "tool_calls": {
                      "type": "array",
                      "items": {}
                    }
                  }
                },
                "finish_reason": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              }
            }
          },
          "usage": {
            "$ref": "#/components/schemas/Usage"
          }
        }
      },
      "ImageResponse": {
        "type": "object",
        "properties": {
          "created": {
            "type": "integer"
          },
          "data": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "url": {
                  "type": "string"
                },
                "b64_json": {
                  "type": "string"
                },
                "revised_prompt": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "ImageJob": {
        "type": "object",
        "description": "An image generation created with `\"async\": true`. Once `completed`, `data` and `usage` are what the blocking call returns.",
        "properties": {
          "id": {
            "type": "string",
            "description": "img_… - pass it to GET /images/generations/{id}."
          },
          "object": {
            "type": "string",
            "const": "image.generation"
          },
          "model": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "in_progress",
              "completed",
              "failed"
            ]
          },
          "created": {
            "type": "integer",
            "description": "Unix timestamp (seconds) of the request."
          },
          "completed_at": {
            "type": "integer"
          },
          "data": {
            "type": "array",
            "description": "The re-hosted images - present once completed.",
            "items": {
              "type": "object",
              "properties": {
                "url": {
                  "type": "string"
                }
              }
            }
          },
          "usage": {
            "type": "object",
            "properties": {
              "cost": {
                "type": "number",
                "description": "What the images cost, USD - present once completed."
              }
            }
          },
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        },
        "required": [
          "id",
          "object",
          "model",
          "status",
          "created"
        ]
      },
      "Video": {
        "type": "object",
        "description": "One render. Asynchronous: poll until `status` is `completed` or `failed`.",
        "properties": {
          "id": {
            "type": "string",
            "description": "vid_… - pass it to GET /videos/{id}."
          },
          "object": {
            "type": "string",
            "const": "video"
          },
          "model": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "in_progress",
              "completed",
              "failed"
            ]
          },
          "created_at": {
            "type": "integer",
            "description": "Unix timestamp (seconds)."
          },
          "completed_at": {
            "type": "integer"
          },
          "seconds": {
            "type": "integer",
            "description": "The clip length this render was priced on."
          },
          "url": {
            "type": "string",
            "description": "The re-hosted mp4 - present once completed."
          },
          "data": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "url": {
                  "type": "string"
                }
              }
            }
          },
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          },
          "cost": {
            "type": "number",
            "description": "What the render cost, USD - present once completed."
          }
        },
        "required": [
          "id",
          "object",
          "model",
          "status",
          "created_at"
        ]
      },
      "Usage": {
        "type": "object",
        "properties": {
          "prompt_tokens": {
            "type": "integer"
          },
          "completion_tokens": {
            "type": "integer"
          },
          "total_tokens": {
            "type": "integer"
          },
          "cost": {
            "type": "number",
            "description": "What the request cost, USD - the amount that left the balance. In a stream it rides the closing chunk (empty `choices`) before `[DONE]`."
          }
        }
      },
      "UsageEvent": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "usage_event",
              "generation"
            ]
          },
          "id": {
            "type": "string"
          },
          "request_id": {
            "type": [
              "string",
              "null"
            ],
            "description": "The `x-request-id` of the call (`vid_…` for a video, `img_…` for an async image)."
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "surface": {
            "type": "string",
            "enum": [
              "chat",
              "image",
              "video"
            ]
          },
          "model": {
            "type": "string"
          },
          "outcome": {
            "type": "string",
            "enum": [
              "success",
              "error",
              "canceled"
            ]
          },
          "error_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "http_status": {
            "type": [
              "integer",
              "null"
            ]
          },
          "key_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "prompt_tokens": {
            "type": [
              "integer",
              "null"
            ]
          },
          "completion_tokens": {
            "type": [
              "integer",
              "null"
            ]
          },
          "total_tokens": {
            "type": [
              "integer",
              "null"
            ]
          },
          "cost_usd": {
            "type": "number",
            "description": "Charged to the balance, USD."
          },
          "image_urls": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "string"
            }
          }
        }
      },
      "ModelList": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "const": "list"
          },
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Model"
            }
          }
        }
      },
      "Model": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "object": {
            "type": "string",
            "const": "model"
          },
          "created": {
            "type": "integer",
            "description": "Unix timestamp (seconds)."
          },
          "owned_by": {
            "type": "string",
            "const": "altrouter"
          },
          "surface": {
            "type": "string",
            "enum": [
              "chat",
              "image",
              "video"
            ]
          },
          "context_length": {
            "type": "integer",
            "description": "Max context window in tokens (chat models)."
          },
          "pricing": {
            "description": "Our sell price, in USD - ChatPricing, ImagePricing or VideoPricing, per the model’s surface.",
            "oneOf": [
              {
                "$ref": "#/components/schemas/ChatPricing"
              },
              {
                "$ref": "#/components/schemas/ImagePricing"
              },
              {
                "$ref": "#/components/schemas/VideoPricing"
              }
            ]
          },
          "params": {
            "type": "array",
            "description": "Tunable request parameters this model accepts.",
            "items": {
              "$ref": "#/components/schemas/ParamField"
            }
          }
        },
        "required": [
          "id",
          "object",
          "created",
          "owned_by",
          "surface",
          "pricing",
          "params"
        ]
      },
      "ChatPricing": {
        "type": "object",
        "description": "Sell price for a chat model, USD per 1M tokens.",
        "properties": {
          "prompt_per_1m_usd": {
            "type": "number"
          },
          "completion_per_1m_usd": {
            "type": "number"
          },
          "approximate": {
            "type": "boolean",
            "description": "True when the price is a pre-flight estimate (billed on actual usage)."
          },
          "discount_pct": {
            "type": "integer",
            "description": "Savings vs the official list price, when we are cheaper."
          },
          "official_prompt_per_1m_usd": {
            "type": "number"
          },
          "official_completion_per_1m_usd": {
            "type": "number"
          }
        },
        "required": [
          "prompt_per_1m_usd",
          "completion_per_1m_usd",
          "approximate"
        ]
      },
      "ImagePricing": {
        "type": "object",
        "description": "Sell price for an image model, USD per image.",
        "properties": {
          "per_image_usd": {
            "type": "number"
          },
          "per_image_4k_usd": {
            "type": "number",
            "description": "Price for the cheapest 4K-capable variant, when offered."
          },
          "approximate": {
            "type": "boolean"
          },
          "discount_pct": {
            "type": "integer"
          },
          "official_per_image_usd": {
            "type": "number"
          }
        },
        "required": [
          "per_image_usd",
          "approximate"
        ]
      },
      "VideoPricing": {
        "type": "object",
        "description": "Sell price for a video model. Length-priced models quote per second; models the upstream charges flat per clip quote per video.",
        "properties": {
          "per_second_usd": {
            "type": "number"
          },
          "per_video_usd": {
            "type": "number"
          },
          "approximate": {
            "type": "boolean"
          },
          "discount_pct": {
            "type": "integer"
          },
          "official_per_second_usd": {
            "type": "number"
          },
          "official_per_video_usd": {
            "type": "number"
          },
          "tiers": {
            "type": "array",
            "description": "Price per quality tier (value of the `resolution`/`quality` param) and, where sound is off by default and billed extra, with and without sound. per_second_usd above is the default tier.",
            "items": {
              "type": "object",
              "properties": {
                "resolution": {
                  "type": "string"
                },
                "audio": {
                  "type": "boolean"
                },
                "per_second_usd": {
                  "type": "number"
                },
                "per_video_usd": {
                  "type": "number"
                }
              }
            }
          }
        },
        "required": [
          "approximate"
        ]
      },
      "ParamField": {
        "type": "object",
        "description": "A tunable request parameter for a model (rendered as a control in the playground).",
        "properties": {
          "key": {
            "type": "string",
            "description": "The literal request field name."
          },
          "type": {
            "type": "string",
            "enum": [
              "slider",
              "number",
              "boolean",
              "select",
              "image",
              "text"
            ]
          },
          "default": {
            "type": [
              "number",
              "string",
              "boolean"
            ]
          },
          "min": {
            "type": "number"
          },
          "max": {
            "type": "number"
          },
          "step": {
            "type": "number"
          },
          "options": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        },
        "required": [
          "key",
          "type"
        ]
      },
      "Payment": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "const": "payment"
          },
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "created",
              "waiting",
              "confirming",
              "partially_paid",
              "finished",
              "failed",
              "refunded",
              "expired"
            ],
            "description": "`finished` = credited. Terminal: finished, failed, refunded, expired."
          },
          "provider": {
            "type": "string",
            "description": "GET only."
          },
          "method": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "crypto",
              "crypto_platega",
              "sbp",
              "card",
              null
            ]
          },
          "amount_usd": {
            "type": "number",
            "description": "Credits to be added, USD."
          },
          "charge": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "amount": {
                "type": "number"
              },
              "currency": {
                "type": "string"
              }
            },
            "description": "GET only: what the payer is charged when not the USD amount (e.g. RUB for sbp)."
          },
          "credited_usd": {
            "type": "number",
            "description": "GET only: what has landed on the balance."
          },
          "invoice_url": {
            "type": [
              "string",
              "null"
            ],
            "description": "The provider’s hosted payment page; null with pay_currency."
          },
          "deposit": {
            "type": [
              "object",
              "null"
            ],
            "description": "With pay_currency: send exactly pay_amount of pay_currency to pay_address (with extra_id as memo when set) before expires_at (2 h; unpaid by then → expired, a late payment still credits). USDT/USDC are priced in the coin itself, 1:1: pay_amount = amount_usd; other coins at the market rate.",
            "properties": {
              "pay_currency": {
                "type": "string"
              },
              "pay_amount": {
                "type": "number"
              },
              "pay_address": {
                "type": "string"
              },
              "extra_id": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "network": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "expires_at": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              }
            }
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "GET only."
          },
          "updated_at": {
            "type": "string",
            "format": "date-time",
            "description": "GET only."
          }
        },
        "required": [
          "object",
          "id",
          "status",
          "amount_usd",
          "invoice_url"
        ]
      },
      "Credits": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "const": "credits"
          },
          "available_usd": {
            "type": "number",
            "description": "Spendable balance (settled balance minus active holds), USD."
          },
          "balance_usd": {
            "type": "number",
            "description": "Total settled balance, USD."
          },
          "held_usd": {
            "type": "number",
            "description": "Funds reserved by in-flight requests, USD."
          }
        },
        "required": [
          "object",
          "available_usd",
          "balance_usd",
          "held_usd"
        ]
      }
    }
  }
}
