---
title: "Create speech"
description: "Turns text into speech. Follows OpenAI's Audio Speech API, and any provider that serves speech can answer it. The response is the audio's bytes, or with `stream_format: \"sse\"` a stream of `speech.audio.*` events. Priced per minute of audio made. Options a provider does not take are refused with `400` before the call: MiniMax refuses `instructions`, Gemini and Mistral refuse `speed`, Mistral refuses `instructions`, and MiniMax, Gemini (for `instructions`) and Qwen need a `voice`."
---

<a id="playground-button:docs/apis/gateway/create-speech"></a>

**POST** `https://gateway.respan.ai/v1/audio/speech`

Turns text into speech. Follows OpenAI's Audio Speech API, and any provider that serves speech can answer it. The response is the audio's bytes, or with `stream_format: "sse"` a stream of `speech.audio.*` events. Priced per minute of audio made. Options a provider does not take are refused with `400` before the call: MiniMax refuses `instructions`, Gemini and Mistral refuse `speed`, Mistral refuses `instructions`, and MiniMax, Gemini (for `instructions`) and Qwen need a `voice`.

## Servers

`https://gateway.respan.ai`: Respan gateway

## Authentication

### RespanApiKey

Use your Respan API key for Respan API authentication. Enter only the Respan API key value; clients send Authorization: Bearer &lt;RESPAN_API_KEY&gt;. For /api/responses, provider credentials such as Perplexity, OpenAI, or Azure OpenAI go in Settings -&gt; Providers or respan_params.credential_override in the request body, not in this authentication field.

HTTP scheme: `bearer`; format: `Respan API key`.


```http
Authorization: Bearer $RESPAN_API_KEY
```


## Request body

A request body is required.

### application/json


| Field | Type | Requirement | Description and constraints |
| --- | --- | --- | --- |
| `$` | `object` | Required body | Additional properties are allowed |
| `model` | `string` | Required in parent | The speech model, such as `tts-1`. Prefix it with its provider to keep it on one. |
| `input` | `string` | Required in parent | The text to speak. |
| `voice` | `string` | Required in parent | A voice name of the model's provider. A provider refuses another's names. |
| `response_format` | `string` | Optional | The audio format.<br />Allowed: `"mp3"`, `"wav"`, `"pcm"`<br />Default: `mp3` |
| `instructions` | `string` | Optional | The style to speak the text in, where the provider takes it. |
| `speed` | `number` | Optional | Speaking rate, where the provider takes it. 1 is the voice's own pace. |
| `sample_rate` | `integer` | Optional | Samples per second, such as `24000`, where the provider takes it. |
| `stream_format` | `string` | Optional | `sse` to get the audio as a stream of events, where the provider takes it.<br />Allowed: `"sse"` |
| `provider` | `object` | Optional | Settings only one provider takes, as `{"options": {"<provider id>": {...}}}`. A call carries the settings of the provider it goes to and ignores the rest. A key the provider does not list, or one that another field already sets, is refused with `400` naming `provider.options.<id>.<key>`. In a form, send it as JSON text.<br />Additional properties are allowed |


<details class="api-schema-source">
<summary>OpenAPI request schema</summary>


```json
{
  "type": "object",
  "required": [
    "model",
    "input",
    "voice"
  ],
  "properties": {
    "model": {
      "type": "string",
      "description": "The speech model, such as `tts-1`. Prefix it with its provider to keep it on one."
    },
    "input": {
      "type": "string",
      "description": "The text to speak."
    },
    "voice": {
      "type": "string",
      "description": "A voice name of the model's provider. A provider refuses another's names."
    },
    "response_format": {
      "type": "string",
      "description": "The audio format.",
      "enum": [
        "mp3",
        "wav",
        "pcm"
      ],
      "default": "mp3"
    },
    "instructions": {
      "type": "string",
      "description": "The style to speak the text in, where the provider takes it."
    },
    "speed": {
      "type": "number",
      "description": "Speaking rate, where the provider takes it. 1 is the voice's own pace."
    },
    "sample_rate": {
      "type": "integer",
      "description": "Samples per second, such as `24000`, where the provider takes it."
    },
    "stream_format": {
      "type": "string",
      "description": "`sse` to get the audio as a stream of events, where the provider takes it.",
      "enum": [
        "sse"
      ]
    },
    "provider": {
      "type": "object",
      "description": "Settings only one provider takes, as `{\"options\": {\"<provider id>\": {...}}}`. A call carries the settings of the provider it goes to and ignores the rest. A key the provider does not list, or one that another field already sets, is refused with `400` naming `provider.options.<id>.<key>`. In a form, send it as JSON text.",
      "additionalProperties": true
    }
  },
  "additionalProperties": true
}
```

</details>

##### OpenAI voice


```json
{
  "model": "tts-1",
  "voice": "alloy",
  "input": "Your order has shipped."
}
```


##### MiniMax with provider settings


```json
{
  "model": "speech-2.8-hd",
  "voice": "English_expressive_narrator",
  "input": "Your order has shipped.",
  "provider": {
    "options": {
      "minimax": {
        "pitch": 3,
        "language_boost": "English"
      }
    }
  }
}
```


## Responses

### 200

The audio's bytes, or a `text/event-stream` of `speech.audio.*` events with `stream_format: "sse"`.

#### Response headers


| Parameter | Type | Required | Description and constraints |
| --- | --- | --- | --- |
| `X-Respan-Log-Id` | `string` | Optional | ID of the Respan request log for this call. |


#### audio/mpeg


| Field | Type | Requirement | Description and constraints |
| --- | --- | --- | --- |
| `$` | `string` | Body | Format: `binary` |


<details class="api-schema-source">
<summary>OpenAPI response schema</summary>


```json
{
  "type": "string",
  "format": "binary"
}
```

</details>

#### text/event-stream


| Field | Type | Requirement | Description and constraints |
| --- | --- | --- | --- |
| `$` | `string` | Body | - |


<details class="api-schema-source">
<summary>OpenAPI response schema</summary>


```json
{
  "type": "string"
}
```

</details>

### 400

The request is malformed, or a field is one the provider cannot take. Fields refused before the call say which one.

#### application/json


| Field | Type | Requirement | Description and constraints |
| --- | --- | --- | --- |
| `$` | `object` | Body | Additional properties are allowed |


<details class="api-schema-source">
<summary>OpenAPI response schema</summary>


```json
{
  "type": "object",
  "additionalProperties": true
}
```

</details>

### 403

The API key is missing, invalid or expired.

#### application/json


| Field | Type | Requirement | Description and constraints |
| --- | --- | --- | --- |
| `$` | `object` | Body | - |
| `detail` | `string` | Required in parent | - |


<details class="api-schema-source">
<summary>OpenAPI response schema</summary>


```json
{
  "type": "object",
  "required": [
    "detail"
  ],
  "properties": {
    "detail": {
      "type": "string"
    }
  }
}
```

</details>

##### Example


```json
{
  "detail": "Your API key is invalid or expired, please check your API key in the platform settings."
}
```


### 429

A rate limit or usage limit was reached. Retry with exponential backoff.

#### application/json


| Field | Type | Requirement | Description and constraints |
| --- | --- | --- | --- |
| `$` | `object` | Body | Additional properties are allowed |


<details class="api-schema-source">
<summary>OpenAPI response schema</summary>


```json
{
  "type": "object",
  "additionalProperties": true
}
```

</details>

## OpenAPI source

The operation and referenced components below retain the complete OpenAPI definitions, including constraints and examples.

<!-- openapi-operation:start -->
<details class="api-schema-source">
<summary>OpenAPI operation</summary>


```json
{
  "summary": "Create speech",
  "operationId": "createSpeech",
  "tags": [
    "Gateway"
  ],
  "servers": [
    {
      "url": "https://gateway.respan.ai",
      "description": "Respan gateway"
    }
  ],
  "description": "Turns text into speech. Follows OpenAI's Audio Speech API, and any provider that serves speech can answer it. The response is the audio's bytes, or with `stream_format: \"sse\"` a stream of `speech.audio.*` events. Priced per minute of audio made. Options a provider does not take are refused with `400` before the call: MiniMax refuses `instructions`, Gemini and Mistral refuse `speed`, Mistral refuses `instructions`, and MiniMax, Gemini (for `instructions`) and Qwen need a `voice`.",
  "security": [
    {
      "RespanApiKey": []
    }
  ],
  "requestBody": {
    "required": true,
    "content": {
      "application/json": {
        "schema": {
          "type": "object",
          "required": [
            "model",
            "input",
            "voice"
          ],
          "properties": {
            "model": {
              "type": "string",
              "description": "The speech model, such as `tts-1`. Prefix it with its provider to keep it on one."
            },
            "input": {
              "type": "string",
              "description": "The text to speak."
            },
            "voice": {
              "type": "string",
              "description": "A voice name of the model's provider. A provider refuses another's names."
            },
            "response_format": {
              "type": "string",
              "description": "The audio format.",
              "enum": [
                "mp3",
                "wav",
                "pcm"
              ],
              "default": "mp3"
            },
            "instructions": {
              "type": "string",
              "description": "The style to speak the text in, where the provider takes it."
            },
            "speed": {
              "type": "number",
              "description": "Speaking rate, where the provider takes it. 1 is the voice's own pace."
            },
            "sample_rate": {
              "type": "integer",
              "description": "Samples per second, such as `24000`, where the provider takes it."
            },
            "stream_format": {
              "type": "string",
              "description": "`sse` to get the audio as a stream of events, where the provider takes it.",
              "enum": [
                "sse"
              ]
            },
            "provider": {
              "type": "object",
              "description": "Settings only one provider takes, as `{\"options\": {\"<provider id>\": {...}}}`. A call carries the settings of the provider it goes to and ignores the rest. A key the provider does not list, or one that another field already sets, is refused with `400` naming `provider.options.<id>.<key>`. In a form, send it as JSON text.",
              "additionalProperties": true
            }
          },
          "additionalProperties": true
        },
        "examples": {
          "openai": {
            "summary": "OpenAI voice",
            "value": {
              "model": "tts-1",
              "voice": "alloy",
              "input": "Your order has shipped."
            }
          },
          "minimax": {
            "summary": "MiniMax with provider settings",
            "value": {
              "model": "speech-2.8-hd",
              "voice": "English_expressive_narrator",
              "input": "Your order has shipped.",
              "provider": {
                "options": {
                  "minimax": {
                    "pitch": 3,
                    "language_boost": "English"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "responses": {
    "200": {
      "description": "The audio's bytes, or a `text/event-stream` of `speech.audio.*` events with `stream_format: \"sse\"`.",
      "headers": {
        "X-Respan-Log-Id": {
          "description": "ID of the Respan request log for this call.",
          "schema": {
            "type": "string"
          }
        }
      },
      "content": {
        "audio/mpeg": {
          "schema": {
            "type": "string",
            "format": "binary"
          }
        },
        "text/event-stream": {
          "schema": {
            "type": "string"
          }
        }
      }
    },
    "400": {
      "description": "The request is malformed, or a field is one the provider cannot take. Fields refused before the call say which one.",
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "additionalProperties": true
          }
        }
      }
    },
    "403": {
      "$ref": "#/components/responses/InvalidApiKey"
    },
    "429": {
      "description": "A rate limit or usage limit was reached. Retry with exponential backoff.",
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "additionalProperties": true
          }
        }
      }
    }
  }
}
```

</details>
<!-- openapi-operation:end -->

<!-- openapi-path-item:start -->
<details class="api-schema-source">
<summary>OpenAPI path metadata</summary>


```json
{}
```

</details>
<!-- openapi-path-item:end -->

<!-- openapi-components:start -->
<details class="api-schema-source">
<summary>Referenced OpenAPI components</summary>


```json
{
  "responses": {
    "InvalidApiKey": {
      "description": "The API key is missing, invalid or expired.",
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "required": [
              "detail"
            ],
            "properties": {
              "detail": {
                "type": "string"
              }
            }
          },
          "example": {
            "detail": "Your API key is invalid or expired, please check your API key in the platform settings."
          }
        }
      }
    }
  },
  "securitySchemes": {
    "RespanApiKey": {
      "type": "http",
      "scheme": "bearer",
      "bearerFormat": "Respan API key",
      "description": "Use your Respan API key for Respan API authentication. Enter only the Respan API key value; clients send Authorization: Bearer <RESPAN_API_KEY>. For /api/responses, provider credentials such as Perplexity, OpenAI, or Azure OpenAI go in Settings -> Providers or respan_params.credential_override in the request body, not in this authentication field.",
      "x-fern-bearer": {
        "name": "respanApiKey",
        "env": "RESPAN_API_KEY"
      }
    }
  }
}
```

</details>
<!-- openapi-components:end -->
