# POST /ai/generate-speech

**Resource:** [AI](./ai.md)  
**Scopes:** `ai:use`  
**Write operation:** yes

Convert text to speech audio using ElevenLabs. Uploads the audio to R2 and saves to company files. Returns an audio URL, duration, file size, and credits charged. Costs 50 credits per 100 characters (minimum 50 credits). Voice resolution order: workspace voices by name -> workspace default -> platform voices -> presets (jessica/rachel/adam/sam) -> raw ElevenLabs voice ID. Optionally returns timed transcript segments (sentences, phrases, or words) for animation timing (e.g. Remotion video sync).

## Parameters

| Name | In | Type | Required | Description |
|------|----|------|----------|-------------|
| `text` | body | string | yes | Text to convert to speech (2-5000 characters) |
| `voice` | body | string | no | Voice name, preset (jessica/rachel/adam/sam), or raw ElevenLabs voice ID. Default: jessica. |
| `model` | body | string | no | ElevenLabs model: eleven_multilingual_v2 (default), eleven_monolingual_v1, eleven_turbo_v2_5 |
| `stability` | body | number | no | Voice stability 0-1 (default 0.6). Higher = more consistent, lower = more expressive. |
| `similarity_boost` | body | number | no | Voice clarity/similarity 0-1 (default 0.75) |
| `style` | body | number | no | Speaking style intensity 0-1 (default 0.4) |
| `output_format` | body | string | no | Audio output format (default: mp3_44100_128) |
| `name` | body | string | no | Custom file name for the audio (auto-generated if omitted) |
| `transcript` | body | string | no | Request timed transcript segments alongside audio. Values: "none" (default, no transcript), "sentences" (sentence-level timestamps), "phrases" (comma/clause-level timestamps), "words" (word-level timestamps). When set (not "none"), response includes transcript array of {text, start, end, frame_start, frame_end} objects and transcript_mode. frame_start/frame_end are at 30fps for Remotion animation. |

---
Base URL: `https://api.trustpager.com/functions/v1/api/v1` — Auth: `Authorization: Bearer YOUR_API_KEY`