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

# Create chat completion

> OpenAI-compatible chat completions. The body is forwarded to the inference engine unchanged, so any OpenAI chat completions parameter is accepted; the engine validates it. Request body cap: 10 MB.



## OpenAPI

````yaml /api-reference/openapi.json post /v1/chat/completions
openapi: 3.1.0
info:
  title: Hopper API
  version: 1.0.0
  description: >-
    Inference for voice agents: LLM, text to speech, and speech to text at
    api.withhopper.com. OpenAI-compatible routes are served under /v1; native
    routes are served at the root. All errors use the OpenAI envelope.
servers:
  - url: https://api.withhopper.com
security:
  - bearerAuth: []
tags:
  - name: LLM
    description: OpenAI-compatible chat completions and model listing.
  - name: Text to Speech
    description: >-
      Speech synthesis: native /tts routes and the OpenAI-compatible
      /v1/audio/speech.
  - name: Speech to Text
    description: Batch transcription. Streaming runs over WS /stt/websocket.
  - name: Voices
    description: Voice library, cloning, profiles, and localization.
  - name: Pronunciation
    description: Pronunciation dictionaries applied at synthesis time.
  - name: Jobs
    description: Status of async voice jobs.
  - name: Health
    description: Unauthenticated liveness check.
paths:
  /v1/chat/completions:
    post:
      tags:
        - LLM
      summary: Create chat completion
      description: >-
        OpenAI-compatible chat completions. The body is forwarded to the
        inference engine unchanged, so any OpenAI chat completions parameter is
        accepted; the engine validates it. Request body cap: 10 MB.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - model
                - messages
              additionalProperties: true
              description: >-
                Passed through to the inference engine. Fields below are the
                common subset; any other OpenAI chat completions parameter is
                also accepted.
              properties:
                model:
                  type: string
                  description: Model id, e.g. gemma-4-31b.
                messages:
                  type: array
                  description: OpenAI chat messages.
                  items:
                    type: object
                stream:
                  type: boolean
                  default: false
                  description: Stream tokens as SSE chunks.
                temperature:
                  type: number
                  description: Sampling temperature; passed through.
                max_tokens:
                  type: integer
                  description: Maximum output tokens; passed through.
                tools:
                  type: array
                  description: OpenAI tool definitions; passed through.
                  items:
                    type: object
                stream_options:
                  type: object
                  description: >-
                    Set include_usage true to receive a final usage chunk. The
                    gateway meters usage either way.
                  properties:
                    include_usage:
                      type: boolean
      responses:
        '200':
          description: >-
            Non-streaming: an OpenAI chat completion object with both spend
            headers. Streaming: text/event-stream of OpenAI chunks, with only
            x-hopper-credits-remaining-usd (the pre-request balance; cost is
            unknown until the stream ends).
          headers:
            x-hopper-request-cost-usd:
              $ref: '#/components/headers/XHopperRequestCostUsd'
            x-hopper-credits-remaining-usd:
              $ref: '#/components/headers/XHopperCreditsRemainingUsd'
          content:
            application/json:
              schema:
                type: object
                description: >-
                  OpenAI chat completion object, forwarded from the inference
                  engine.
            text/event-stream:
              schema:
                type: string
                description: OpenAI-compatible SSE chunks.
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/PaymentRequired'
        '413':
          description: 'Request body over 10 MB. Code: body_too_large.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          $ref: '#/components/responses/RateLimited'
        '502':
          description: >-
            Inference engine unreachable or timed out (300 s). Code:
            upstream_unavailable.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '503':
          $ref: '#/components/responses/VerifyUnavailable'
components:
  headers:
    XHopperRequestCostUsd:
      description: >-
        Cost of this request, 6-decimal USD string (e.g. 0.000123). Absent on
        LLM streaming responses; the cost is unknown until the stream ends.
      schema:
        type: string
    XHopperCreditsRemainingUsd:
      description: >-
        Credit balance in USD, 6-decimal string. On LLM streaming responses this
        is the pre-request balance.
      schema:
        type: string
  responses:
    Unauthorized:
      description: >-
        Missing, malformed, or revoked API key. Codes: invalid_api_key,
        api_key_disabled.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: >-
                Incorrect API key provided. Check your key at
                https://withhopper.com/dashboard.
              type: invalid_request_error
              code: invalid_api_key
              param: null
    PaymentRequired:
      description: Credit balance is zero.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: You have run out of credits. Contact us to add more.
              type: insufficient_quota
              code: insufficient_quota
              param: null
    RateLimited:
      description: >-
        Over 600 requests per minute on this key. Retry after the number of
        seconds in Retry-After.
      headers:
        Retry-After:
          description: Seconds to wait before retrying.
          schema:
            type: integer
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: >-
                Rate limit reached: 600 requests per minute per key. Retry after
                21s.
              type: rate_limit_error
              code: rate_limit_exceeded
              param: null
    VerifyUnavailable:
      description: Key verification is temporarily unavailable.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: Key verification is temporarily unavailable. Retry shortly.
              type: api_error
              code: verify_unavailable
              param: null
  schemas:
    Error:
      type: object
      description: OpenAI error envelope, used by every error response.
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            type:
              type: string
            code:
              type: string
            param:
              type:
                - string
                - 'null'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        API key in the Authorization header: Bearer sk_hopper_... Keys are
        minted in the dashboard at withhopper.com/console/keys and shown once at
        creation. WebSocket connections also accept ?api_key=.

````