Vercel Chat API

Chat completions (OpenAI-compatible)

OpenAPI Specification

vercel-chat-api-openapi.yml Raw ↑
openapi: 3.1.0
info:
  title: Vercel AI Gateway Chat API
  description: The Vercel AI Gateway provides a unified API to access hundreds of AI models from multiple providers (Anthropic, OpenAI, Google, Meta, Mistral, and more) through a single endpoint. Features include one API key for hundreds of models, spend monitoring, automatic retries and fallbacks, provider routing by cost/latency/throughput, embeddings support, and zero markup on token pricing. Compatible with the AI SDK, OpenAI SDK, and Anthropic SDK.
  version: 1.0.0
  contact:
    name: Vercel Support
    url: https://vercel.com/help
  termsOfService: https://vercel.com/legal/terms
servers:
- url: https://ai-gateway.vercel.sh
  description: Vercel AI Gateway
security:
- BearerAuth: []
tags:
- name: Chat
  description: Chat completions (OpenAI-compatible)
paths:
  /v1/chat/completions:
    post:
      operationId: createChatCompletion
      summary: Create Chat Completion
      description: Create a chat completion using any model accessible via the Vercel AI Gateway. Supports streaming, tool calls, image inputs, and provider routing options. Compatible with the OpenAI Chat Completions API.
      tags:
      - Chat
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequest'
      responses:
        '200':
          description: Chat completion response or SSE stream
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletionResponse'
            text/event-stream:
              schema:
                type: string
                description: Server-sent events stream of completion chunks
        '401':
          $ref: '#/components/responses/Unauthorized'
        '429':
          $ref: '#/components/responses/RateLimitExceeded'
components:
  responses:
    Unauthorized:
      description: Missing or invalid Bearer token
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    RateLimitExceeded:
      description: Rate limit or spend limit exceeded
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  schemas:
    ProviderOptions:
      type: object
      description: Gateway-specific routing options
      properties:
        gateway:
          type: object
          properties:
            order:
              type: array
              items:
                type: string
              description: Ordered list of providers to try (fallback chain)
            sort:
              type: string
              enum:
              - cost
              - ttft
              - tps
              description: Automatically sort providers by cost, time-to-first-token, or tokens-per-second
    ChatCompletionRequest:
      type: object
      required:
      - model
      - messages
      properties:
        model:
          type: string
          description: Model ID in format 'provider/model-name' (e.g., 'anthropic/claude-opus-4.6', 'openai/gpt-4o')
          example: anthropic/claude-opus-4.6
        messages:
          type: array
          items:
            $ref: '#/components/schemas/Message'
          description: Conversation messages
        stream:
          type: boolean
          default: false
          description: Whether to stream the response using SSE
        temperature:
          type: number
          minimum: 0
          maximum: 2
          description: Sampling temperature
        max_tokens:
          type: integer
          description: Maximum tokens to generate
        tools:
          type: array
          items:
            $ref: '#/components/schemas/Tool'
          description: Available tools for the model
        tool_choice:
          oneOf:
          - type: string
            enum:
            - none
            - auto
            - required
          - type: object
          description: Tool selection strategy
        providerOptions:
          $ref: '#/components/schemas/ProviderOptions'
        provider:
          type: object
          properties:
            sort:
              type: string
              enum:
              - cost
              - ttft
              - tps
              description: Provider sorting strategy shorthand
    Tool:
      type: object
      properties:
        type:
          type: string
          enum:
          - function
        function:
          type: object
          properties:
            name:
              type: string
            description:
              type: string
            parameters:
              type: object
              description: JSON Schema for function parameters
    Message:
      type: object
      required:
      - role
      - content
      properties:
        role:
          type: string
          enum:
          - system
          - user
          - assistant
          - tool
          description: Message role
        content:
          oneOf:
          - type: string
            description: Text content
          - type: array
            description: Multi-modal content array
            items:
              oneOf:
              - type: object
                description: Text content part
                properties:
                  type:
                    type: string
                    enum:
                    - text
                  text:
                    type: string
              - type: object
                description: Image content part
                properties:
                  type:
                    type: string
                    enum:
                    - image_url
                  image_url:
                    type: object
                    properties:
                      url:
                        type: string
                        description: Image URL or base64 data URI
                      detail:
                        type: string
                        enum:
                        - auto
                        - low
                        - high
        name:
          type: string
          description: Optional name for the message author
        tool_call_id:
          type: string
          description: Tool call ID (for tool messages)
    ChatCompletionResponse:
      type: object
      properties:
        id:
          type: string
        object:
          type: string
          default: chat.completion
        created:
          type: integer
        model:
          type: string
        choices:
          type: array
          items:
            type: object
            properties:
              index:
                type: integer
              message:
                $ref: '#/components/schemas/Message'
              finish_reason:
                type: string
                enum:
                - stop
                - length
                - tool_calls
                - content_filter
        usage:
          type: object
          properties:
            prompt_tokens:
              type: integer
            completion_tokens:
              type: integer
            total_tokens:
              type: integer
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            type:
              type: string
            code:
              type: string
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: Vercel AI Gateway API key (AI_GATEWAY_API_KEY)