> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://developers.meshapi.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://developers.meshapi.ai/_mcp/server.

# Create Speech

POST https://api.meshapi.ai/v1/audio/speech
Content-Type: application/json

Convert text to speech.

Provider is resolved automatically from the model name via the model_pricing
table — no hardcoded provider branching. Streaming is used when the provider
adapter supports it and `stream=true` (the default).

The `voice` field is required for ElevenLabs models. Sarvam models use
`speaker` instead.

Reference: https://developers.meshapi.ai/api-reference/mesh-api/audio/create-speech

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: openapi
  version: 1.0.0
paths:
  /v1/audio/speech:
    post:
      operationId: create-speech
      summary: Create Speech
      description: >-
        Convert text to speech.


        Provider is resolved automatically from the model name via the
        model_pricing

        table — no hardcoded provider branching. Streaming is used when the
        provider

        adapter supports it and `stream=true` (the default).


        The `voice` field is required for ElevenLabs models. Sarvam models use

        `speaker` instead.
      tags:
        - audio
      parameters:
        - name: Authorization
          in: header
          description: Bearer authentication
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                description: Any type
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SpeechRequest'
servers:
  - url: https://api.meshapi.ai
    description: Production Server
components:
  schemas:
    VoiceSettings:
      type: object
      properties:
        stability:
          type:
            - number
            - 'null'
          format: double
        similarity_boost:
          type:
            - number
            - 'null'
          format: double
        style:
          type:
            - number
            - 'null'
          format: double
        use_speaker_boost:
          type:
            - boolean
            - 'null'
        speed:
          type:
            - number
            - 'null'
          format: double
      title: VoiceSettings
    PronunciationDictionaryLocator:
      type: object
      properties:
        pronunciation_dictionary_id:
          type: string
        version_id:
          type: string
      required:
        - pronunciation_dictionary_id
        - version_id
      title: PronunciationDictionaryLocator
    SpeechRequest:
      type: object
      properties:
        model:
          type: string
          default: eleven_flash_v2_5
        input:
          type: string
        voice:
          type:
            - string
            - 'null'
        stream:
          type: boolean
          default: true
        response_format:
          type:
            - string
            - 'null'
        language_code:
          type:
            - string
            - 'null'
        voice_settings:
          oneOf:
            - $ref: '#/components/schemas/VoiceSettings'
            - type: 'null'
        pronunciation_dictionary_locators:
          type:
            - array
            - 'null'
          items:
            $ref: '#/components/schemas/PronunciationDictionaryLocator'
        seed:
          type:
            - integer
            - 'null'
        previous_text:
          type:
            - string
            - 'null'
        next_text:
          type:
            - string
            - 'null'
        previous_request_ids:
          type:
            - array
            - 'null'
          items:
            type: string
        next_request_ids:
          type:
            - array
            - 'null'
          items:
            type: string
        apply_text_normalization:
          type:
            - string
            - 'null'
        apply_language_text_normalization:
          type:
            - boolean
            - 'null'
        use_pvc_as_ivc:
          type:
            - boolean
            - 'null'
        enable_logging:
          type:
            - boolean
            - 'null'
        optimize_streaming_latency:
          type:
            - integer
            - 'null'
        speaker:
          type: string
          default: anushka
        target_language_code:
          type: string
          default: hi-IN
        pitch:
          type:
            - number
            - 'null'
          format: double
        pace:
          type:
            - number
            - 'null'
          format: double
        loudness:
          type:
            - number
            - 'null'
          format: double
        speech_sample_rate:
          type:
            - integer
            - 'null'
        enable_preprocessing:
          type:
            - boolean
            - 'null'
      required:
        - input
      title: SpeechRequest
    ValidationErrorLocItems:
      oneOf:
        - type: string
        - type: integer
      title: ValidationErrorLocItems
    ValidationErrorCtx:
      type: object
      properties: {}
      title: ValidationErrorCtx
    ValidationError:
      type: object
      properties:
        loc:
          type: array
          items:
            $ref: '#/components/schemas/ValidationErrorLocItems'
        msg:
          type: string
        type:
          type: string
        input:
          description: Any type
        ctx:
          $ref: '#/components/schemas/ValidationErrorCtx'
      required:
        - loc
        - msg
        - type
      title: ValidationError
    HTTPValidationError:
      type: object
      properties:
        detail:
          type: array
          items:
            $ref: '#/components/schemas/ValidationError'
      title: HTTPValidationError
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

```

## Examples

### Example response



**Request**

```json
undefined
```

**Response**

```json
"binary audio bytes"
```

**SDK Code**

```python Example response
import requests

url = "https://api.meshapi.ai/v1/audio/speech"

headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, headers=headers)

print(response.json())
```

```javascript Example response
const url = 'https://api.meshapi.ai/v1/audio/speech';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: undefined
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Example response
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.meshapi.ai/v1/audio/speech"

	req, _ := http.NewRequest("POST", url, nil)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Example response
require 'uri'
require 'net/http'

url = URI("https://api.meshapi.ai/v1/audio/speech")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'

response = http.request(request)
puts response.read_body
```

```java Example response
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.meshapi.ai/v1/audio/speech")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .asString();
```

```php Example response
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.meshapi.ai/v1/audio/speech', [
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp Example response
using RestSharp;

var client = new RestClient("https://api.meshapi.ai/v1/audio/speech");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
IRestResponse response = client.Execute(request);
```

```swift Example response
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.meshapi.ai/v1/audio/speech")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Example request



**Request**

```json
{
  "input": "Welcome to MeshAPI.",
  "model": "sarvam/bulbul:v2",
  "voice": "meera",
  "stream": false,
  "response_format": "mp3_44100_128"
}
```

**Response**

```json
"binary audio bytes"
```

**SDK Code**

```python Example request
import requests

url = "https://api.meshapi.ai/v1/audio/speech"

payload = {
    "input": "Welcome to MeshAPI.",
    "model": "sarvam/bulbul:v2",
    "voice": "meera",
    "stream": False,
    "response_format": "mp3_44100_128"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Example request
const url = 'https://api.meshapi.ai/v1/audio/speech';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"input":"Welcome to MeshAPI.","model":"sarvam/bulbul:v2","voice":"meera","stream":false,"response_format":"mp3_44100_128"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Example request
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.meshapi.ai/v1/audio/speech"

	payload := strings.NewReader("{\n  \"input\": \"Welcome to MeshAPI.\",\n  \"model\": \"sarvam/bulbul:v2\",\n  \"voice\": \"meera\",\n  \"stream\": false,\n  \"response_format\": \"mp3_44100_128\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Example request
require 'uri'
require 'net/http'

url = URI("https://api.meshapi.ai/v1/audio/speech")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"input\": \"Welcome to MeshAPI.\",\n  \"model\": \"sarvam/bulbul:v2\",\n  \"voice\": \"meera\",\n  \"stream\": false,\n  \"response_format\": \"mp3_44100_128\"\n}"

response = http.request(request)
puts response.read_body
```

```java Example request
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.meshapi.ai/v1/audio/speech")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"input\": \"Welcome to MeshAPI.\",\n  \"model\": \"sarvam/bulbul:v2\",\n  \"voice\": \"meera\",\n  \"stream\": false,\n  \"response_format\": \"mp3_44100_128\"\n}")
  .asString();
```

```php Example request
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.meshapi.ai/v1/audio/speech', [
  'body' => '{
  "input": "Welcome to MeshAPI.",
  "model": "sarvam/bulbul:v2",
  "voice": "meera",
  "stream": false,
  "response_format": "mp3_44100_128"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp Example request
using RestSharp;

var client = new RestClient("https://api.meshapi.ai/v1/audio/speech");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"input\": \"Welcome to MeshAPI.\",\n  \"model\": \"sarvam/bulbul:v2\",\n  \"voice\": \"meera\",\n  \"stream\": false,\n  \"response_format\": \"mp3_44100_128\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Example request
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "input": "Welcome to MeshAPI.",
  "model": "sarvam/bulbul:v2",
  "voice": "meera",
  "stream": false,
  "response_format": "mp3_44100_128"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.meshapi.ai/v1/audio/speech")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```