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

# Create Speech

> Generates audio from the input text.

Returns the audio file content, or a stream of audio events.



## OpenAPI

````yaml /openapi.json post /v1/audio/speech
openapi: 3.1.0
info:
  title: AIHubMix Gateway API
  description: |
    Unified multi-protocol gateway. Exposes three native shapes side-by-side:
      - OpenAI (`/v1/chat/completions`, `/v1/responses`, ...)
      - Anthropic (`/v1/messages`)
      - Gemini (`/v1beta/models/{model}:generateContent`)
    Each vendor's native SDK connects directly. Gateway-only fields are
    marked with `x-source.authority: gateway`.
  contact:
    name: AIHubMix Team
  version: 2.1.1
  x-upstream:
    vendorSpecs:
      packageVersion: 0.1.1
      installedFrom: npm
    sources:
      openai/official:
        version: '2026-05-31'
        hash: >-
          sha256:a203971a0bc0cd3b903b9488e3ac40eaa161a274dfaf172c1da73eee029147a8
      anthropic/official:
        version: '2026-05-31'
        hash: >-
          sha256:f9d488f9290d78a081bed62fa0c040476b5d009f3db92c06c8e279e69df73fc9
    layers:
      - role: L0-base
        source: avs://openai/official
        protocol: openai
        authority: official
      - role: L0-base
        source: avs://anthropic/official
        protocol: anthropic
        authority: official
      - role: gateway-other
        source: gateway/anthropic-mappings.yml
        protocol: all
        authority: gateway
      - role: horizontal-auth
        source: gateway/auth.yml
        protocol: all
        authority: gateway
      - role: horizontal-errors
        source: gateway/errors.yml
        protocol: all
        authority: gateway
      - role: L3-gateway
        source: gateway/openai-gateway.yml
        protocol: openai
        authority: gateway
      - role: gateway-other
        source: gateway/openai-image-mappings.yml
        protocol: all
        authority: gateway
      - role: gateway-other
        source: gateway/openai-mappings.yml
        protocol: all
        authority: gateway
      - role: L2-passthrough
        source: gateway/openai-passthrough.yml
        protocol: openai
        authority: gateway
servers:
  - url: https://aihubmix.com
    description: Production
  - url: https://api.inferera.com
    description: Backup (use when the primary domain is unreachable)
security:
  - gatewayBearer: []
tags:
  - name: OpenAI Compatible
    description: >-
      OpenAI-compatible endpoints (chat, completions, embeddings, images, audio,
      videos, moderations).
  - name: Anthropic Compatible
    description: Anthropic-native endpoints (messages with Anthropic protocol).
  - name: Google Vertex AI Compatible
    description: Google Gemini / Vertex AI endpoints.
paths:
  /v1/audio/speech:
    post:
      tags:
        - OpenAI Compatible
      summary: Create Speech
      description: |-
        Generates audio from the input text.

        Returns the audio file content, or a stream of audio events.
      operationId: createSpeech
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateSpeechRequest'
      responses:
        '200':
          description: OK
          headers:
            Transfer-Encoding:
              schema:
                type: string
              description: chunked
          content:
            application/octet-stream:
              schema:
                type: string
                format: binary
            text/event-stream:
              schema:
                $ref: '#/components/schemas/CreateSpeechResponseStreamEvent'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GatewayError'
        '401':
          description: Authentication failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GatewayError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GatewayError'
        '404':
          description: Not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GatewayError'
        '429':
          description: Rate limited
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GatewayError'
        5XX:
          description: Server / upstream error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GatewayError'
components:
  schemas:
    CreateSpeechRequest:
      type: object
      additionalProperties: false
      properties:
        model:
          description: >
            One of the available [TTS
            models](https://developers.openai.com/api/docs/models#tts): `tts-1`,
            `tts-1-hd`, `gpt-4o-mini-tts`, or `gpt-4o-mini-tts-2025-12-15`.
          anyOf:
            - type: string
            - type: string
              enum:
                - tts-1
                - tts-1-hd
                - gpt-4o-mini-tts
                - gpt-4o-mini-tts-2025-12-15
        input:
          type: string
          description: >-
            The text to generate audio for. The maximum length is 4096
            characters.
          maxLength: 4096
        instructions:
          type: string
          description: >-
            Control the voice of your generated audio with additional
            instructions. Does not work with `tts-1` or `tts-1-hd`.
          maxLength: 4096
        voice:
          $ref: '#/components/schemas/VoiceIdsOrCustomVoice'
          description: >-
            The voice to use when generating the audio. Supported built-in
            voices are `alloy`, `ash`, `ballad`, `coral`, `echo`, `fable`,
            `onyx`, `nova`, `sage`, `shimmer`, `verse`, `marin`, and `cedar`.
            You may also provide a custom voice object with an `id`, for example
            `{ "id": "voice_1234" }`. Previews of the voices are available in
            the [Text to speech
            guide](https://developers.openai.com/api/docs/guides/text-to-speech#voice-options).
        response_format:
          description: >-
            The format to audio in. Supported formats are `mp3`, `opus`, `aac`,
            `flac`, `wav`, and `pcm`.
          default: mp3
          type: string
          enum:
            - mp3
            - opus
            - aac
            - flac
            - wav
            - pcm
        speed:
          description: >-
            The speed of the generated audio. Select a value from `0.25` to
            `4.0`. `1.0` is the default.
          type: number
          default: 1
          minimum: 0.25
          maximum: 4
        stream_format:
          description: >-
            The format to stream the audio in. Supported formats are `sse` and
            `audio`. `sse` is not supported for `tts-1` or `tts-1-hd`.
          type: string
          default: audio
          enum:
            - sse
            - audio
      required:
        - model
        - input
        - voice
      x-source:
        from: avs://openai/official
        authority: official
    CreateSpeechResponseStreamEvent:
      anyOf:
        - $ref: '#/components/schemas/SpeechAudioDeltaEvent'
        - $ref: '#/components/schemas/SpeechAudioDoneEvent'
      discriminator:
        propertyName: type
      x-source:
        from: avs://openai/official
        authority: official
    GatewayError:
      type: object
      description: |
        OpenAI-compatible error envelope. Top-level `error` object carrying
        `message` / `type` / `param` / `code`. `request_id` lives in the
        `X-Request-Id` response header, not in the body. The legacy `upstream`
        field is no longer emitted.
      x-source:
        from: gateway
        authority: gateway
      required:
        - error
      properties:
        error:
          type: object
          required:
            - message
          properties:
            message:
              type: string
              description: Human-readable error message.
            type:
              type: string
              nullable: true
              description: >
                Error category. OpenAI-compatible values include

                invalid_request_error / authentication_error / permission_error
                /

                not_found_error / rate_limit_error, etc. The upstream value is

                passed through verbatim; the enum is not fixed.
            param:
              type: string
              nullable: true
              description: Name of the offending field, when applicable.
            code:
              nullable: true
              description: |
                Sub-error code. May be a string or integer (the gateway treats
                `code` as an arbitrary type).
    VoiceIdsOrCustomVoice:
      title: Voice
      description: |
        A built-in voice name or a custom voice reference.
      anyOf:
        - $ref: '#/components/schemas/VoiceIdsShared'
        - type: object
          description: Custom voice reference.
          additionalProperties: false
          required:
            - id
          properties:
            id:
              type: string
              description: The custom voice ID, e.g. `voice_1234`.
              example: voice_1234
      x-source:
        from: avs://openai/official
        authority: official
    SpeechAudioDeltaEvent:
      type: object
      description: Emitted for each chunk of audio data generated during speech synthesis.
      properties:
        type:
          type: string
          description: |
            The type of the event. Always `speech.audio.delta`.
          enum:
            - speech.audio.delta
        audio:
          type: string
          description: |
            A chunk of Base64-encoded audio data.
      required:
        - type
        - audio
      x-source:
        from: avs://openai/official
        authority: official
    SpeechAudioDoneEvent:
      type: object
      description: >-
        Emitted when the speech synthesis is complete and all audio has been
        streamed.
      properties:
        type:
          type: string
          description: |
            The type of the event. Always `speech.audio.done`.
          enum:
            - speech.audio.done
        usage:
          type: object
          description: |
            Token usage statistics for the request.
          properties:
            input_tokens:
              type: integer
              description: Number of input tokens in the prompt.
            output_tokens:
              type: integer
              description: Number of output tokens generated.
            total_tokens:
              type: integer
              description: Total number of tokens used (input + output).
          required:
            - input_tokens
            - output_tokens
            - total_tokens
      required:
        - type
        - usage
      x-source:
        from: avs://openai/official
        authority: official
    VoiceIdsShared:
      example: ash
      anyOf:
        - type: string
        - type: string
          enum:
            - alloy
            - ash
            - ballad
            - coral
            - echo
            - sage
            - shimmer
            - verse
            - marin
            - cedar
      x-source:
        from: avs://openai/official
        authority: official
  securitySchemes:
    gatewayBearer:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: |
        Gateway-issued API key, formatted as `sk-gateway-xxxxxxxx`.
        Used by OpenAI-shaped endpoints (/v1/chat/completions, etc.).
      x-source:
        from: gateway
        authority: gateway

````