> ## 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 speech (OpenAI-compatible)

> OpenAI-compatible speech synthesis. Format mappings: mp3 = 44.1 kHz at 128 kbps, wav = pcm_s16le 24 kHz, pcm = raw pcm_s16le 24 kHz. For full control of container, sample rate, and encoding, use POST /tts/bytes.



## OpenAPI

````yaml /api-reference/openapi.json post /v1/audio/speech
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/audio/speech:
    post:
      tags:
        - Text to Speech
      summary: Create speech (OpenAI-compatible)
      description: >-
        OpenAI-compatible speech synthesis. Format mappings: mp3 = 44.1 kHz at
        128 kbps, wav = pcm_s16le 24 kHz, pcm = raw pcm_s16le 24 kHz. For full
        control of container, sample rate, and encoding, use POST /tts/bytes.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - model
                - input
                - voice
              properties:
                model:
                  type: string
                  description: TTS model id, e.g. omnivoice.
                input:
                  type: string
                  minLength: 1
                  maxLength: 5000
                  description: Text to synthesize, 1-5000 characters. Billed per character.
                voice:
                  type: string
                  description: Voice id from GET /voices.
                response_format:
                  type: string
                  enum:
                    - mp3
                    - wav
                    - pcm
                  default: mp3
                  description: opus, aac, and flac return 400.
                speed:
                  type: number
                  minimum: 0.6
                  maximum: 1.5
                  description: Playback speed. Streaming requires speed 1.
                stream:
                  type: boolean
                  default: false
                  description: >-
                    Relay raw WAV/PCM bytes progressively as they are generated.
                    Not supported with mp3.
      responses:
        '200':
          description: Audio bytes.
          headers:
            x-hopper-request-cost-usd:
              $ref: '#/components/headers/XHopperRequestCostUsd'
            x-hopper-credits-remaining-usd:
              $ref: '#/components/headers/XHopperCreditsRemainingUsd'
          content:
            audio/mpeg:
              schema:
                type: string
                format: binary
            audio/wav:
              schema:
                type: string
                format: binary
            application/octet-stream:
              schema:
                type: string
                format: binary
        '400':
          description: >-
            Unsupported response_format, mp3 with stream, or speed other than 1
            with stream. Codes: invalid_output_format,
            invalid_generation_config.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  message: Streaming TTS does not support mp3; use wav or pcm/raw.
                  type: invalid_request_error
                  code: invalid_output_format
                  param: null
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/PaymentRequired'
        '404':
          description: 'Unknown model or voice. Codes: model_not_found, voice_not_found.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          $ref: '#/components/responses/VoiceProfileMissing'
        '429':
          $ref: '#/components/responses/RateLimited'
        '502':
          description: 'Upstream failed. Codes: upstream_unavailable, upstream_error.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '503':
          description: 'No healthy upstream for this model. Code: model_offline.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '504':
          description: 'Upstream timed out (300 s). Code: upstream_timeout.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
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
  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'
  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
    VoiceProfileMissing:
      description: >-
        The voice has no ready profile for this model. Prepare one with POST
        /voices/:id/profiles. Code: voice_profile_missing.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              message: Voice 'X' is not prepared for model 'Y'.
              type: invalid_request_error
              code: voice_profile_missing
              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
  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=.

````