# Speech

Turn text into spoken audio with a supported voice. The speech endpoint uses the OpenAI request shape and returns an audio file.

`POST /v1/audio/speech`

`GET /v1/audio/speech/jobs/{job_id}`

`GET /v1/audio/speech/jobs/{job_id}/artifacts/{index}`

## Generate speech

POST /v1/audio/speech accepts model, input and voice. response_format defaults to mp3. Use a speech model with options.speech set to true and choose a voice and format from its catalog options.

- input is the exact text to speak, limited to 2,000 characters. Duration, lyrics, instructions, speed and streaming are not supported by this endpoint.
- Supported formats are MP3, WAV, FLAC, Opus/Ogg and AAC, depending on the model. Voice IDs are case-sensitive. Model and voice are required.
- Use the OpenAI SDK’s audio.speech.create() with the uRouter base URL, or the cURL example below. Set max_retries to 0. An Idempotency-Key is optional but recommended for recovery.

### Speech

```text
curl --fail-with-body "https://urouter.net/gateway/v1/audio/speech" \
  -H "Authorization: Bearer $UROUTER_API_KEY" \
  -H 'Content-Type: application/json' \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
  "model": "YOUR_SPEECH_MODEL_ID",
  "input": "Hello from uRouter.",
  "voice": "YOUR_SUPPORTED_VOICE",
  "response_format": "mp3"
}' --output speech.mp3
```

### Speech with the OpenAI Python SDK

```text
import os
from pathlib import Path
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["UROUTER_API_KEY"],
    base_url="https://urouter.net/gateway/v1",
    max_retries=0,
    timeout=180,
)
audio = client.audio.speech.create(
    model="YOUR_SPEECH_MODEL_ID",
    input="Hello from uRouter.",
    voice="YOUR_SUPPORTED_VOICE",
    response_format="mp3",
)
Path("speech.mp3").write_bytes(audio.content)
```

## Save or recover the audio

A successful request returns HTTP 200 and audio bytes. Save the response as a file. The Location and X-uRouter-Job-ID headers identify the original operation.

- If the connection drops or settlement is still pending, resolve Location against the original speech request URL and retrieve it with the same account’s API key. GET /v1/audio/speech/jobs/{job_id} reports execution, financial and delivery status.
- When result_state is ready, download results[].download_path before result_expires_at. Prefix paths beginning with /v1 with /gateway when using this site’s origin.
- Reusing the original Idempotency-Key recovers the same operation. Never send a new key to retrieve uncertain work. Existing clients can still use the legacy speech job form at /v1/music/generations.
