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

# Chat Completions

> OpenAI-compatible chat completions endpoint.

Auth:        Authorization: Bearer rsk_<ULID>
Streaming:   set stream=true for SSE chunks
Templates:   set template="name" + variables={...}
Rate limits: RPM and RPD enforced per key via Redis fixed-window counters
Spend cap:   enforced if key.spend_cap_usd is set (soft cap)



## OpenAPI

````yaml /api/openapi.json post /v1/chat/completions
openapi: 3.1.0
info:
  title: MeshAPI
  description: One key, all AI models.
  version: 0.1.0
servers:
  - url: https://api.meshapi.ai
security:
  - BearerAuth: []
paths:
  /v1/chat/completions:
    post:
      tags:
        - Chat
      summary: Chat Completions
      description: >-
        OpenAI-compatible chat completions endpoint.


        Auth:        Authorization: Bearer rsk_<ULID>

        Streaming:   set stream=true for SSE chunks

        Templates:   set template="name" + variables={...}

        Rate limits: RPM and RPD enforced per key via Redis fixed-window
        counters

        Spend cap:   enforced if key.spend_cap_usd is set (soft cap)
      operationId: chat_completions
      parameters:
        - in: header
          name: X-Mesh-Version
          required: false
          schema:
            type: string
            enum:
              - 2026-08
            default: 2026-08
          example: 2026-08
          description: >-
            Dated version of the API contract to pin this request to. Omit it
            and the request is served under `2026-08` — the oldest supported
            version, so an existing integration is never moved by a release. A
            malformed or unsupported value is rejected with `400
            invalid_api_version` rather than falling back silently. The version
            actually served is echoed as `X-Mesh-Version` on every response,
            including errors.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequest'
            examples:
              default:
                summary: Example request
                value:
                  model: anthropic/claude-haiku-4.5
                  messages:
                    - role: user
                      content: Say hi in one sentence.
                  temperature: 0.2
      responses:
        '200':
          description: Completion (JSON), or an SSE stream when stream=true
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletionResponse'
              examples:
                default:
                  summary: Successful chat completion
                  value:
                    id: chatcmpl-DxC3eeQ6uBWSljHJ0MzxY3ZcGykl0
                    object: chat.completion
                    created: 1783000074
                    model: gpt-4o-2024-08-06
                    choices:
                      - index: 0
                        message:
                          role: assistant
                          content: Hi there! How can I assist you today?
                          annotations: []
                        finish_reason: stop
                    usage:
                      prompt_tokens: 12
                      completion_tokens: 10
                      total_tokens: 22
                      prompt_tokens_details:
                        cached_tokens: 0
                        audio_tokens: 0
                      completion_tokens_details:
                        reasoning_tokens: 0
                        audio_tokens: 0
                        accepted_prediction_tokens: 0
                        rejected_prediction_tokens: 0
                    service_tier: default
                    system_fingerprint: fp_42864b4b2b
            text/event-stream:
              example: >+
                data:
                {"id":"gen-1748331628-ABCdef123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}


                data: [DONE]

        '400':
          description: Model does not support chat completions API
          content:
            application/json:
              example:
                error:
                  code: model_capability_not_supported
                  message: >-
                    Model 'text-embedding-3-small' does not support the
                    chat/completions API.
                request_id: req_01ARZ3NDEKTSV4RRFFQ69G5FAV
        '401':
          description: Missing or invalid API key
          content:
            application/json:
              example:
                error:
                  code: unauthorized
                  message: Invalid or missing API key.
                request_id: req_01ARZ3NDEKTSV4RRFFQ69G5FAV
        '402':
          description: Insufficient balance or spend cap reached
          content:
            application/json:
              examples:
                spend_cap_reached:
                  summary: Per-key spend cap reached
                  value:
                    error:
                      code: spend_limit_exceeded
                      message: >-
                        Spend cap of $10.0000 reached. Current spend: $10.0023.
                        Contact your administrator to increase the cap.
                    request_id: req_01ARZ3NDEKTSV4RRFFQ69G5FAV
                no_balance:
                  summary: Insufficient credit balance
                  value:
                    error:
                      code: spend_limit_exceeded
                      message: >-
                        Insufficient balance. Top up your account to use paid
                        models.
                    request_id: req_01ARZ3NDEKTSV4RRFFQ69G5FAV
        '403':
          description: API key is suspended
          content:
            application/json:
              example:
                error:
                  code: forbidden
                  message: API key is suspended.
                request_id: req_01ARZ3NDEKTSV4RRFFQ69G5FAV
        '404':
          description: Prompt template not found
          content:
            application/json:
              example:
                error:
                  code: not_found
                  message: Template '01ARZ3NDEKTSV4RRFFQ69G5FAV' not found.
                request_id: req_01ARZ3NDEKTSV4RRFFQ69G5FAV
        '422':
          description: Request validation failed
          content:
            application/json:
              example:
                error:
                  code: validation_error
                  message: Request validation failed.
                  details:
                    - type: missing
                      loc:
                        - body
                        - model
                      msg: Field required
                request_id: req_01ARZ3NDEKTSV4RRFFQ69G5FAV
        '429':
          description: Rate limit exceeded (RPM or RPD)
          content:
            application/json:
              examples:
                rpm_exceeded:
                  summary: Requests-per-minute limit hit
                  value:
                    error:
                      code: rate_limit_exceeded
                      message: RPM limit of 60 req/min exceeded.
                    request_id: req_01ARZ3NDEKTSV4RRFFQ69G5FAV
                rpd_exceeded:
                  summary: Requests-per-day limit hit
                  value:
                    error:
                      code: rate_limit_exceeded
                      message: RPD limit of 1000 req/day exceeded.
                    request_id: req_01ARZ3NDEKTSV4RRFFQ69G5FAV
        '500':
          description: Upstream provider error or gateway timeout
          content:
            application/json:
              examples:
                upstream_error:
                  summary: Upstream provider returned an error
                  value:
                    error:
                      code: upstream_error
                      message: Upstream provider returned an error.
                      upstream_detail: >-
                        {"error":{"message":"No endpoints found that match your
                        data policy","code":400}}
                    request_id: req_01ARZ3NDEKTSV4RRFFQ69G5FAV
                gateway_timeout:
                  summary: Upstream timed out
                  value:
                    error:
                      code: gateway_timeout
                      message: Upstream provider did not respond in time.
                    request_id: req_01ARZ3NDEKTSV4RRFFQ69G5FAV
                internal_error:
                  summary: >-
                    Internal platform error (DB failure — FastAPI default
                    format)
                  value:
                    detail: Internal Server Error
        '503':
          description: Upstream provider temporarily unavailable
          content:
            application/json:
              example:
                error:
                  code: provider_not_available
                  message: >-
                    The model provider is temporarily unavailable. Please try
                    again shortly.
                request_id: req_01ARZ3NDEKTSV4RRFFQ69G5FAV
      security:
        - BearerAuth: []
components:
  schemas:
    ChatCompletionRequest:
      properties:
        model:
          anyOf:
            - type: string
            - type: 'null'
          title: Model
        messages:
          items:
            $ref: '#/components/schemas/Message'
          type: array
          title: Messages
        template:
          anyOf:
            - type: string
            - type: 'null'
          title: Template
        variables:
          anyOf:
            - additionalProperties:
                type: string
              type: object
            - type: 'null'
          title: Variables
        session_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Session Id
        stream:
          type: boolean
          title: Stream
          default: false
        temperature:
          anyOf:
            - type: number
              maximum: 2
              minimum: 0
            - type: 'null'
          title: Temperature
        max_tokens:
          anyOf:
            - type: integer
              minimum: 1
            - type: 'null'
          title: Max Tokens
        top_p:
          anyOf:
            - type: number
              maximum: 1
              minimum: 0
            - type: 'null'
          title: Top P
        frequency_penalty:
          anyOf:
            - type: number
              maximum: 2
              minimum: -2
            - type: 'null'
          title: Frequency Penalty
        presence_penalty:
          anyOf:
            - type: number
              maximum: 2
              minimum: -2
            - type: 'null'
          title: Presence Penalty
        stop:
          anyOf:
            - type: string
            - items:
                type: string
              type: array
            - type: 'null'
          title: Stop
        seed:
          anyOf:
            - type: integer
            - type: 'null'
          title: Seed
        reasoning_effort:
          anyOf:
            - type: string
              enum:
                - high
                - medium
                - low
                - none
            - type: 'null'
          title: Reasoning Effort
        tools:
          anyOf:
            - items:
                $ref: '#/components/schemas/Tool'
              type: array
            - type: 'null'
          title: Tools
        tool_choice:
          anyOf:
            - type: string
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Tool Choice
        response_format:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Response Format
        transforms:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Transforms
        models:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Models
        user:
          anyOf:
            - type: string
              maxLength: 256
            - type: 'null'
          title: User
        modality:
          anyOf:
            - type: string
              enum:
                - text
                - image
            - type: 'null'
          title: Modality
        image:
          anyOf:
            - $ref: '#/components/schemas/ImageOptions'
            - type: 'null'
        async_mode:
          type: boolean
          title: Async Mode
          default: false
        modalities:
          anyOf:
            - items:
                type: string
                enum:
                  - text
                  - audio
                  - image
              type: array
            - type: 'null'
          title: Modalities
        audio:
          anyOf:
            - $ref: '#/components/schemas/AudioOutputOptions'
            - type: 'null'
        timeout:
          anyOf:
            - type: number
              exclusiveMinimum: 0
            - type: 'null'
          title: Timeout
        cache:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Cache
      type: object
      required:
        - messages
      title: ChatCompletionRequest
      example:
        messages:
          - content: say hi
            role: user
        model: anthropic/claude-haiku-4.5
    ChatCompletionResponse:
      properties:
        id:
          type: string
          title: Id
        object:
          type: string
          title: Object
        created:
          type: integer
          title: Created
        model:
          type: string
          title: Model
        choices:
          items:
            $ref: '#/components/schemas/Choice'
          type: array
          title: Choices
        usage:
          anyOf:
            - $ref: '#/components/schemas/UsageInfo'
            - type: 'null'
        system_fingerprint:
          anyOf:
            - type: string
            - type: 'null'
          title: System Fingerprint
      type: object
      required:
        - id
        - object
        - created
        - model
        - choices
      title: ChatCompletionResponse
    Message:
      properties:
        role:
          type: string
          enum:
            - system
            - user
            - assistant
            - tool
          title: Role
        content:
          anyOf:
            - type: string
            - items:
                $ref: '#/components/schemas/ContentPart'
              type: array
            - type: 'null'
          title: Content
        name:
          anyOf:
            - type: string
            - type: 'null'
          title: Name
        tool_call_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Tool Call Id
        tool_calls:
          anyOf:
            - items:
                $ref: '#/components/schemas/ToolCall'
              type: array
            - type: 'null'
          title: Tool Calls
        reasoning_details:
          anyOf:
            - items:
                additionalProperties: true
                type: object
              type: array
            - type: 'null'
          title: Reasoning Details
        cache_control:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Cache Control
      type: object
      required:
        - role
      title: Message
    Tool:
      properties:
        type:
          type: string
          const: function
          title: Type
          default: function
        function:
          $ref: '#/components/schemas/ToolFunction'
      type: object
      required:
        - function
      title: Tool
    ImageOptions:
      properties:
        'n':
          type: integer
          maximum: 10
          minimum: 1
          title: 'N'
          default: 1
        size:
          type: string
          title: Size
          default: auto
        quality:
          type: string
          title: Quality
          default: auto
        response_format:
          type: string
          enum:
            - url
            - b64_json
          title: Response Format
          default: url
        output_format:
          anyOf:
            - type: string
              enum:
                - png
                - jpeg
                - webp
            - type: 'null'
          title: Output Format
        output_compression:
          anyOf:
            - type: integer
              maximum: 100
              minimum: 0
            - type: 'null'
          title: Output Compression
        background:
          anyOf:
            - type: string
              enum:
                - transparent
                - opaque
                - auto
            - type: 'null'
          title: Background
        moderation:
          anyOf:
            - type: string
              enum:
                - low
                - auto
            - type: 'null'
          title: Moderation
        partial_images:
          anyOf:
            - type: integer
              maximum: 3
              minimum: 0
            - type: 'null'
          title: Partial Images
        aspect_ratio:
          anyOf:
            - type: string
            - type: 'null'
          title: Aspect Ratio
        resolution:
          anyOf:
            - type: string
            - type: 'null'
          title: Resolution
        image:
          anyOf:
            - type: string
            - items:
                type: string
              type: array
            - type: 'null'
          title: Image
        seed:
          anyOf:
            - type: integer
              maximum: 2147483647
              minimum: -1
            - type: 'null'
          title: Seed
        sequential_image_generation:
          anyOf:
            - type: string
              enum:
                - auto
                - disabled
            - type: 'null'
          title: Sequential Image Generation
        sequential_image_generation_options:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Sequential Image Generation Options
        guidance_scale:
          anyOf:
            - type: number
              maximum: 10
              minimum: 1
            - type: 'null'
          title: Guidance Scale
        watermark:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Watermark
        optimize_prompt:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Optimize Prompt
        optimize_prompt_options:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Optimize Prompt Options
      type: object
      title: ImageOptions
    AudioOutputOptions:
      properties:
        voice:
          type: string
          title: Voice
          default: alloy
        format:
          type: string
          enum:
            - wav
            - mp3
            - flac
            - opus
            - pcm16
          title: Format
          default: wav
      type: object
      title: AudioOutputOptions
    Choice:
      properties:
        index:
          type: integer
          title: Index
        message:
          anyOf:
            - $ref: '#/components/schemas/Message'
            - type: 'null'
        delta:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Delta
        finish_reason:
          anyOf:
            - type: string
            - type: 'null'
          title: Finish Reason
        logprobs:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Logprobs
      type: object
      required:
        - index
      title: Choice
    UsageInfo:
      properties:
        prompt_tokens:
          type: integer
          title: Prompt Tokens
        completion_tokens:
          type: integer
          title: Completion Tokens
        total_tokens:
          type: integer
          title: Total Tokens
        input_tokens_details:
          anyOf:
            - additionalProperties:
                type: integer
              type: object
            - type: 'null'
          title: Input Tokens Details
        output_tokens_details:
          anyOf:
            - additionalProperties:
                type: integer
              type: object
            - type: 'null'
          title: Output Tokens Details
      type: object
      required:
        - prompt_tokens
        - completion_tokens
        - total_tokens
      title: UsageInfo
    ContentPart:
      properties:
        type:
          type: string
          enum:
            - text
            - image_url
            - video_url
            - input_audio
          title: Type
        text:
          anyOf:
            - type: string
            - type: 'null'
          title: Text
        image_url:
          anyOf:
            - $ref: '#/components/schemas/ImageUrl'
            - type: 'null'
        video_url:
          anyOf:
            - $ref: '#/components/schemas/VideoUrl'
            - type: 'null'
        input_audio:
          anyOf:
            - $ref: '#/components/schemas/InputAudio'
            - type: 'null'
        fps:
          anyOf:
            - type: string
            - type: 'null'
          title: Fps
        cache_control:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Cache Control
      type: object
      required:
        - type
      title: ContentPart
    ToolCall:
      properties:
        id:
          type: string
          title: Id
        type:
          type: string
          const: function
          title: Type
          default: function
        function:
          additionalProperties: true
          type: object
          title: Function
        thought_signature:
          anyOf:
            - type: string
            - type: 'null'
          title: Thought Signature
      type: object
      required:
        - id
        - function
      title: ToolCall
    ToolFunction:
      properties:
        name:
          type: string
          title: Name
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
        parameters:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Parameters
      type: object
      required:
        - name
      title: ToolFunction
    ImageUrl:
      properties:
        url:
          type: string
          title: Url
        detail:
          type: string
          enum:
            - auto
            - low
            - high
          title: Detail
          default: auto
      type: object
      required:
        - url
      title: ImageUrl
    VideoUrl:
      properties:
        url:
          type: string
          title: Url
      type: object
      required:
        - url
      title: VideoUrl
    InputAudio:
      properties:
        data:
          anyOf:
            - type: string
            - type: 'null'
          title: Data
        uri:
          anyOf:
            - type: string
            - type: 'null'
          title: Uri
        url:
          anyOf:
            - type: string
            - type: 'null'
          title: Url
        format:
          type: string
          enum:
            - wav
            - mp3
            - aiff
            - aac
            - ogg
            - flac
            - m4a
            - pcm16
            - pcm24
          title: Format
      type: object
      required:
        - format
      title: InputAudio
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: >-
        Enter your MeshAPI key (`rsk_...`) — sent as `Authorization: Bearer
        <key>`.

````