> ## Documentation Index
> Fetch the complete documentation index at: https://spillway.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI-compatible chat completion (streaming when `stream:true`).



## OpenAPI

````yaml /api-reference/openapi.json post /v1/chat/completions
openapi: 3.1.0
info:
  title: Spillway API
  version: 1.0.0
  description: >-
    The control plane for AI spend. One OpenAI-compatible gateway (`/v1/*`) plus
    a governance and administration API (`/api/*`). Request bodies are generated
    from the zod schemas in `@spillway/shared` — the single source of truth.
servers:
  - url: http://localhost:3000
    description: Local dev
security: []
paths:
  /v1/chat/completions:
    post:
      tags:
        - Gateway
      summary: OpenAI-compatible chat completion (streaming when `stream:true`).
      parameters:
        - schema:
            type: string
            maxLength: 256
            description: >-
              Pin this request to a routing session (sticky provider/model
              across a conversation). Header wins over body `session_id`.
            example: chat-7f3a2b
          required: false
          name: x-spillway-session-id
          in: header
        - schema:
            type: string
            description: >-
              Comma-separated capability hard-filter (e.g. `vision,tool_use`) —
              candidates lacking any listed capability are excluded. Header wins
              over body `spillway.require_capabilities`. Unknown capability →
              422.
            example: vision,tool_use
          required: false
          name: x-spillway-require-capabilities
          in: header
        - schema:
            type: string
            description: >-
              Disambiguate a model name served by multiple providers. Must be a
              known provider AND on the key's allow-list (403
              `model_not_allowed` otherwise).
            example: anthropic
          required: false
          name: x-spillway-provider
          in: header
        - schema:
            type: string
            description: >-
              Opt into per-request tracing: `on` / `1` / `true`
              (case-insensitive). The response then carries
              `x-spillway-trace-id`.
            example: 'on'
          required: false
          name: x-spillway-trace
          in: header
        - schema:
            type: string
            description: >-
              JSON object of request tags merged into the request `metadata` for
              reporting (body `metadata` wins on collision). Bounded: ≤16 keys
              total, key ≤64 chars, value ≤256 chars.
            example: '{"team":"platform","feature":"chat"}'
          required: false
          name: x-spillway-tags
          in: header
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                model:
                  type: string
                  minLength: 1
                messages:
                  type: array
                  items:
                    type: object
                    properties:
                      role:
                        type: string
                    required:
                      - role
                  minItems: 1
                stream:
                  type: boolean
                max_tokens:
                  type: integer
                  exclusiveMinimum: 0
                max_completion_tokens:
                  type: integer
                  exclusiveMinimum: 0
                metadata:
                  type: object
                  additionalProperties:
                    type: string
                    maxLength: 1024
              required:
                - model
                - messages
      responses:
        '200':
          description: >-
            Provider-shaped response (OpenAI/Anthropic JSON, or an SSE stream
            when streaming).
        default:
          description: Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - virtualKey: []
components:
  schemas:
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - budget_exceeded
                - rate_limited
                - model_not_allowed
                - key_not_found
                - key_revoked
                - key_paused
                - rule_deny
                - all_providers_failed
                - upstream_error
                - invalid_request
                - internal_error
                - unauthenticated
                - forbidden
                - not_found
                - conflict
                - validation_error
                - org_required
                - last_owner
                - key_expired
                - service_unavailable
                - no_candidates
                - provider_key_decrypt_failed
                - provider_unavailable
                - upstream_parse_error
                - request_too_large
                - model_not_found
                - no_route_available
                - approval_required
                - tier_required
                - plan_upgrade_required
                - cel_parse_error
                - cel_type_error
                - cel_cost_exceeded
                - cel_ast_too_large
                - cel_banned_macro
                - cel_regex_too_long
                - approval_chain_unsatisfiable
                - not_pending
                - self_approval_not_allowed
                - not_an_approver
                - unknown_effect
                - invalid_action_token
                - threshold_condition_not_isolated
            message:
              type: string
            details:
              type: object
              additionalProperties: {}
          required:
            - code
            - message
      required:
        - error
      description: Control-plane error envelope (§1.4).
  securitySchemes:
    virtualKey:
      type: http
      scheme: bearer
      description: >-
        Virtual key `mk-live-…` on the data plane. `x-api-key: mk-live-…` is
        also accepted.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.