POST /audio/speech — text-to-speech via the dedicated endpoint.
{:ok, mp3_binary} = OpenrouterSdk.Api.Speech.create(%{
model: "<some-tts-slug>",
input: "hello there",
voice: "alloy",
response_format: "mp3"
})
File.write!("hello.mp3", mp3_binary)the response is the raw audio bytes — we do NOT decode json on this endpoint.
caveat
openrouter's /audio/speech accepts a fixed allowlist of model
slugs that are NOT exposed via /models, so you can't discover
them through the catalog. for catalog-driven tts, prefer
OpenrouterSdk.speak/2 (in OpenrouterSdk.Audio) — it routes
through /chat/completions with audio output and works against
any model in OpenrouterSdk.Catalog.Models.tts_models/0.
Summary
Functions
@spec create( map(), keyword() ) :: {:ok, binary()} | {:error, OpenrouterSdk.Error.t()}
@spec create_stream( map(), keyword() ) :: {:ok, Enumerable.t() | reference() | term()} | {:error, OpenrouterSdk.Error.t()}
stream the audio response as a Stream of byte chunks. consumers
who want pid / fun delivery pass :into exactly like the chat
streaming api.