Skip to content
Docs

AI Gateway Speech Quickstart: Transcription and TTS

Generate speech from text through AI Gateway, save the audio, and transcribe it back to text.

Paste this prompt into a coding agent with terminal access:

Agent Prompt

Add a text-to-speech and speech-to-text round trip through AI Gateway in the current environment. Use the AI Gateway skill for this task. If it is unavailable, run npx skills add vercel/vercel-plugin --skill ai-gateway, then find and read its SKILL.md before continuing. Reuse the environment's language, framework, package manager, and AI client when possible, choose AI Gateway SDKs or APIs that support speech generation and transcription, and add only required dependencies. Read AI_GATEWAY_API_KEY from the environment. If it is missing, run npx vercel@latest whoami and pause for login if needed. Determine the team, then run npx vercel@latest --scope <team-slug> ai-gateway api-keys create --name <descriptive-name>. Capture stdout directly into AI_GATEWAY_API_KEY for the request or existing ignored secret storage, and never expose the value. Use openai/tts-1 and openai/whisper-1, save the audio, print the transcript, run the result, and report the output.

Use Node.js 22.18 or later and a team with available AI Gateway Credits. Export AI_GATEWAY_API_KEY in your current shell. If you need a key, open the Create API Key dialog.

Terminal
export AI_GATEWAY_API_KEY="your_ai_gateway_api_key"

Install the AI SDK:

Terminal
pnpm add ai@latest

Create index.mts:

index.mts
import {
  experimental_generateSpeech as generateSpeech,
  experimental_transcribe as transcribe,
} from 'ai';
import { writeFile } from 'node:fs/promises';
 
const text = 'Thanks for trying AI Gateway.';
const speech = await generateSpeech({
  model: 'openai/tts-1',
  text,
  voice: 'alloy',
  outputFormat: 'mp3',
});
 
await writeFile('speech.mp3', speech.audio.uint8Array);
 
const transcript = await transcribe({
  model: 'openai/whisper-1',
  audio: speech.audio.uint8Array,
});
 
console.log(transcript.text);

Run the script:

Terminal
node index.mts
Last updated September 8, 2026

Was this helpful?

supported.