{
  "openapi": "3.1.0",
  "info": {
    "title": "AIgateway",
    "version": "1",
    "summary": "One OpenAI-compatible API to every frontier and open-weight AI model.",
    "description": "OpenAI-compatible endpoints for chat, embeddings, images, audio, video, translation, classification, OCR, rerank, moderation, plus aggregator-native primitives (sub-accounts, evals, replays, batches, files, signed URLs, webhooks). Catalog: 150+ models across 44 labs. Change `base_url` on the OpenAI SDK to https://api.aigateway.sh/v1 and every existing integration works.",
    "contact": {
      "email": "support@aigateway.sh",
      "url": "https://aigateway.sh/support"
    },
    "termsOfService": "https://aigateway.sh/terms",
    "license": {
      "name": "Proprietary — commercial use permitted under the Terms of Service",
      "url": "https://aigateway.sh/terms"
    }
  },
  "servers": [
    {
      "url": "https://api.aigateway.sh/v1",
      "description": "Production gateway (edge)"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "externalDocs": {
    "description": "Full reference + SDK docs",
    "url": "https://aigateway.sh/reference"
  },
  "tags": [
    {
      "name": "chat",
      "description": "OpenAI-compatible chat completions (text, vision, tool use, streaming, reasoning)"
    },
    {
      "name": "embeddings",
      "description": "Text embeddings"
    },
    {
      "name": "images",
      "description": "Image generation"
    },
    {
      "name": "audio",
      "description": "STT, TTS, music"
    },
    {
      "name": "video",
      "description": "Async video + 3D generation"
    },
    {
      "name": "moderation",
      "description": "Content safety"
    },
    {
      "name": "modality-extra",
      "description": "Translation, classification, detection, OCR, rerank"
    },
    {
      "name": "jobs",
      "description": "Async job lifecycle"
    },
    {
      "name": "files",
      "description": "File upload, download, signed URLs"
    },
    {
      "name": "batches",
      "description": "OpenAI-style batch API at 50% off"
    },
    {
      "name": "sub-accounts",
      "description": "Per-customer scoped keys with spend caps"
    },
    {
      "name": "evals",
      "description": "Eval-driven model routing"
    },
    {
      "name": "replays",
      "description": "Replay any past request on a new model"
    },
    {
      "name": "usage",
      "description": "Per-tag and per-customer cost attribution"
    },
    {
      "name": "webhooks",
      "description": "Signed callbacks for jobs + lifecycle events"
    },
    {
      "name": "account",
      "description": "Balance + cache management"
    },
    {
      "name": "models",
      "description": "Catalog discovery"
    },
    {
      "name": "health",
      "description": "Provider health"
    }
  ],
  "paths": {
    "/chat/completions": {
      "post": {
        "tags": [
          "chat"
        ],
        "summary": "Create chat completion",
        "description": "Drop-in replacement for OpenAI's /v1/chat/completions. Supports streaming via SSE, tool calling, vision, JSON mode, and reasoning models with normalized `reasoning_content` deltas.",
        "operationId": "createChatCompletion",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatCompletionRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Chat completion (SSE if stream=true)"
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "402": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/embeddings": {
      "post": {
        "tags": [
          "embeddings"
        ],
        "summary": "Create embeddings",
        "operationId": "createEmbeddings",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "model",
                  "input"
                ],
                "properties": {
                  "model": {
                    "type": "string",
                    "example": "baai/bge-m3"
                  },
                  "input": {
                    "oneOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "array",
                        "items": {
                          "type": "string"
                        }
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Embedding vectors"
          }
        }
      }
    },
    "/images/generations": {
      "post": {
        "tags": [
          "images"
        ],
        "summary": "Generate image",
        "operationId": "createImage",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "model",
                  "prompt"
                ],
                "properties": {
                  "model": {
                    "type": "string",
                    "example": "black-forest-labs/flux-2-klein-9b"
                  },
                  "prompt": {
                    "type": "string"
                  },
                  "size": {
                    "type": "string",
                    "example": "1024x1024"
                  },
                  "quality": {
                    "type": "string",
                    "enum": [
                      "standard",
                      "hd"
                    ]
                  },
                  "style": {
                    "type": "string"
                  },
                  "response_format": {
                    "type": "string",
                    "enum": [
                      "url",
                      "b64_json"
                    ]
                  },
                  "n": {
                    "type": "integer",
                    "default": 1
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Image URL(s) or base64"
          }
        }
      }
    },
    "/audio/transcriptions": {
      "post": {
        "tags": [
          "audio"
        ],
        "summary": "Transcribe audio (STT)",
        "operationId": "createTranscription",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "model",
                  "file"
                ],
                "properties": {
                  "model": {
                    "type": "string",
                    "example": "deepgram/nova-3"
                  },
                  "file": {
                    "type": "string",
                    "format": "binary"
                  },
                  "language": {
                    "type": "string"
                  }
                }
              }
            },
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "model",
                  "audio_url"
                ],
                "properties": {
                  "model": {
                    "type": "string",
                    "example": "deepgram/nova-3"
                  },
                  "audio_url": {
                    "type": "string",
                    "format": "uri"
                  },
                  "language": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Transcription result"
          }
        }
      }
    },
    "/audio/speech": {
      "post": {
        "tags": [
          "audio"
        ],
        "summary": "Synthesize speech (TTS)",
        "operationId": "createSpeech",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "model",
                  "input"
                ],
                "properties": {
                  "model": {
                    "type": "string",
                    "example": "deepgram/aura-2-en"
                  },
                  "input": {
                    "type": "string"
                  },
                  "voice": {
                    "type": "string"
                  },
                  "response_format": {
                    "type": "string",
                    "enum": [
                      "mp3",
                      "opus",
                      "aac",
                      "flac"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Audio binary stream"
          }
        }
      }
    },
    "/moderations": {
      "post": {
        "tags": [
          "moderation"
        ],
        "summary": "Moderate content",
        "operationId": "createModeration",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "input"
                ],
                "properties": {
                  "model": {
                    "type": "string",
                    "example": "meta/llama-guard-3-8b"
                  },
                  "input": {
                    "oneOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "array",
                        "items": {
                          "type": "string"
                        }
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Per-category safety flags"
          }
        }
      }
    },
    "/translations": {
      "post": {
        "tags": [
          "modality-extra"
        ],
        "summary": "Translate text",
        "operationId": "createTranslation",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "text",
                  "source_lang",
                  "target_lang"
                ],
                "properties": {
                  "text": {
                    "type": "string"
                  },
                  "source_lang": {
                    "type": "string",
                    "example": "en"
                  },
                  "target_lang": {
                    "type": "string",
                    "example": "fr"
                  },
                  "model": {
                    "type": "string",
                    "example": "meta/m2m100-1.2b"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Translated text"
          }
        }
      }
    },
    "/classifications": {
      "post": {
        "tags": [
          "modality-extra"
        ],
        "summary": "Classify text",
        "operationId": "createClassification",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "input"
                ],
                "properties": {
                  "input": {
                    "oneOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "array",
                        "items": {
                          "type": "string"
                        }
                      }
                    ]
                  },
                  "model": {
                    "type": "string",
                    "example": "huggingface/distilbert-sst-2"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Label + score per input"
          }
        }
      }
    },
    "/detections": {
      "post": {
        "tags": [
          "modality-extra"
        ],
        "summary": "Detect objects in image",
        "operationId": "createDetection",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "image_url": {
                    "type": "string",
                    "format": "uri"
                  },
                  "image_b64": {
                    "type": "string"
                  },
                  "model": {
                    "type": "string",
                    "example": "facebook/detr-resnet-50"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Bounding boxes + labels"
          }
        }
      }
    },
    "/ocr": {
      "post": {
        "tags": [
          "modality-extra"
        ],
        "summary": "Extract text from image",
        "operationId": "createOcr",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "image_url": {
                    "type": "string",
                    "format": "uri"
                  },
                  "image_b64": {
                    "type": "string"
                  },
                  "model": {
                    "type": "string",
                    "example": "microsoft/trocr-base-printed"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Extracted text"
          }
        }
      }
    },
    "/rerank": {
      "post": {
        "tags": [
          "modality-extra"
        ],
        "summary": "Rerank documents",
        "operationId": "createRerank",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "query",
                  "documents"
                ],
                "properties": {
                  "query": {
                    "type": "string"
                  },
                  "documents": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "model": {
                    "type": "string",
                    "example": "baai/bge-reranker-base"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Documents ordered by relevance"
          }
        }
      }
    },
    "/videos/generations": {
      "post": {
        "tags": [
          "video"
        ],
        "summary": "Generate video (async)",
        "operationId": "createVideo",
        "description": "Returns 202 with a job id. Poll GET /jobs/{id} or pass webhook_url.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AsyncJobRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Job accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/JobAccepted"
                }
              }
            }
          }
        }
      }
    },
    "/audio/music": {
      "post": {
        "tags": [
          "audio"
        ],
        "summary": "Generate music (async)",
        "operationId": "createMusic",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AsyncJobRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Job accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/JobAccepted"
                }
              }
            }
          }
        }
      }
    },
    "/3d/generations": {
      "post": {
        "tags": [
          "video"
        ],
        "summary": "Generate 3D asset (async)",
        "operationId": "create3D",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AsyncJobRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Job accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/JobAccepted"
                }
              }
            }
          }
        }
      }
    },
    "/jobs/{id}": {
      "get": {
        "tags": [
          "jobs"
        ],
        "summary": "Get async job",
        "operationId": "getJob",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Job status + result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "jobs"
        ],
        "summary": "Cancel async job",
        "operationId": "cancelJob",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Cancelled"
          }
        }
      }
    },
    "/files": {
      "post": {
        "tags": [
          "files"
        ],
        "summary": "Upload file",
        "operationId": "uploadFile",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "file",
                  "purpose"
                ],
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary"
                  },
                  "purpose": {
                    "type": "string",
                    "enum": [
                      "batch",
                      "batch_output",
                      "fine-tune",
                      "assistants"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "File metadata",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/File"
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "files"
        ],
        "summary": "List files",
        "operationId": "listFiles",
        "parameters": [
          {
            "name": "purpose",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "File list"
          }
        }
      }
    },
    "/files/{id}": {
      "get": {
        "tags": [
          "files"
        ],
        "summary": "Get file metadata",
        "operationId": "getFile",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "File metadata"
          }
        }
      },
      "delete": {
        "tags": [
          "files"
        ],
        "summary": "Delete file",
        "operationId": "deleteFile",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted"
          }
        }
      }
    },
    "/files/{id}/content": {
      "get": {
        "tags": [
          "files"
        ],
        "summary": "Download file content",
        "operationId": "downloadFile",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Raw file bytes"
          }
        }
      }
    },
    "/files/jobs/{jobId}/{filename}/signed": {
      "get": {
        "tags": [
          "files"
        ],
        "summary": "Mint signed URL for a job result",
        "description": "Returns a publicly fetchable URL on media.aigateway.sh, valid until expires_at. Max expiry 7 days.",
        "operationId": "signJobFile",
        "parameters": [
          {
            "name": "jobId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "filename",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "expires_in",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 3600,
              "maximum": 604800
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Signed URL",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "url": {
                      "type": "string"
                    },
                    "expires_at": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/batches": {
      "post": {
        "tags": [
          "batches"
        ],
        "summary": "Create batch",
        "description": "Submits a JSONL file (uploaded via /files with purpose=batch) for batched inference at 50% off. SLA 24h.",
        "operationId": "createBatch",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "input_file_id",
                  "endpoint"
                ],
                "properties": {
                  "input_file_id": {
                    "type": "string"
                  },
                  "endpoint": {
                    "type": "string",
                    "example": "/v1/chat/completions"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Batch record",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Batch"
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "batches"
        ],
        "summary": "List batches",
        "operationId": "listBatches",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Batch list"
          }
        }
      }
    },
    "/batches/{id}": {
      "get": {
        "tags": [
          "batches"
        ],
        "summary": "Get batch",
        "operationId": "getBatch",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Batch record"
          }
        }
      }
    },
    "/batches/{id}/cancel": {
      "post": {
        "tags": [
          "batches"
        ],
        "summary": "Cancel batch",
        "operationId": "cancelBatch",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Cancelled"
          }
        }
      }
    },
    "/sub-accounts": {
      "post": {
        "tags": [
          "sub-accounts"
        ],
        "summary": "Create sub-account",
        "description": "Mints a scoped key for one of your end customers. Spend cap, RPM, default tag, isolated analytics.",
        "operationId": "createSubAccount",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "spend_cap_cents"
                ],
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "external_ref": {
                    "type": "string"
                  },
                  "spend_cap_cents": {
                    "type": "integer"
                  },
                  "rate_limit_rpm": {
                    "type": "integer"
                  },
                  "default_tag": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Sub-account record (key shown once)"
          }
        }
      },
      "get": {
        "tags": [
          "sub-accounts"
        ],
        "summary": "List sub-accounts",
        "operationId": "listSubAccounts",
        "responses": {
          "200": {
            "description": "Sub-account list"
          }
        }
      }
    },
    "/sub-accounts/{id}": {
      "get": {
        "tags": [
          "sub-accounts"
        ],
        "summary": "Get sub-account",
        "operationId": "getSubAccount",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Sub-account record"
          }
        }
      },
      "patch": {
        "tags": [
          "sub-accounts"
        ],
        "summary": "Update sub-account",
        "operationId": "updateSubAccount",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Updated record"
          }
        }
      },
      "delete": {
        "tags": [
          "sub-accounts"
        ],
        "summary": "Delete sub-account",
        "operationId": "deleteSubAccount",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted"
          }
        }
      }
    },
    "/sub-accounts/{id}/usage": {
      "get": {
        "tags": [
          "sub-accounts"
        ],
        "summary": "Per-customer usage",
        "operationId": "subAccountUsage",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "month",
            "in": "query",
            "schema": {
              "type": "string",
              "example": "2026-04"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Usage report"
          }
        }
      }
    },
    "/evals": {
      "post": {
        "tags": [
          "evals"
        ],
        "summary": "Create eval run",
        "description": "Run an eval across candidate models on your dataset. Returns an id you can use as `model: 'eval:<id>'` to always route to the current winner.",
        "operationId": "createEval",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "candidate_models",
                  "dataset",
                  "metric"
                ],
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "candidate_models": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "dataset": {
                    "type": "array",
                    "items": {
                      "type": "object"
                    }
                  },
                  "metric": {
                    "type": "string",
                    "enum": [
                      "quality",
                      "cost",
                      "speed"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Eval run started"
          }
        }
      },
      "get": {
        "tags": [
          "evals"
        ],
        "summary": "List eval runs",
        "operationId": "listEvals",
        "responses": {
          "200": {
            "description": "Eval list"
          }
        }
      }
    },
    "/evals/{id}": {
      "get": {
        "tags": [
          "evals"
        ],
        "summary": "Get eval",
        "operationId": "getEval",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Eval result + winner_model"
          }
        }
      }
    },
    "/replays": {
      "post": {
        "tags": [
          "replays"
        ],
        "summary": "Replay a past request on a new model",
        "operationId": "createReplay",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "source_request_id",
                  "target_model"
                ],
                "properties": {
                  "source_request_id": {
                    "type": "string"
                  },
                  "target_model": {
                    "type": "string"
                  },
                  "shadow": {
                    "type": "boolean",
                    "default": false
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Side-by-side cost / latency / output diff"
          }
        }
      },
      "get": {
        "tags": [
          "replays"
        ],
        "summary": "List replays",
        "operationId": "listReplays",
        "responses": {
          "200": {
            "description": "Replay list"
          }
        }
      }
    },
    "/replays/{id}": {
      "get": {
        "tags": [
          "replays"
        ],
        "summary": "Get replay",
        "operationId": "getReplay",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Replay record"
          }
        }
      }
    },
    "/usage/by-tag": {
      "get": {
        "tags": [
          "usage"
        ],
        "summary": "Usage by tag",
        "operationId": "usageByTag",
        "parameters": [
          {
            "name": "month",
            "in": "query",
            "schema": {
              "type": "string",
              "example": "2026-04"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Aggregated usage per tag"
          }
        }
      }
    },
    "/usage/by-sub-account": {
      "get": {
        "tags": [
          "usage"
        ],
        "summary": "Usage by sub-account",
        "operationId": "usageBySubAccount",
        "parameters": [
          {
            "name": "month",
            "in": "query",
            "schema": {
              "type": "string",
              "example": "2026-04"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Aggregated usage per customer"
          }
        }
      }
    },
    "/budgets": {
      "post": {
        "tags": [
          "usage"
        ],
        "summary": "Set monthly budget for a tag",
        "operationId": "createBudget",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "tag",
                  "cap_cents"
                ],
                "properties": {
                  "tag": {
                    "type": "string"
                  },
                  "cap_cents": {
                    "type": "integer"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Budget created"
          }
        }
      }
    },
    "/balance": {
      "get": {
        "tags": [
          "account"
        ],
        "summary": "Wallet balance",
        "operationId": "getBalance",
        "responses": {
          "200": {
            "description": "Balance",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "cents": {
                      "type": "integer"
                    },
                    "usd": {
                      "type": "number"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/cache": {
      "delete": {
        "tags": [
          "account"
        ],
        "summary": "Purge cache",
        "description": "Drops every entry in the exact-match KV cache and the semantic Vectorize cache for the authenticated account.",
        "operationId": "purgeCache",
        "responses": {
          "200": {
            "description": "Purged"
          }
        }
      }
    },
    "/webhook-secret": {
      "get": {
        "tags": [
          "webhooks"
        ],
        "summary": "Get signing secret",
        "operationId": "getWebhookSecret",
        "responses": {
          "200": {
            "description": "Signing secret"
          }
        }
      }
    },
    "/webhook-secret/rotate": {
      "post": {
        "tags": [
          "webhooks"
        ],
        "summary": "Rotate signing secret",
        "operationId": "rotateWebhookSecret",
        "responses": {
          "200": {
            "description": "New secret"
          }
        }
      }
    },
    "/models": {
      "get": {
        "tags": [
          "models"
        ],
        "summary": "List models",
        "operationId": "listModels",
        "parameters": [
          {
            "name": "modality",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "text",
                "image",
                "audio-stt",
                "audio-tts",
                "video",
                "embedding",
                "rerank",
                "moderation"
              ]
            }
          },
          {
            "name": "provider",
            "in": "query",
            "schema": {
              "type": "string",
              "example": "anthropic"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OpenAI-shaped model list with pricing + capabilities"
          }
        }
      }
    },
    "/models/{id}": {
      "get": {
        "tags": [
          "models"
        ],
        "summary": "Get model detail",
        "operationId": "getModel",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "example": "anthropic/claude-opus-4.7"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Single-model record"
          }
        }
      }
    },
    "/health/providers": {
      "get": {
        "tags": [
          "health"
        ],
        "summary": "Provider health",
        "operationId": "providerHealth",
        "responses": {
          "200": {
            "description": "p50, p95, error rate per upstream"
          }
        }
      }
    }
  },
  "webhooks": {
    "aigatewayEvent": {
      "post": {
        "summary": "Signed webhook callback",
        "description": "Fired for async job results AND lifecycle events. Verify x-aig-signature with HMAC-SHA256 over `${t}.${raw_body}` using the secret from /v1/webhook-secret. Failed deliveries retry on a 6-attempt schedule: 0s, 30s, 2m, 10m, 1h, 6h.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEvent"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Acknowledged"
          },
          "2XX": {
            "description": "Anything 2xx counts as delivered"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "sk-aig-..."
      }
    },
    "parameters": {
      "RequestId": {
        "name": "X-Request-Id",
        "in": "header",
        "required": false,
        "schema": {
          "type": "string"
        },
        "description": "Correlation id; echoed in response"
      },
      "AigTag": {
        "name": "x-aig-tag",
        "in": "header",
        "required": false,
        "schema": {
          "type": "string"
        },
        "description": "Free-form cost-attribution tag"
      },
      "Cache": {
        "name": "x-cache",
        "in": "header",
        "required": false,
        "schema": {
          "type": "string",
          "enum": [
            "auto",
            "force",
            "skip"
          ]
        }
      },
      "Routing": {
        "name": "x-routing",
        "in": "header",
        "required": false,
        "schema": {
          "type": "string",
          "enum": [
            "cost",
            "speed",
            "quality",
            "auto"
          ]
        }
      }
    },
    "headers": {
      "X-Request-Id": {
        "description": "Echo of inbound or generated UUID",
        "schema": {
          "type": "string"
        }
      },
      "X-Model": {
        "description": "The model the gateway actually dispatched to",
        "schema": {
          "type": "string"
        }
      },
      "X-Provider": {
        "description": "The upstream provider",
        "schema": {
          "type": "string"
        }
      },
      "X-Latency-Ms": {
        "description": "Wall-clock latency of the upstream call",
        "schema": {
          "type": "integer"
        }
      },
      "X-Cache-Status": {
        "description": "hit|miss + type=exact|semantic",
        "schema": {
          "type": "string"
        }
      },
      "X-Cost-Cents": {
        "description": "Cost charged for this request, fractional cents",
        "schema": {
          "type": "number"
        }
      },
      "X-Input-Units": {
        "description": "Input units billed (tokens / images / seconds)",
        "schema": {
          "type": "number"
        }
      },
      "X-Output-Units": {
        "description": "Output units billed",
        "schema": {
          "type": "number"
        }
      }
    },
    "responses": {
      "Error": {
        "description": "OpenAI-shaped error envelope",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "required": [
                "error"
              ],
              "properties": {
                "error": {
                  "type": "object",
                  "required": [
                    "message",
                    "type"
                  ],
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "type": {
                      "type": "string",
                      "enum": [
                        "invalid_request_error",
                        "authentication_error",
                        "budget_exceeded",
                        "model_not_found",
                        "rate_limit_error",
                        "provider_error",
                        "timeout_error"
                      ]
                    },
                    "code": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "schemas": {
      "ChatCompletionRequest": {
        "type": "object",
        "required": [
          "model",
          "messages"
        ],
        "properties": {
          "model": {
            "type": "string",
            "description": "Provider-qualified slug. Featured: anthropic/claude-opus-4.7, openai/gpt-5.4, google/gemini-3.1-pro, moonshot/kimi-k2.6, anthropic/claude-sonnet-4.6, minimax/m2.7, openai/gpt-5.4-mini, xai/grok-4, google/gemini-3-flash, anthropic/claude-haiku-4.5. Fetch full list from /models. Catalog: 150+.",
            "example": "anthropic/claude-opus-4.7"
          },
          "messages": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "role",
                "content"
              ],
              "properties": {
                "role": {
                  "type": "string",
                  "enum": [
                    "system",
                    "user",
                    "assistant",
                    "tool"
                  ]
                },
                "content": {
                  "oneOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "array"
                    }
                  ]
                }
              }
            }
          },
          "stream": {
            "type": "boolean",
            "default": false
          },
          "temperature": {
            "type": "number"
          },
          "max_tokens": {
            "type": "integer"
          },
          "tools": {
            "type": "array"
          },
          "tool_choice": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "object"
              }
            ]
          },
          "response_format": {
            "type": "object"
          },
          "webhook_url": {
            "type": "string",
            "format": "uri",
            "description": "If set, delivery flips to async-job mode (202 + signed callback)"
          }
        }
      },
      "AsyncJobRequest": {
        "type": "object",
        "required": [
          "prompt"
        ],
        "properties": {
          "prompt": {
            "type": "string"
          },
          "model": {
            "type": "string"
          },
          "duration": {
            "type": "number"
          },
          "aspect_ratio": {
            "type": "string"
          },
          "resolution": {
            "type": "string"
          },
          "image_url": {
            "type": "string",
            "format": "uri"
          },
          "webhook_url": {
            "type": "string",
            "format": "uri"
          }
        }
      },
      "JobAccepted": {
        "type": "object",
        "required": [
          "id",
          "status",
          "object"
        ],
        "properties": {
          "id": {
            "type": "string",
            "example": "job_abc123"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued"
            ]
          },
          "object": {
            "type": "string",
            "enum": [
              "job"
            ]
          }
        }
      },
      "Job": {
        "type": "object",
        "required": [
          "id",
          "status"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "processing",
              "completed",
              "failed"
            ]
          },
          "modality": {
            "type": "string"
          },
          "model": {
            "type": "string"
          },
          "created_at": {
            "type": "integer"
          },
          "updated_at": {
            "type": "integer"
          },
          "error": {
            "type": "object",
            "properties": {
              "message": {
                "type": "string"
              },
              "code": {
                "type": "string"
              }
            }
          },
          "result_file_id": {
            "type": "string"
          },
          "result_url": {
            "type": "string",
            "format": "uri"
          },
          "webhook_url": {
            "type": "string",
            "format": "uri"
          },
          "webhook_delivered": {
            "type": "boolean"
          },
          "attempts": {
            "type": "integer"
          }
        }
      },
      "File": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "file-abc"
          },
          "object": {
            "type": "string",
            "enum": [
              "file"
            ]
          },
          "bytes": {
            "type": "integer"
          },
          "created_at": {
            "type": "integer"
          },
          "filename": {
            "type": "string"
          },
          "purpose": {
            "type": "string"
          }
        }
      },
      "Batch": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "object": {
            "type": "string",
            "enum": [
              "batch"
            ]
          },
          "endpoint": {
            "type": "string"
          },
          "input_file_id": {
            "type": "string"
          },
          "completion_window": {
            "type": "string",
            "example": "24h"
          },
          "status": {
            "type": "string",
            "enum": [
              "validating",
              "queued",
              "in_progress",
              "finalizing",
              "completed",
              "failed",
              "expired"
            ]
          },
          "output_file_id": {
            "type": "string"
          },
          "error_file_id": {
            "type": "string"
          },
          "request_counts": {
            "type": "object",
            "properties": {
              "processing": {
                "type": "integer"
              },
              "completed": {
                "type": "integer"
              },
              "failed": {
                "type": "integer"
              }
            }
          },
          "created_at": {
            "type": "integer"
          },
          "expires_at": {
            "type": "integer"
          },
          "completed_at": {
            "type": "integer"
          }
        }
      },
      "WebhookEvent": {
        "type": "object",
        "required": [
          "id",
          "type",
          "occurred_at",
          "data"
        ],
        "properties": {
          "id": {
            "type": "string",
            "example": "evt_01jx..."
          },
          "type": {
            "type": "string",
            "enum": [
              "job.completed",
              "job.failed",
              "balance.low",
              "balance.exhausted",
              "usage.threshold.exceeded",
              "usage.daily.summary",
              "subaccount.created",
              "subaccount.spend.exceeded",
              "model.added",
              "model.deprecated",
              "key.rotated"
            ]
          },
          "occurred_at": {
            "type": "integer",
            "description": "Unix seconds"
          },
          "data": {
            "type": "object",
            "description": "Event-type-specific payload"
          }
        }
      }
    }
  },
  "x-featured-models": [
    "anthropic/claude-opus-4.7",
    "openai/gpt-5.4",
    "google/gemini-3.1-pro",
    "moonshot/kimi-k2.6",
    "anthropic/claude-sonnet-4.6",
    "minimax/m2.7",
    "openai/gpt-5.4-mini",
    "xai/grok-4",
    "google/gemini-3-flash",
    "anthropic/claude-haiku-4.5"
  ],
  "x-model-count": "150+",
  "x-llms-txt": "https://aigateway.sh/llms.txt",
  "x-llms-full-txt": "https://aigateway.sh/llms-full.txt",
  "x-mcp-endpoint": "https://api.aigateway.sh/mcp",
  "x-webhook-headers": {
    "signature": "x-aig-signature",
    "eventType": "x-aig-event-type",
    "deliveryId": "x-aig-delivery-id",
    "attempt": "x-aig-attempt",
    "retrySchedule": "0s, 30s, 2m, 10m, 1h, 6h"
  }
}