From 3f4276901bd6adea467536c460a0833f85976a58 Mon Sep 17 00:00:00 2001 From: speakeasybot Date: Fri, 4 Dec 2026 19:22:58 +0000 Subject: [PATCH] ## Python SDK Changes: * `open_router.tts.create_speech()`: `request.stream_format` **Added** * `open_router.tts.list_models()`: `response.data[].endpoints[].output_modalities[].supported_parameters.stream_format` **Added** * `open_router.tts.get_model()`: `response.endpoints[].output_modalities[].supported_parameters.stream_format` **Added** --- .speakeasy/gen.lock | 64 ++++++++++--------- .speakeasy/gen.yaml | 2 +- .speakeasy/out.openapi.yaml | 23 ++++++- .speakeasy/workflow.lock | 10 +-- RELEASES.md | 12 +++- docs/components/outputdelivery.mdx | 2 +- docs/components/speechoutputmodality.mdx | 10 +-- docs/components/speechrequest.mdx | 31 ++++----- docs/components/speechsupportedparameters.mdx | 1 + docs/components/streamformat.mdx | 22 +++++++ docs/sdks/tts/README.mdx | 39 +++++------ pyproject.toml | 2 +- src/openrouter/_version.py | 4 +- src/openrouter/components/__init__.py | 3 + src/openrouter/components/speechrequest.py | 26 ++++++-- .../components/speechsupportedparameters.py | 4 ++ src/openrouter/tts.py | 14 ++-- uv.lock | 2 +- 18 files changed, 179 insertions(+), 92 deletions(-) create mode 100644 docs/components/streamformat.mdx diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index deda3d40..333ea6d2 100644 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -1,19 +1,19 @@ lockVersion: 2.0.0 id: c48cf606-fb42-4a45-9c23-8f0555307828 management: - docChecksum: 1fb36d8fe6994efc875680f153470832 + docChecksum: 825bfff76c73da0325731e2ba8da4202 docVersion: 1.0.0 speakeasyVersion: 1.803.2 generationVersion: 2.950.13 - releaseVersion: 1.3.245 - configChecksum: 6338d4a43a124214f78f5298a6854178 + releaseVersion: 1.3.246 + configChecksum: 733089b0d7ea60f53efbf118c34405af repoURL: https://github.com/OpenRouterTeam/python-sdk.git installationURL: https://github.com/OpenRouterTeam/python-sdk.git published: true persistentEdits: - generation_id: f9afa0a4-3416-49a0-96b8-02d74b9f599a - pristine_commit_hash: 62ccc3fb84ee4d1f3c42fad184589190a3a50a34 - pristine_tree_hash: ea647dc6e16e01d457e89add465d6e5e0d857f45 + generation_id: 0ccec9dc-cb52-400c-834d-2dbaff752f32 + pristine_commit_hash: 33ca665870b0d7595b2c3d5bc7cddfe9a36b1d25 + pristine_tree_hash: 3d9d8d6d663094042cf4dbae0617d1bba8b25599 features: python: acceptHeaders: 3.0.0 @@ -7000,8 +7000,8 @@ trackedFiles: pristine_git_object: 62bc0076806110e866d63bf477349fe9753bdf3e docs/components/outputdelivery.mdx: id: 0cb4c1fb2927 - last_write_checksum: sha1:02ea6a68e8275fbdc527358512bba85e9fedd347 - pristine_git_object: 5604179c01583b203a9da51ce5229af8313ce25a + last_write_checksum: sha1:287cea36f48f7d2d6655d63c4e9f19affd64ccca + pristine_git_object: cfe9e59cce91f454ae3fb90790238537442aa6ce docs/components/outputfilesearchcallitem.mdx: id: 16f4409e4148 last_write_checksum: sha1:2ca9cc034ab3d2acb7456475d90ed65b7c65c8fd @@ -8776,8 +8776,8 @@ trackedFiles: pristine_git_object: f1efb6365d56d846e102d1b665590f58a6899211 docs/components/speechoutputmodality.mdx: id: a3a222faacda - last_write_checksum: sha1:ea913bbcc3d82aec213fa2c9e0af21222a3dd8b2 - pristine_git_object: 729223131c899c3ef139480ddffe22e1ccffa305 + last_write_checksum: sha1:8db8112c874d4a736fd297653ca6172ea66d1964 + pristine_git_object: 4fa75031d3033a6b1b90f6cb08e3e26f681899f5 docs/components/speechoutputmodalitytype.mdx: id: bc216dcb8091 last_write_checksum: sha1:201cce4f72878e6efd47edf139626c1e02eab816 @@ -8800,8 +8800,8 @@ trackedFiles: pristine_git_object: 38be122fce694e660cd56d82182dd3d15098479d docs/components/speechrequest.mdx: id: 06e81b0433f6 - last_write_checksum: sha1:34aa30a244b4bfd300bc2ce9088dc7959ae04678 - pristine_git_object: 20df033ed8bf659a2788ace32915adf6c6a74c70 + last_write_checksum: sha1:e268d103d91677943e9f60afb8a0ca24737b9abd + pristine_git_object: 78a1e3b014fde528de3fe4c9142656d772d756ce docs/components/speechrequestdatacollection.mdx: id: 6c5938568888 last_write_checksum: sha1:89a08b4c4de66c1ef7676792a38747e030ed6729 @@ -8828,8 +8828,8 @@ trackedFiles: pristine_git_object: 28816d7a32f629289c2a932e9c16a17183c25e69 docs/components/speechsupportedparameters.mdx: id: e40d7c8fb1e4 - last_write_checksum: sha1:aa79177157900a8673a1e31311462e645d933e29 - pristine_git_object: 39378df792773716c59e56ca2bc1ec7c9131c93c + last_write_checksum: sha1:85a86a6a38fc75f87623b39af760eb7797c0a7f8 + pristine_git_object: 0a99447929147a9acfcaf9820c75174b1a9a37b9 docs/components/speechturn.mdx: id: ca90a4443e6e last_write_checksum: sha1:68b0e3750740ff2ff4a34a5dd0a0f5a191e514f1 @@ -8958,6 +8958,10 @@ trackedFiles: id: 2fb7934965aa last_write_checksum: sha1:a5fc58c7a48c29f682beaa9f30accf1a620dd670 pristine_git_object: 7671de0f55c2bd170b86ffb4682ad9e456a11522 + docs/components/streamformat.mdx: + id: dc7c965ef755 + last_write_checksum: sha1:372eabd870bc2342257402dd2f216e518e88eb46 + pristine_git_object: 515298891f1da610e8de86e3888ae4594b4100ef docs/components/streamlogprob.mdx: id: 67598a2734a4 last_write_checksum: sha1:6db1530f644e35f8f17710f4f21c66506eea27c0 @@ -12640,8 +12644,8 @@ trackedFiles: pristine_git_object: bcbe30fccceb97caa3a0e170038245dcc7f1e540 docs/sdks/tts/README.mdx: id: cd1132543884 - last_write_checksum: sha1:dd814abd82b8fa498b0c84cd0af540c607132bd9 - pristine_git_object: d3d9218fe4c68a3d282f0ce8e39f2186a0b8a47a + last_write_checksum: sha1:36bb84fe391df95e0bf15450e67603f3db106aef + pristine_git_object: fd28773bdc6c7e80c1cfb30dbf92605b8f7f9d96 docs/sdks/vault/README.mdx: id: 3738c6722acd last_write_checksum: sha1:290b439ff730b9eabf4a6ef93737d1c61006b0fa @@ -12660,8 +12664,8 @@ trackedFiles: pristine_git_object: 3e38f1a929f7d6b1d6de74604aa87e3d8f010544 pyproject.toml: id: 5d07e7d72637 - last_write_checksum: sha1:a25a37f94607cea1f1a1e29a8fe07b7782a9ba5e - pristine_git_object: cf2c0ea4c4d168070dade5b8faacf0487f69cc15 + last_write_checksum: sha1:d133963a921ce2f638c14f9f3438cb1e6f491544 + pristine_git_object: 6014e72ed8695b2464a75b7dd709d76399234208 scripts/prepare_readme.py: id: e0c5957a6035 last_write_checksum: sha1:77f44b60b98bc126557ec27391f91dfba764bb54 @@ -12688,8 +12692,8 @@ trackedFiles: pristine_git_object: 86713cfea633e09d33b3d4e65281071fe20e6137 src/openrouter/_version.py: id: d8d15ad6c586 - last_write_checksum: sha1:80be0f28207ade97310f5873fbc1a8135cc8ea47 - pristine_git_object: 149b72e6a644f4f5f1efddc7f967bb8f6182d84b + last_write_checksum: sha1:6744ebf097cf9083395a410975c292993d61123a + pristine_git_object: afee1974f38b07507e67e3b8627fb3e745dad8db src/openrouter/alpha.py: id: 306c4d93308d last_write_checksum: sha1:80cc0f39649445431cc2247ed0e0765438467766 @@ -12736,8 +12740,8 @@ trackedFiles: pristine_git_object: ad3d247954547814054c01989a2dff3d12b3e4e1 src/openrouter/components/__init__.py: id: 81754e97b3f4 - last_write_checksum: sha1:981d6840b9827a149a88da7d6c23c9c664484e0e - pristine_git_object: 45c3d7f6ca27f7e13d3b7393c5ddf30c221555df + last_write_checksum: sha1:62fb1463197a8ee9c06daaaa7d1736b60b399051 + pristine_git_object: 799d8780225e137ac3294359f4eb11c64cc3c698 src/openrouter/components/aabenchmarkentry.py: id: e2e0f0b48c82 last_write_checksum: sha1:08125e1d60df82793e11e8aed6e3c9fdb7512ebb @@ -16280,12 +16284,12 @@ trackedFiles: pristine_git_object: 69c0355e7d575e6b7c52183d3cd5696611e4e8bf src/openrouter/components/speechrequest.py: id: 2a9400167112 - last_write_checksum: sha1:bb959c5995e0d83ef9932e178c46e297d133fc85 - pristine_git_object: 36c32a68f1b0d37c3ce89aea6e2eb3e4297170a7 + last_write_checksum: sha1:e85707cc35ca5d629cd61e5814482297a3c2665d + pristine_git_object: b88af6a262e303cf6fc995d29b9cae87d9e4b907 src/openrouter/components/speechsupportedparameters.py: id: 618f33cc9229 - last_write_checksum: sha1:6f3fe1b11d56407227306a93fb6d232066158913 - pristine_git_object: bea7e35329cb9b1b4f4ac2e7bb03306abd277d07 + last_write_checksum: sha1:e05046fb9df89bd1c7ac118dec1c51f00de91007 + pristine_git_object: c99fcc565b29c9053bb50a18561a4b38449998c3 src/openrouter/components/speechturn.py: id: 121e0a940f91 last_write_checksum: sha1:31bdba00e027b81de8a3872d48e694475cf02e7a @@ -17848,8 +17852,8 @@ trackedFiles: pristine_git_object: 701fa8597ff85f41a60736ade55fcb32f9ec7125 src/openrouter/tts.py: id: 5055d4b95f1d - last_write_checksum: sha1:f9d243bf8c8e10939d0ca1e4cf5bad9806012e6d - pristine_git_object: d88e0167943fe165376884e9634c47a37a04c1f2 + last_write_checksum: sha1:3a0b902e83a6987d94dffb1a752582704b471643 + pristine_git_object: 3fc05547bb566ec91045c6576eca6397ff9c3a9b src/openrouter/types/__init__.py: id: 5eab536205b7 last_write_checksum: sha1:f9ad14217f832e74f594285960125add50324be9 @@ -23401,4 +23405,6 @@ examples: examplesVersion: 1.0.2 releaseNotes: | ## Python SDK Changes: - * `open_router.tts.create_speech()`: `request.response_format` **Changed** + * `open_router.tts.create_speech()`: `request.stream_format` **Added** + * `open_router.tts.list_models()`: `response.data[].endpoints[].output_modalities[].supported_parameters.stream_format` **Added** + * `open_router.tts.get_model()`: `response.endpoints[].output_modalities[].supported_parameters.stream_format` **Added** diff --git a/.speakeasy/gen.yaml b/.speakeasy/gen.yaml index 18108743..38f9c2d6 100644 --- a/.speakeasy/gen.yaml +++ b/.speakeasy/gen.yaml @@ -37,7 +37,7 @@ generation: documentation: mintlify preApplyUnionDiscriminators: true python: - version: 1.3.245 + version: 1.3.246 additionalDependencies: dev: pytest: '>=8.3' diff --git a/.speakeasy/out.openapi.yaml b/.speakeasy/out.openapi.yaml index 906e393d..de8126e8 100644 --- a/.speakeasy/out.openapi.yaml +++ b/.speakeasy/out.openapi.yaml @@ -37050,7 +37050,7 @@ components: example: 'mistralai/voxtral-mini-tts-2603' type: 'string' output_delivery: - description: '`stream` (default) streams the audio bytes directly in the response body (or returns inline base64 JSON when `timestamp_granularities` is nonempty). `url` stores the generated audio in OpenRouter storage and returns a JSON response with a signed download `url`, `expires_at`, and `media_type` (plus `words` and/or `characters` when `timestamp_granularities` is nonempty). The URL is a bearer link: anyone holding it can download the audio until it expires, up to 24 hours after the audio was stored (use `expires_at`); the stored copy is deleted by the storage lifecycle within the following day. When a URL cannot be issued (zero-data-retention via account settings, guardrails, `provider.zdr`, or a ZDR endpoint; no workspace; or storage failure), untimed requests fall back to streaming raw audio bytes (except on a storage failure for responses larger than 10 MiB, which returns an error), and timed requests fall back to inline base64 JSON (`{audio, media_type, words?, characters?}`) with no `url`.' + description: '`stream` (default) streams the audio bytes directly in the response body (returns inline base64 JSON when `timestamp_granularities` is nonempty and `stream_format` is `"audio"`, or `text/event-stream` events when `stream_format` is `"sse"`). `url` stores the generated audio in OpenRouter storage and returns a JSON response with a signed download `url`, `expires_at`, and `media_type` (plus `words` and/or `characters` when `timestamp_granularities` is nonempty). The URL is a bearer link: anyone holding it can download the audio until it expires, up to 24 hours after the audio was stored (use `expires_at`); the stored copy is deleted by the storage lifecycle within the following day. When a URL cannot be issued (zero-data-retention via account settings, guardrails, `provider.zdr`, or a ZDR endpoint; no workspace; or storage failure), untimed requests fall back to streaming raw audio bytes (except on a storage failure for responses larger than 10 MiB, which returns an error), and timed requests fall back to inline base64 JSON (`{audio, media_type, words?, characters?}`) with no `url`.' enum: - 'stream' - 'url' @@ -37141,8 +37141,16 @@ components: example: 1 format: 'double' type: 'number' + stream_format: + description: 'Wire framing for inline responses. `audio` (default) returns raw audio bytes (or a buffered JSON envelope when `timestamp_granularities` is nonempty). `sse` streams `text/event-stream` events (`speech.audio.delta`, `speech.timestamps.delta` when `timestamp_granularities` is nonempty, `speech.audio.done`, and `error` on mid-stream failure) with the effective audio media type in `X-Audio-Media-Type`. Cannot be combined with `output_delivery: "url"`. Only routed to endpoints that advertise `sse` in `supported_parameters.stream_format` (and every requested granularity when `timestamp_granularities` is nonempty). Generated SDKs still type the 200 response as binary audio for compatibility; when using `stream_format: "sse"`, call the HTTP endpoint directly and parse `text/event-stream`.' + enum: + - 'audio' + - 'sse' + example: 'audio' + type: 'string' + x-speakeasy-unknown-values: allow timestamp_granularities: - description: 'Timings to return with the audio. When nonempty, the response is JSON instead of raw audio bytes: `{audio, media_type, words?, characters?}` with base64 audio, or `{url, expires_at, media_type, words?, characters?}` when `output_delivery` is `url`. If a signed URL cannot be issued (ZDR, no workspace, or storage failure), timed `url` requests fall back to the inline `{audio, media_type, ...}` envelope with no `url`. The audio defaults to `mp3` unless `response_format` is set. Each timing entry is `{text, start, end}` in seconds. Only routed to endpoints that support every requested granularity (`supported_parameters.timestamp_granularities` on the speech models list). A timed response is sent once the whole audio is generated, not streamed, and is capped at 10 MiB of decoded audio for both inline and `url` delivery (the provider timed response, including its alignment data, is capped too); longer outputs return an error, so use a shorter input or a smaller audio format. Generated SDKs still type the 200 response as binary audio for compatibility; call the HTTP endpoint directly and parse the JSON response when using `timestamp_granularities`. An empty array is treated as no timings.' + description: 'Timings to return with the audio. With the default `stream_format: "audio"`, the response is buffered JSON instead of raw audio bytes: `{audio, media_type, words?, characters?}` with base64 audio, or `{url, expires_at, media_type, words?, characters?}` when `output_delivery` is `url`. If a signed URL cannot be issued (ZDR, no workspace, or storage failure), timed `url` requests fall back to the inline `{audio, media_type, ...}` envelope with no `url`. Buffered timed responses are sent once the whole audio is generated and are capped at 10 MiB of decoded audio (the provider timed response, including its alignment data, is capped too); longer outputs return an error, so use a shorter input, a smaller audio format, or `stream_format: "sse"`. With `stream_format: "sse"`, the response is `text/event-stream` (`speech.audio.delta`, `speech.timestamps.delta`, `speech.audio.done`, and `error` on mid-stream failure) with the effective audio media type in `X-Audio-Media-Type` and no 10 MiB cap. The audio defaults to `mp3` unless `response_format` is set. Each timing entry is `{text, start, end}` in seconds. Only routed to endpoints that support every requested granularity for the requested `stream_format`. Generated SDKs still type the 200 response as binary audio for compatibility; call the HTTP endpoint directly and parse JSON (for `stream_format: "audio"`) or `text/event-stream` (for `stream_format: "sse"`). An empty array is treated as no timings.' example: - 'word' items: @@ -37205,6 +37213,11 @@ components: max: 4 min: 0.25 type: 'range' + stream_format: + type: 'enum' + values: + - 'audio' + - 'sse' timestamp_granularities: type: 'enum' values: @@ -37222,6 +37235,10 @@ components: $ref: '#/components/schemas/SpeechEnumParameter' speed: $ref: '#/components/schemas/SpeechRangeParameter' + stream_format: + allOf: + - $ref: '#/components/schemas/SpeechEnumParameter' + - description: 'The `stream_format` values the endpoint supports (`audio`, `sse`).' timestamp_granularities: allOf: - $ref: '#/components/schemas/SpeechEnumParameter' @@ -44221,7 +44238,7 @@ paths: example: '' format: 'binary' type: 'string' - description: 'Raw audio bytes stream (`audio/*`) by default. When `output_delivery` is `"url"`, returns `application/json` with `{ url, expires_at, media_type }` (a 24-hour signed download URL) unless zero-data-retention or missing workspace causes fallback to raw audio streaming. When `timestamp_granularities` is nonempty, always returns `application/json`: `{ audio, media_type }` with base64 audio (`SpeechTimedAudioResponse`), or `{ url, expires_at, media_type }` with URL delivery (`SpeechTimedUrlResponse`), each with the requested `words` and/or `characters` timings. A timed `url` request that cannot get a signed URL (zero-data-retention, missing workspace, or storage failure) returns the inline `{ audio, media_type }` envelope with no `url`.' + description: 'Raw audio bytes stream (`audio/*`) by default. When `stream_format` is `"sse"`, returns `text/event-stream` with `X-Audio-Media-Type` set to the effective audio media type (exposed via `Access-Control-Expose-Headers`) and default SSE `data:` frames (no named `event:` field) carrying one JSON object per event discriminated by `type`: `{"type":"speech.audio.delta","audio":""}` (base64-encoded audio chunk; decode each delta separately before concatenating bytes), `{"type":"speech.timestamps.delta","words"?:[{"text","start","end"}],"characters"?:[{"text","start","end"}]}` (when `timestamp_granularities` is nonempty; times in float seconds from start of output), `{"type":"speech.audio.done","media_type":"","usage"?:{"input_characters"?:number}}`, and `{"type":"error","error":{"message":""}}` on mid-stream failure. When `output_delivery` is `"url"`, returns `application/json` with `{ url, expires_at, media_type }` (a 24-hour signed download URL) unless zero-data-retention or missing workspace causes fallback to raw audio streaming. When `timestamp_granularities` is nonempty and `stream_format` is `"audio"` (default), returns `application/json`: `{ audio, media_type }` with base64 audio (`SpeechTimedAudioResponse`), or `{ url, expires_at, media_type }` with URL delivery (`SpeechTimedUrlResponse`), each with the requested `words` and/or `characters` timings. A timed `url` request that cannot get a signed URL (zero-data-retention, missing workspace, or storage failure) returns the inline `{ audio, media_type }` envelope with no `url`.' '400': content: application/json: diff --git a/.speakeasy/workflow.lock b/.speakeasy/workflow.lock index be31e5ce..7e898818 100644 --- a/.speakeasy/workflow.lock +++ b/.speakeasy/workflow.lock @@ -2,8 +2,8 @@ speakeasyVersion: 1.803.2 sources: OpenRouter API: sourceNamespace: open-router-chat-completions-api - sourceRevisionDigest: sha256:abd848ab874b2178f5ef217b5ab1bca1dd3d8cc83576ff06724b7662046252e8 - sourceBlobDigest: sha256:0810de5494b24165640c0d306ea7c21db614f0256076ed663b82c9787eca1627 + sourceRevisionDigest: sha256:8c4964898b84905744a337e016fd8360c795a9912330a03eeb6e6e2fde165a6b + sourceBlobDigest: sha256:b22c4c6acec0aa7b3978027ab90e094597af08bff4f7c6ae8c68c7dfaf13ca27 tags: - latest - 1.0.0 @@ -11,10 +11,10 @@ targets: open-router: source: OpenRouter API sourceNamespace: open-router-chat-completions-api - sourceRevisionDigest: sha256:abd848ab874b2178f5ef217b5ab1bca1dd3d8cc83576ff06724b7662046252e8 - sourceBlobDigest: sha256:0810de5494b24165640c0d306ea7c21db614f0256076ed663b82c9787eca1627 + sourceRevisionDigest: sha256:8c4964898b84905744a337e016fd8360c795a9912330a03eeb6e6e2fde165a6b + sourceBlobDigest: sha256:b22c4c6acec0aa7b3978027ab90e094597af08bff4f7c6ae8c68c7dfaf13ca27 codeSamplesNamespace: open-router-python-code-samples - codeSamplesRevisionDigest: sha256:5c76b483511f9673002b40469512060c4181e44ccab7b4b8c6c3561563168570 + codeSamplesRevisionDigest: sha256:09f29cdebc9b5e7a06992913784bee13d0d4c8d33921d1e9a9a4d5c664d9e647 workflow: workflowVersion: 1.0.0 speakeasyVersion: 1.803.2 diff --git a/RELEASES.md b/RELEASES.md index 03fae98e..d5576cd1 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -5219,4 +5219,14 @@ Based on: ### Generated - [python v1.3.245] . ### Releases -- [PyPI v1.3.245] https://pypi.org/project/openrouter/1.3.245 - . \ No newline at end of file +- [PyPI v1.3.245] https://pypi.org/project/openrouter/1.3.245 - . + +## 2026-12-04 19:20:47 +### Changes +Based on: +- OpenAPI Doc +- Speakeasy CLI 1.803.2 (2.950.13) https://github.com/speakeasy-api/speakeasy +### Generated +- [python v1.3.246] . +### Releases +- [PyPI v1.3.246] https://pypi.org/project/openrouter/1.3.246 - . \ No newline at end of file diff --git a/docs/components/outputdelivery.mdx b/docs/components/outputdelivery.mdx index 5604179c..cfe9e59c 100644 --- a/docs/components/outputdelivery.mdx +++ b/docs/components/outputdelivery.mdx @@ -2,7 +2,7 @@ title: "OutputDelivery" --- -`stream` (default) streams the audio bytes directly in the response body (or returns inline base64 JSON when `timestamp_granularities` is nonempty). `url` stores the generated audio in OpenRouter storage and returns a JSON response with a signed download `url`, `expires_at`, and `media_type` (plus `words` and/or `characters` when `timestamp_granularities` is nonempty). The URL is a bearer link: anyone holding it can download the audio until it expires, up to 24 hours after the audio was stored (use `expires_at`); the stored copy is deleted by the storage lifecycle within the following day. When a URL cannot be issued (zero-data-retention via account settings, guardrails, `provider.zdr`, or a ZDR endpoint; no workspace; or storage failure), untimed requests fall back to streaming raw audio bytes (except on a storage failure for responses larger than 10 MiB, which returns an error), and timed requests fall back to inline base64 JSON (`{audio, media_type, words?, characters?}`) with no `url`. +`stream` (default) streams the audio bytes directly in the response body (returns inline base64 JSON when `timestamp_granularities` is nonempty and `stream_format` is `"audio"`, or `text/event-stream` events when `stream_format` is `"sse"`). `url` stores the generated audio in OpenRouter storage and returns a JSON response with a signed download `url`, `expires_at`, and `media_type` (plus `words` and/or `characters` when `timestamp_granularities` is nonempty). The URL is a bearer link: anyone holding it can download the audio until it expires, up to 24 hours after the audio was stored (use `expires_at`); the stored copy is deleted by the storage lifecycle within the following day. When a URL cannot be issued (zero-data-retention via account settings, guardrails, `provider.zdr`, or a ZDR endpoint; no workspace; or storage failure), untimed requests fall back to streaming raw audio bytes (except on a storage failure for responses larger than 10 MiB, which returns an error), and timed requests fall back to inline base64 JSON (`{audio, media_type, words?, characters?}`) with no `url`. ## Example Usage diff --git a/docs/components/speechoutputmodality.mdx b/docs/components/speechoutputmodality.mdx index 72922313..4fa75031 100644 --- a/docs/components/speechoutputmodality.mdx +++ b/docs/components/speechoutputmodality.mdx @@ -4,8 +4,8 @@ title: "SpeechOutputModality" ## Fields -| Field | Type | Required | Description | Example | -| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `languages` | List[*str*] | ➖ | BCP 47 tags of the languages the provider documents for this output, for example `en`, `hi` or `pt-BR`. How the language is chosen (from the text, the voice, or a provider option) varies by provider. Absent: not described. | [
"en",
"fr",
"hi"
] | -| `supported_parameters` | [components.SpeechSupportedParameters](../components/speechsupportedparameters.mdx) | ✔️ | N/A | \{
"instructions": \{
"type": "unknown"
},
"response_format": \{
"type": "enum",
"values": [
"mp3",
"pcm"
]
},
"speed": \{
"max": 4,
"min": 0.25,
"type": "range"
},
"timestamp_granularities": \{
"type": "enum",
"values": [
"word",
"character"
]
},
"voice": \{
"type": "enum",
"values": [
"alloy",
"coral"
]
}
} | -| `type` | [components.SpeechOutputModalityType](../components/speechoutputmodalitytype.mdx) | ✔️ | N/A | | \ No newline at end of file +| Field | Type | Required | Description | Example | +| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `languages` | List[*str*] | ➖ | BCP 47 tags of the languages the provider documents for this output, for example `en`, `hi` or `pt-BR`. How the language is chosen (from the text, the voice, or a provider option) varies by provider. Absent: not described. | [
"en",
"fr",
"hi"
] | +| `supported_parameters` | [components.SpeechSupportedParameters](../components/speechsupportedparameters.mdx) | ✔️ | N/A | \{
"instructions": \{
"type": "unknown"
},
"response_format": \{
"type": "enum",
"values": [
"mp3",
"pcm"
]
},
"speed": \{
"max": 4,
"min": 0.25,
"type": "range"
},
"stream_format": \{
"type": "enum",
"values": [
"audio",
"sse"
]
},
"timestamp_granularities": \{
"type": "enum",
"values": [
"word",
"character"
]
},
"voice": \{
"type": "enum",
"values": [
"alloy",
"coral"
]
}
} | +| `type` | [components.SpeechOutputModalityType](../components/speechoutputmodalitytype.mdx) | ✔️ | N/A | | \ No newline at end of file diff --git a/docs/components/speechrequest.mdx b/docs/components/speechrequest.mdx index 20df033e..78a1e3b0 100644 --- a/docs/components/speechrequest.mdx +++ b/docs/components/speechrequest.mdx @@ -7,18 +7,19 @@ Text-to-speech request input ## Fields -| Field | Type | Required | Description | Example | -| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| `input` | [components.SpeechInput](../components/speechinput.mdx) | ✔️ | Text to synthesize, or a list of turns for multi-speaker input. Each turn has its own text, voice, and instructions. Multi-speaker input is supported by Gemini TTS models, by Fish Audio models other than S1, and by Speechify dialogue models. | Hello world | -| `input_references` | List[[components.SpeechInputReference](../components/speechinputreference.mdx)] | ➖ | Reference content for stateless voice cloning or voice design. Audio mode: one to three `input_audio` parts, each optionally paired with a `text` part carrying its transcript (a single clip accepts its transcript before or after it; with multiple clips each transcript immediately follows its clip), plus at most one `image_url` part as a scene image on providers that condition the cloned voice on its setting; only routed to endpoints that support voice cloning (and multiple references or image references when those parts are sent). Image mode: exactly one `image_url` part; only routed to endpoints that support image references. Video mode: exactly one `video_url` part with a public http(s) URL, optionally with one to three `input_audio` parts (and their `text` transcripts) grouped as in audio mode, and no `image_url` part; Seed Audio 1.5 ignores those transcripts, so the words the voices speak go in `input`; only routed to endpoints that support video references (and voice cloning when clips are sent, plus multiple references for two or three clips). An empty array is treated as no reference. | [
\{
"input_audio": \{
"data": "data:audio/wav;base64,UklGRuQXDABXQVZF..."
},
"type": "input_audio"
},
\{
"text": "I used to rule the world.",
"type": "text"
}
] | -| `instructions` | *Optional[str]* | ➖ | Delivery instructions for the whole request, such as tone, pacing, or emotion. For the selected endpoint in the [Speech Models API](https://openrouter.ai/docs/guides/overview/multimodal/tts#via-the-speech-models-api), look for `supported_parameters.instructions` in the `output_modalities` entry with `type: speech`. | Speak in a warm and friendly tone. | -| `model` | *str* | ✔️ | TTS model identifier | mistralai/voxtral-mini-tts-2603 | -| `output_delivery` | [Optional[components.OutputDelivery]](../components/outputdelivery.mdx) | ➖ | `stream` (default) streams the audio bytes directly in the response body (or returns inline base64 JSON when `timestamp_granularities` is nonempty). `url` stores the generated audio in OpenRouter storage and returns a JSON response with a signed download `url`, `expires_at`, and `media_type` (plus `words` and/or `characters` when `timestamp_granularities` is nonempty). The URL is a bearer link: anyone holding it can download the audio until it expires, up to 24 hours after the audio was stored (use `expires_at`); the stored copy is deleted by the storage lifecycle within the following day. When a URL cannot be issued (zero-data-retention via account settings, guardrails, `provider.zdr`, or a ZDR endpoint; no workspace; or storage failure), untimed requests fall back to streaming raw audio bytes (except on a storage failure for responses larger than 10 MiB, which returns an error), and timed requests fall back to inline base64 JSON (`{audio, media_type, words?, characters?}`) with no `url`. | stream | -| `provider` | [Optional[components.SpeechRequestProvider]](../components/speechrequestprovider.mdx) | ➖ | Provider configuration: provider routing preferences (`order`, `only`, `ignore`, `allow_fallbacks`), data policy routing preferences (`zdr`, `data_collection`) and provider-specific passthrough options | | -| `response_format` | [Optional[components.SpeechRequestResponseFormat]](../components/speechrequestresponseformat.mdx) | ➖ | Audio output format. Defaults to `pcm`, or to `mp3` when `timestamp_granularities` is nonempty. | pcm | -| `session_id` | *Optional[str]* | ➖ | A unique identifier for grouping related requests (e.g., a conversation or agent workflow). Used for observability grouping in Broadcast and private logging; never sent to the provider. If provided in both the request body and the x-session-id header, the body value takes precedence. Maximum of 256 characters. | session-1234 | -| `speed` | *Optional[float]* | ➖ | Playback speed multiplier. Honored by models that support it (e.g. OpenAI TTS). Other providers either ignore it or return a 400 for a non-default value when the model has no speed control. | 1 | -| `timestamp_granularities` | List[[components.TimestampGranularity](../components/timestampgranularity.mdx)] | ➖ | Timings to return with the audio. When nonempty, the response is JSON instead of raw audio bytes: `{audio, media_type, words?, characters?}` with base64 audio, or `{url, expires_at, media_type, words?, characters?}` when `output_delivery` is `url`. If a signed URL cannot be issued (ZDR, no workspace, or storage failure), timed `url` requests fall back to the inline `{audio, media_type, ...}` envelope with no `url`. The audio defaults to `mp3` unless `response_format` is set. Each timing entry is `{text, start, end}` in seconds. Only routed to endpoints that support every requested granularity (`supported_parameters.timestamp_granularities` on the speech models list). A timed response is sent once the whole audio is generated, not streamed, and is capped at 10 MiB of decoded audio for both inline and `url` delivery (the provider timed response, including its alignment data, is capped too); longer outputs return an error, so use a shorter input or a smaller audio format. Generated SDKs still type the 200 response as binary audio for compatibility; call the HTTP endpoint directly and parse the JSON response when using `timestamp_granularities`. An empty array is treated as no timings. | [
"word"
] | -| `trace` | [Optional[components.TraceConfig]](../components/traceconfig.mdx) | ➖ | Metadata for observability and tracing. Known keys (trace_id, trace_name, span_name, generation_name, parent_span_id) have special handling. Additional keys are passed through as custom metadata to configured broadcast destinations. | \{
"trace_id": "trace-abc123",
"trace_name": "my-app-trace"
} | -| `user` | *Optional[str]* | ➖ | A unique identifier representing your end-user. Forwarded to Broadcast and private logging as the end-user id; never sent to the provider. | user-1234 | -| `voice` | *Optional[str]* | ➖ | Voice identifier (provider-specific). Required by most providers; only Seed Audio, HeyGen, Fish Audio, AssemblyAI, Speechify accept requests without it. | en_paul_neutral | \ No newline at end of file +| Field | Type | Required | Description | Example | +| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `input` | [components.SpeechInput](../components/speechinput.mdx) | ✔️ | Text to synthesize, or a list of turns for multi-speaker input. Each turn has its own text, voice, and instructions. Multi-speaker input is supported by Gemini TTS models, by Fish Audio models other than S1, and by Speechify dialogue models. | Hello world | +| `input_references` | List[[components.SpeechInputReference](../components/speechinputreference.mdx)] | ➖ | Reference content for stateless voice cloning or voice design. Audio mode: one to three `input_audio` parts, each optionally paired with a `text` part carrying its transcript (a single clip accepts its transcript before or after it; with multiple clips each transcript immediately follows its clip), plus at most one `image_url` part as a scene image on providers that condition the cloned voice on its setting; only routed to endpoints that support voice cloning (and multiple references or image references when those parts are sent). Image mode: exactly one `image_url` part; only routed to endpoints that support image references. Video mode: exactly one `video_url` part with a public http(s) URL, optionally with one to three `input_audio` parts (and their `text` transcripts) grouped as in audio mode, and no `image_url` part; Seed Audio 1.5 ignores those transcripts, so the words the voices speak go in `input`; only routed to endpoints that support video references (and voice cloning when clips are sent, plus multiple references for two or three clips). An empty array is treated as no reference. | [
\{
"input_audio": \{
"data": "data:audio/wav;base64,UklGRuQXDABXQVZF..."
},
"type": "input_audio"
},
\{
"text": "I used to rule the world.",
"type": "text"
}
] | +| `instructions` | *Optional[str]* | ➖ | Delivery instructions for the whole request, such as tone, pacing, or emotion. For the selected endpoint in the [Speech Models API](https://openrouter.ai/docs/guides/overview/multimodal/tts#via-the-speech-models-api), look for `supported_parameters.instructions` in the `output_modalities` entry with `type: speech`. | Speak in a warm and friendly tone. | +| `model` | *str* | ✔️ | TTS model identifier | mistralai/voxtral-mini-tts-2603 | +| `output_delivery` | [Optional[components.OutputDelivery]](../components/outputdelivery.mdx) | ➖ | `stream` (default) streams the audio bytes directly in the response body (returns inline base64 JSON when `timestamp_granularities` is nonempty and `stream_format` is `"audio"`, or `text/event-stream` events when `stream_format` is `"sse"`). `url` stores the generated audio in OpenRouter storage and returns a JSON response with a signed download `url`, `expires_at`, and `media_type` (plus `words` and/or `characters` when `timestamp_granularities` is nonempty). The URL is a bearer link: anyone holding it can download the audio until it expires, up to 24 hours after the audio was stored (use `expires_at`); the stored copy is deleted by the storage lifecycle within the following day. When a URL cannot be issued (zero-data-retention via account settings, guardrails, `provider.zdr`, or a ZDR endpoint; no workspace; or storage failure), untimed requests fall back to streaming raw audio bytes (except on a storage failure for responses larger than 10 MiB, which returns an error), and timed requests fall back to inline base64 JSON (`{audio, media_type, words?, characters?}`) with no `url`. | stream | +| `provider` | [Optional[components.SpeechRequestProvider]](../components/speechrequestprovider.mdx) | ➖ | Provider configuration: provider routing preferences (`order`, `only`, `ignore`, `allow_fallbacks`), data policy routing preferences (`zdr`, `data_collection`) and provider-specific passthrough options | | +| `response_format` | [Optional[components.SpeechRequestResponseFormat]](../components/speechrequestresponseformat.mdx) | ➖ | Audio output format. Defaults to `pcm`, or to `mp3` when `timestamp_granularities` is nonempty. | pcm | +| `session_id` | *Optional[str]* | ➖ | A unique identifier for grouping related requests (e.g., a conversation or agent workflow). Used for observability grouping in Broadcast and private logging; never sent to the provider. If provided in both the request body and the x-session-id header, the body value takes precedence. Maximum of 256 characters. | session-1234 | +| `speed` | *Optional[float]* | ➖ | Playback speed multiplier. Honored by models that support it (e.g. OpenAI TTS). Other providers either ignore it or return a 400 for a non-default value when the model has no speed control. | 1 | +| `stream_format` | [Optional[components.StreamFormat]](../components/streamformat.mdx) | ➖ | Wire framing for inline responses. `audio` (default) returns raw audio bytes (or a buffered JSON envelope when `timestamp_granularities` is nonempty). `sse` streams `text/event-stream` events (`speech.audio.delta`, `speech.timestamps.delta` when `timestamp_granularities` is nonempty, `speech.audio.done`, and `error` on mid-stream failure) with the effective audio media type in `X-Audio-Media-Type`. Cannot be combined with `output_delivery: "url"`. Only routed to endpoints that advertise `sse` in `supported_parameters.stream_format` (and every requested granularity when `timestamp_granularities` is nonempty). Generated SDKs still type the 200 response as binary audio for compatibility; when using `stream_format: "sse"`, call the HTTP endpoint directly and parse `text/event-stream`. | audio | +| `timestamp_granularities` | List[[components.TimestampGranularity](../components/timestampgranularity.mdx)] | ➖ | Timings to return with the audio. With the default `stream_format: "audio"`, the response is buffered JSON instead of raw audio bytes: `{audio, media_type, words?, characters?}` with base64 audio, or `{url, expires_at, media_type, words?, characters?}` when `output_delivery` is `url`. If a signed URL cannot be issued (ZDR, no workspace, or storage failure), timed `url` requests fall back to the inline `{audio, media_type, ...}` envelope with no `url`. Buffered timed responses are sent once the whole audio is generated and are capped at 10 MiB of decoded audio (the provider timed response, including its alignment data, is capped too); longer outputs return an error, so use a shorter input, a smaller audio format, or `stream_format: "sse"`. With `stream_format: "sse"`, the response is `text/event-stream` (`speech.audio.delta`, `speech.timestamps.delta`, `speech.audio.done`, and `error` on mid-stream failure) with the effective audio media type in `X-Audio-Media-Type` and no 10 MiB cap. The audio defaults to `mp3` unless `response_format` is set. Each timing entry is `{text, start, end}` in seconds. Only routed to endpoints that support every requested granularity for the requested `stream_format`. Generated SDKs still type the 200 response as binary audio for compatibility; call the HTTP endpoint directly and parse JSON (for `stream_format: "audio"`) or `text/event-stream` (for `stream_format: "sse"`). An empty array is treated as no timings. | [
"word"
] | +| `trace` | [Optional[components.TraceConfig]](../components/traceconfig.mdx) | ➖ | Metadata for observability and tracing. Known keys (trace_id, trace_name, span_name, generation_name, parent_span_id) have special handling. Additional keys are passed through as custom metadata to configured broadcast destinations. | \{
"trace_id": "trace-abc123",
"trace_name": "my-app-trace"
} | +| `user` | *Optional[str]* | ➖ | A unique identifier representing your end-user. Forwarded to Broadcast and private logging as the end-user id; never sent to the provider. | user-1234 | +| `voice` | *Optional[str]* | ➖ | Voice identifier (provider-specific). Required by most providers; only Seed Audio, HeyGen, Fish Audio, AssemblyAI, Speechify accept requests without it. | en_paul_neutral | \ No newline at end of file diff --git a/docs/components/speechsupportedparameters.mdx b/docs/components/speechsupportedparameters.mdx index 39378df7..0a994479 100644 --- a/docs/components/speechsupportedparameters.mdx +++ b/docs/components/speechsupportedparameters.mdx @@ -9,5 +9,6 @@ title: "SpeechSupportedParameters" | `instructions` | [Optional[components.SpeechUnknownParameter]](../components/speechunknownparameter.mdx) | ➖ | N/A | \{
"type": "unknown"
} | | `response_format` | [Optional[components.SpeechEnumParameter]](../components/speechenumparameter.mdx) | ➖ | N/A | \{
"type": "enum",
"values": [
"alloy",
"coral"
]
} | | `speed` | [Optional[components.SpeechRangeParameter]](../components/speechrangeparameter.mdx) | ➖ | The accepted `speed` range. Absent: the provider documents no range; some providers still forward `speed`. | \{
"max": 4,
"min": 0.25,
"type": "range"
} | +| `stream_format` | [Optional[components.SpeechEnumParameter]](../components/speechenumparameter.mdx) | ➖ | N/A | \{
"type": "enum",
"values": [
"alloy",
"coral"
]
} | | `timestamp_granularities` | [Optional[components.SpeechEnumParameter]](../components/speechenumparameter.mdx) | ➖ | N/A | \{
"type": "enum",
"values": [
"alloy",
"coral"
]
} | | `voice` | [Optional[components.SpeechVoiceParameter]](../components/speechvoiceparameter.mdx) | ➖ | `enum` lists the documented voices in `values`; some providers also accept voice IDs not listed there (custom or cloned voices). `unknown` means the field is accepted but no voices are listed. | \{
"type": "enum",
"values": [
"alloy",
"coral"
]
} | \ No newline at end of file diff --git a/docs/components/streamformat.mdx b/docs/components/streamformat.mdx new file mode 100644 index 00000000..51529889 --- /dev/null +++ b/docs/components/streamformat.mdx @@ -0,0 +1,22 @@ +--- +title: "StreamFormat" +--- + +Wire framing for inline responses. `audio` (default) returns raw audio bytes (or a buffered JSON envelope when `timestamp_granularities` is nonempty). `sse` streams `text/event-stream` events (`speech.audio.delta`, `speech.timestamps.delta` when `timestamp_granularities` is nonempty, `speech.audio.done`, and `error` on mid-stream failure) with the effective audio media type in `X-Audio-Media-Type`. Cannot be combined with `output_delivery: "url"`. Only routed to endpoints that advertise `sse` in `supported_parameters.stream_format` (and every requested granularity when `timestamp_granularities` is nonempty). Generated SDKs still type the 200 response as binary audio for compatibility; when using `stream_format: "sse"`, call the HTTP endpoint directly and parse `text/event-stream`. + +## Example Usage + +```python +from openrouter.components import StreamFormat + +# Open enum: unrecognized values are captured as UnrecognizedStr +value: StreamFormat = "audio" +``` + + +## Values + +This is an open enum. Unrecognized values will not fail type checks. + +- `"audio"` +- `"sse"` diff --git a/docs/sdks/tts/README.mdx b/docs/sdks/tts/README.mdx index d3d9218f..fd28773b 100644 --- a/docs/sdks/tts/README.mdx +++ b/docs/sdks/tts/README.mdx @@ -40,25 +40,26 @@ with OpenRouter( ### Parameters -| Parameter | Type | Required | Description | Example | -| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| `input` | [components.SpeechInput](../../components/speechinput.mdx) | ✔️ | Text to synthesize, or a list of turns for multi-speaker input. Each turn has its own text, voice, and instructions. Multi-speaker input is supported by Gemini TTS models, by Fish Audio models other than S1, and by Speechify dialogue models. | Hello world | -| `model` | *str* | ✔️ | TTS model identifier | mistralai/voxtral-mini-tts-2603 | -| `http_referer` | *Optional[str]* | ➖ | The app identifier should be your app's URL and is used as the primary identifier for rankings.
This is used to track API usage per application.
| | -| `x_open_router_title` | *Optional[str]* | ➖ | The app display name allows you to customize how your app appears in OpenRouter's dashboard.
| | -| `x_open_router_categories` | *Optional[str]* | ➖ | Comma-separated list of app categories (e.g. "cli-agent,cloud-agent"). Used for marketplace rankings.
| | -| `input_references` | List[[components.SpeechInputReference](../../components/speechinputreference.mdx)] | ➖ | Reference content for stateless voice cloning or voice design. Audio mode: one to three `input_audio` parts, each optionally paired with a `text` part carrying its transcript (a single clip accepts its transcript before or after it; with multiple clips each transcript immediately follows its clip), plus at most one `image_url` part as a scene image on providers that condition the cloned voice on its setting; only routed to endpoints that support voice cloning (and multiple references or image references when those parts are sent). Image mode: exactly one `image_url` part; only routed to endpoints that support image references. Video mode: exactly one `video_url` part with a public http(s) URL, optionally with one to three `input_audio` parts (and their `text` transcripts) grouped as in audio mode, and no `image_url` part; Seed Audio 1.5 ignores those transcripts, so the words the voices speak go in `input`; only routed to endpoints that support video references (and voice cloning when clips are sent, plus multiple references for two or three clips). An empty array is treated as no reference. | [
\{
"input_audio": \{
"data": "data:audio/wav;base64,UklGRuQXDABXQVZF..."
},
"type": "input_audio"
},
\{
"text": "I used to rule the world.",
"type": "text"
}
] | -| `instructions` | *Optional[str]* | ➖ | Delivery instructions for the whole request, such as tone, pacing, or emotion. For the selected endpoint in the [Speech Models API](https://openrouter.ai/docs/guides/overview/multimodal/tts#via-the-speech-models-api), look for `supported_parameters.instructions` in the `output_modalities` entry with `type: speech`. | Speak in a warm and friendly tone. | -| `output_delivery` | [Optional[components.OutputDelivery]](../../components/outputdelivery.mdx) | ➖ | `stream` (default) streams the audio bytes directly in the response body (or returns inline base64 JSON when `timestamp_granularities` is nonempty). `url` stores the generated audio in OpenRouter storage and returns a JSON response with a signed download `url`, `expires_at`, and `media_type` (plus `words` and/or `characters` when `timestamp_granularities` is nonempty). The URL is a bearer link: anyone holding it can download the audio until it expires, up to 24 hours after the audio was stored (use `expires_at`); the stored copy is deleted by the storage lifecycle within the following day. When a URL cannot be issued (zero-data-retention via account settings, guardrails, `provider.zdr`, or a ZDR endpoint; no workspace; or storage failure), untimed requests fall back to streaming raw audio bytes (except on a storage failure for responses larger than 10 MiB, which returns an error), and timed requests fall back to inline base64 JSON (`{audio, media_type, words?, characters?}`) with no `url`. | stream | -| `provider` | [Optional[components.SpeechRequestProvider]](../../components/speechrequestprovider.mdx) | ➖ | Provider configuration: provider routing preferences (`order`, `only`, `ignore`, `allow_fallbacks`), data policy routing preferences (`zdr`, `data_collection`) and provider-specific passthrough options | | -| `response_format` | [Optional[components.SpeechRequestResponseFormat]](../../components/speechrequestresponseformat.mdx) | ➖ | Audio output format. Defaults to `pcm`, or to `mp3` when `timestamp_granularities` is nonempty. | pcm | -| `session_id` | *Optional[str]* | ➖ | A unique identifier for grouping related requests (e.g., a conversation or agent workflow). Used for observability grouping in Broadcast and private logging; never sent to the provider. If provided in both the request body and the x-session-id header, the body value takes precedence. Maximum of 256 characters. | session-1234 | -| `speed` | *Optional[float]* | ➖ | Playback speed multiplier. Honored by models that support it (e.g. OpenAI TTS). Other providers either ignore it or return a 400 for a non-default value when the model has no speed control. | 1 | -| `timestamp_granularities` | List[[components.TimestampGranularity](../../components/timestampgranularity.mdx)] | ➖ | Timings to return with the audio. When nonempty, the response is JSON instead of raw audio bytes: `{audio, media_type, words?, characters?}` with base64 audio, or `{url, expires_at, media_type, words?, characters?}` when `output_delivery` is `url`. If a signed URL cannot be issued (ZDR, no workspace, or storage failure), timed `url` requests fall back to the inline `{audio, media_type, ...}` envelope with no `url`. The audio defaults to `mp3` unless `response_format` is set. Each timing entry is `{text, start, end}` in seconds. Only routed to endpoints that support every requested granularity (`supported_parameters.timestamp_granularities` on the speech models list). A timed response is sent once the whole audio is generated, not streamed, and is capped at 10 MiB of decoded audio for both inline and `url` delivery (the provider timed response, including its alignment data, is capped too); longer outputs return an error, so use a shorter input or a smaller audio format. Generated SDKs still type the 200 response as binary audio for compatibility; call the HTTP endpoint directly and parse the JSON response when using `timestamp_granularities`. An empty array is treated as no timings. | [
"word"
] | -| `trace` | [Optional[components.TraceConfig]](../../components/traceconfig.mdx) | ➖ | Metadata for observability and tracing. Known keys (trace_id, trace_name, span_name, generation_name, parent_span_id) have special handling. Additional keys are passed through as custom metadata to configured broadcast destinations. | \{
"trace_id": "trace-abc123",
"trace_name": "my-app-trace"
} | -| `user` | *Optional[str]* | ➖ | A unique identifier representing your end-user. Forwarded to Broadcast and private logging as the end-user id; never sent to the provider. | user-1234 | -| `voice` | *Optional[str]* | ➖ | Voice identifier (provider-specific). Required by most providers; only Seed Audio, HeyGen, Fish Audio, AssemblyAI, Speechify accept requests without it. | en_paul_neutral | -| `retries` | [Optional[utils.RetryConfig]](../../models/utils/retryconfig.mdx) | ➖ | Configuration to override the default retry behavior of the client. | | +| Parameter | Type | Required | Description | Example | +| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `input` | [components.SpeechInput](../../components/speechinput.mdx) | ✔️ | Text to synthesize, or a list of turns for multi-speaker input. Each turn has its own text, voice, and instructions. Multi-speaker input is supported by Gemini TTS models, by Fish Audio models other than S1, and by Speechify dialogue models. | Hello world | +| `model` | *str* | ✔️ | TTS model identifier | mistralai/voxtral-mini-tts-2603 | +| `http_referer` | *Optional[str]* | ➖ | The app identifier should be your app's URL and is used as the primary identifier for rankings.
This is used to track API usage per application.
| | +| `x_open_router_title` | *Optional[str]* | ➖ | The app display name allows you to customize how your app appears in OpenRouter's dashboard.
| | +| `x_open_router_categories` | *Optional[str]* | ➖ | Comma-separated list of app categories (e.g. "cli-agent,cloud-agent"). Used for marketplace rankings.
| | +| `input_references` | List[[components.SpeechInputReference](../../components/speechinputreference.mdx)] | ➖ | Reference content for stateless voice cloning or voice design. Audio mode: one to three `input_audio` parts, each optionally paired with a `text` part carrying its transcript (a single clip accepts its transcript before or after it; with multiple clips each transcript immediately follows its clip), plus at most one `image_url` part as a scene image on providers that condition the cloned voice on its setting; only routed to endpoints that support voice cloning (and multiple references or image references when those parts are sent). Image mode: exactly one `image_url` part; only routed to endpoints that support image references. Video mode: exactly one `video_url` part with a public http(s) URL, optionally with one to three `input_audio` parts (and their `text` transcripts) grouped as in audio mode, and no `image_url` part; Seed Audio 1.5 ignores those transcripts, so the words the voices speak go in `input`; only routed to endpoints that support video references (and voice cloning when clips are sent, plus multiple references for two or three clips). An empty array is treated as no reference. | [
\{
"input_audio": \{
"data": "data:audio/wav;base64,UklGRuQXDABXQVZF..."
},
"type": "input_audio"
},
\{
"text": "I used to rule the world.",
"type": "text"
}
] | +| `instructions` | *Optional[str]* | ➖ | Delivery instructions for the whole request, such as tone, pacing, or emotion. For the selected endpoint in the [Speech Models API](https://openrouter.ai/docs/guides/overview/multimodal/tts#via-the-speech-models-api), look for `supported_parameters.instructions` in the `output_modalities` entry with `type: speech`. | Speak in a warm and friendly tone. | +| `output_delivery` | [Optional[components.OutputDelivery]](../../components/outputdelivery.mdx) | ➖ | `stream` (default) streams the audio bytes directly in the response body (returns inline base64 JSON when `timestamp_granularities` is nonempty and `stream_format` is `"audio"`, or `text/event-stream` events when `stream_format` is `"sse"`). `url` stores the generated audio in OpenRouter storage and returns a JSON response with a signed download `url`, `expires_at`, and `media_type` (plus `words` and/or `characters` when `timestamp_granularities` is nonempty). The URL is a bearer link: anyone holding it can download the audio until it expires, up to 24 hours after the audio was stored (use `expires_at`); the stored copy is deleted by the storage lifecycle within the following day. When a URL cannot be issued (zero-data-retention via account settings, guardrails, `provider.zdr`, or a ZDR endpoint; no workspace; or storage failure), untimed requests fall back to streaming raw audio bytes (except on a storage failure for responses larger than 10 MiB, which returns an error), and timed requests fall back to inline base64 JSON (`{audio, media_type, words?, characters?}`) with no `url`. | stream | +| `provider` | [Optional[components.SpeechRequestProvider]](../../components/speechrequestprovider.mdx) | ➖ | Provider configuration: provider routing preferences (`order`, `only`, `ignore`, `allow_fallbacks`), data policy routing preferences (`zdr`, `data_collection`) and provider-specific passthrough options | | +| `response_format` | [Optional[components.SpeechRequestResponseFormat]](../../components/speechrequestresponseformat.mdx) | ➖ | Audio output format. Defaults to `pcm`, or to `mp3` when `timestamp_granularities` is nonempty. | pcm | +| `session_id` | *Optional[str]* | ➖ | A unique identifier for grouping related requests (e.g., a conversation or agent workflow). Used for observability grouping in Broadcast and private logging; never sent to the provider. If provided in both the request body and the x-session-id header, the body value takes precedence. Maximum of 256 characters. | session-1234 | +| `speed` | *Optional[float]* | ➖ | Playback speed multiplier. Honored by models that support it (e.g. OpenAI TTS). Other providers either ignore it or return a 400 for a non-default value when the model has no speed control. | 1 | +| `stream_format` | [Optional[components.StreamFormat]](../../components/streamformat.mdx) | ➖ | Wire framing for inline responses. `audio` (default) returns raw audio bytes (or a buffered JSON envelope when `timestamp_granularities` is nonempty). `sse` streams `text/event-stream` events (`speech.audio.delta`, `speech.timestamps.delta` when `timestamp_granularities` is nonempty, `speech.audio.done`, and `error` on mid-stream failure) with the effective audio media type in `X-Audio-Media-Type`. Cannot be combined with `output_delivery: "url"`. Only routed to endpoints that advertise `sse` in `supported_parameters.stream_format` (and every requested granularity when `timestamp_granularities` is nonempty). Generated SDKs still type the 200 response as binary audio for compatibility; when using `stream_format: "sse"`, call the HTTP endpoint directly and parse `text/event-stream`. | audio | +| `timestamp_granularities` | List[[components.TimestampGranularity](../../components/timestampgranularity.mdx)] | ➖ | Timings to return with the audio. With the default `stream_format: "audio"`, the response is buffered JSON instead of raw audio bytes: `{audio, media_type, words?, characters?}` with base64 audio, or `{url, expires_at, media_type, words?, characters?}` when `output_delivery` is `url`. If a signed URL cannot be issued (ZDR, no workspace, or storage failure), timed `url` requests fall back to the inline `{audio, media_type, ...}` envelope with no `url`. Buffered timed responses are sent once the whole audio is generated and are capped at 10 MiB of decoded audio (the provider timed response, including its alignment data, is capped too); longer outputs return an error, so use a shorter input, a smaller audio format, or `stream_format: "sse"`. With `stream_format: "sse"`, the response is `text/event-stream` (`speech.audio.delta`, `speech.timestamps.delta`, `speech.audio.done`, and `error` on mid-stream failure) with the effective audio media type in `X-Audio-Media-Type` and no 10 MiB cap. The audio defaults to `mp3` unless `response_format` is set. Each timing entry is `{text, start, end}` in seconds. Only routed to endpoints that support every requested granularity for the requested `stream_format`. Generated SDKs still type the 200 response as binary audio for compatibility; call the HTTP endpoint directly and parse JSON (for `stream_format: "audio"`) or `text/event-stream` (for `stream_format: "sse"`). An empty array is treated as no timings. | [
"word"
] | +| `trace` | [Optional[components.TraceConfig]](../../components/traceconfig.mdx) | ➖ | Metadata for observability and tracing. Known keys (trace_id, trace_name, span_name, generation_name, parent_span_id) have special handling. Additional keys are passed through as custom metadata to configured broadcast destinations. | \{
"trace_id": "trace-abc123",
"trace_name": "my-app-trace"
} | +| `user` | *Optional[str]* | ➖ | A unique identifier representing your end-user. Forwarded to Broadcast and private logging as the end-user id; never sent to the provider. | user-1234 | +| `voice` | *Optional[str]* | ➖ | Voice identifier (provider-specific). Required by most providers; only Seed Audio, HeyGen, Fish Audio, AssemblyAI, Speechify accept requests without it. | en_paul_neutral | +| `retries` | [Optional[utils.RetryConfig]](../../models/utils/retryconfig.mdx) | ➖ | Configuration to override the default retry behavior of the client. | | ### Response diff --git a/pyproject.toml b/pyproject.toml index cf2c0ea4..6014e72e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "openrouter" -version = "1.3.245" +version = "1.3.246" description = "Official Python Client SDK for OpenRouter." authors = [{ name = "OpenRouter" },] readme = "README-PYPI.md" diff --git a/src/openrouter/_version.py b/src/openrouter/_version.py index 149b72e6..afee1974 100644 --- a/src/openrouter/_version.py +++ b/src/openrouter/_version.py @@ -3,10 +3,10 @@ import importlib.metadata __title__: str = "openrouter" -__version__: str = "1.3.245" +__version__: str = "1.3.246" __openapi_doc_version__: str = "1.0.0" __gen_version__: str = "2.950.13" -__user_agent__: str = "speakeasy-sdk/python 1.3.245 2.950.13 1.0.0 openrouter" +__user_agent__: str = "speakeasy-sdk/python 1.3.246 2.950.13 1.0.0 openrouter" try: if __package__ is not None: diff --git a/src/openrouter/components/__init__.py b/src/openrouter/components/__init__.py index 45c3d7f6..799d8780 100644 --- a/src/openrouter/components/__init__.py +++ b/src/openrouter/components/__init__.py @@ -4941,6 +4941,7 @@ SpeechRequestProviderTypedDict, SpeechRequestResponseFormat, SpeechRequestTypedDict, + StreamFormat, TimestampGranularity, ) from .speechsupportedparameters import ( @@ -9126,6 +9127,7 @@ "StreamEventsResponseOutputItemDoneType", "StreamEventsResponseOutputItemDoneTypedDict", "StreamEventsTypedDict", + "StreamFormat", "StreamLogprob", "StreamLogprobTopLogprob", "StreamLogprobTopLogprobTypedDict", @@ -13261,6 +13263,7 @@ "SpeechRequestProviderTypedDict": ".speechrequest", "SpeechRequestResponseFormat": ".speechrequest", "SpeechRequestTypedDict": ".speechrequest", + "StreamFormat": ".speechrequest", "TimestampGranularity": ".speechrequest", "SpeechSupportedParameters": ".speechsupportedparameters", "SpeechSupportedParametersTypedDict": ".speechsupportedparameters", diff --git a/src/openrouter/components/speechrequest.py b/src/openrouter/components/speechrequest.py index 36c32a68..b88af6a2 100644 --- a/src/openrouter/components/speechrequest.py +++ b/src/openrouter/components/speechrequest.py @@ -26,7 +26,7 @@ ], UnrecognizedStr, ] -r"""`stream` (default) streams the audio bytes directly in the response body (or returns inline base64 JSON when `timestamp_granularities` is nonempty). `url` stores the generated audio in OpenRouter storage and returns a JSON response with a signed download `url`, `expires_at`, and `media_type` (plus `words` and/or `characters` when `timestamp_granularities` is nonempty). The URL is a bearer link: anyone holding it can download the audio until it expires, up to 24 hours after the audio was stored (use `expires_at`); the stored copy is deleted by the storage lifecycle within the following day. When a URL cannot be issued (zero-data-retention via account settings, guardrails, `provider.zdr`, or a ZDR endpoint; no workspace; or storage failure), untimed requests fall back to streaming raw audio bytes (except on a storage failure for responses larger than 10 MiB, which returns an error), and timed requests fall back to inline base64 JSON (`{audio, media_type, words?, characters?}`) with no `url`.""" +r"""`stream` (default) streams the audio bytes directly in the response body (returns inline base64 JSON when `timestamp_granularities` is nonempty and `stream_format` is `\"audio\"`, or `text/event-stream` events when `stream_format` is `\"sse\"`). `url` stores the generated audio in OpenRouter storage and returns a JSON response with a signed download `url`, `expires_at`, and `media_type` (plus `words` and/or `characters` when `timestamp_granularities` is nonempty). The URL is a bearer link: anyone holding it can download the audio until it expires, up to 24 hours after the audio was stored (use `expires_at`); the stored copy is deleted by the storage lifecycle within the following day. When a URL cannot be issued (zero-data-retention via account settings, guardrails, `provider.zdr`, or a ZDR endpoint; no workspace; or storage failure), untimed requests fall back to streaming raw audio bytes (except on a storage failure for responses larger than 10 MiB, which returns an error), and timed requests fall back to inline base64 JSON (`{audio, media_type, words?, characters?}`) with no `url`.""" SpeechRequestDataCollection = Union[ @@ -175,6 +175,16 @@ def serialize_model(self, handler): r"""Audio output format. Defaults to `pcm`, or to `mp3` when `timestamp_granularities` is nonempty.""" +StreamFormat = Union[ + Literal[ + "audio", + "sse", + ], + UnrecognizedStr, +] +r"""Wire framing for inline responses. `audio` (default) returns raw audio bytes (or a buffered JSON envelope when `timestamp_granularities` is nonempty). `sse` streams `text/event-stream` events (`speech.audio.delta`, `speech.timestamps.delta` when `timestamp_granularities` is nonempty, `speech.audio.done`, and `error` on mid-stream failure) with the effective audio media type in `X-Audio-Media-Type`. Cannot be combined with `output_delivery: \"url\"`. Only routed to endpoints that advertise `sse` in `supported_parameters.stream_format` (and every requested granularity when `timestamp_granularities` is nonempty). Generated SDKs still type the 200 response as binary audio for compatibility; when using `stream_format: \"sse\"`, call the HTTP endpoint directly and parse `text/event-stream`.""" + + TimestampGranularity = Union[ Literal[ "word", @@ -196,7 +206,7 @@ class SpeechRequestTypedDict(TypedDict): instructions: NotRequired[str] r"""Delivery instructions for the whole request, such as tone, pacing, or emotion. For the selected endpoint in the [Speech Models API](https://openrouter.ai/docs/guides/overview/multimodal/tts#via-the-speech-models-api), look for `supported_parameters.instructions` in the `output_modalities` entry with `type: speech`.""" output_delivery: NotRequired[OutputDelivery] - r"""`stream` (default) streams the audio bytes directly in the response body (or returns inline base64 JSON when `timestamp_granularities` is nonempty). `url` stores the generated audio in OpenRouter storage and returns a JSON response with a signed download `url`, `expires_at`, and `media_type` (plus `words` and/or `characters` when `timestamp_granularities` is nonempty). The URL is a bearer link: anyone holding it can download the audio until it expires, up to 24 hours after the audio was stored (use `expires_at`); the stored copy is deleted by the storage lifecycle within the following day. When a URL cannot be issued (zero-data-retention via account settings, guardrails, `provider.zdr`, or a ZDR endpoint; no workspace; or storage failure), untimed requests fall back to streaming raw audio bytes (except on a storage failure for responses larger than 10 MiB, which returns an error), and timed requests fall back to inline base64 JSON (`{audio, media_type, words?, characters?}`) with no `url`.""" + r"""`stream` (default) streams the audio bytes directly in the response body (returns inline base64 JSON when `timestamp_granularities` is nonempty and `stream_format` is `\"audio\"`, or `text/event-stream` events when `stream_format` is `\"sse\"`). `url` stores the generated audio in OpenRouter storage and returns a JSON response with a signed download `url`, `expires_at`, and `media_type` (plus `words` and/or `characters` when `timestamp_granularities` is nonempty). The URL is a bearer link: anyone holding it can download the audio until it expires, up to 24 hours after the audio was stored (use `expires_at`); the stored copy is deleted by the storage lifecycle within the following day. When a URL cannot be issued (zero-data-retention via account settings, guardrails, `provider.zdr`, or a ZDR endpoint; no workspace; or storage failure), untimed requests fall back to streaming raw audio bytes (except on a storage failure for responses larger than 10 MiB, which returns an error), and timed requests fall back to inline base64 JSON (`{audio, media_type, words?, characters?}`) with no `url`.""" provider: NotRequired[SpeechRequestProviderTypedDict] r"""Provider configuration: provider routing preferences (`order`, `only`, `ignore`, `allow_fallbacks`), data policy routing preferences (`zdr`, `data_collection`) and provider-specific passthrough options""" response_format: NotRequired[SpeechRequestResponseFormat] @@ -205,8 +215,10 @@ class SpeechRequestTypedDict(TypedDict): r"""A unique identifier for grouping related requests (e.g., a conversation or agent workflow). Used for observability grouping in Broadcast and private logging; never sent to the provider. If provided in both the request body and the x-session-id header, the body value takes precedence. Maximum of 256 characters.""" speed: NotRequired[float] r"""Playback speed multiplier. Honored by models that support it (e.g. OpenAI TTS). Other providers either ignore it or return a 400 for a non-default value when the model has no speed control.""" + stream_format: NotRequired[StreamFormat] + r"""Wire framing for inline responses. `audio` (default) returns raw audio bytes (or a buffered JSON envelope when `timestamp_granularities` is nonempty). `sse` streams `text/event-stream` events (`speech.audio.delta`, `speech.timestamps.delta` when `timestamp_granularities` is nonempty, `speech.audio.done`, and `error` on mid-stream failure) with the effective audio media type in `X-Audio-Media-Type`. Cannot be combined with `output_delivery: \"url\"`. Only routed to endpoints that advertise `sse` in `supported_parameters.stream_format` (and every requested granularity when `timestamp_granularities` is nonempty). Generated SDKs still type the 200 response as binary audio for compatibility; when using `stream_format: \"sse\"`, call the HTTP endpoint directly and parse `text/event-stream`.""" timestamp_granularities: NotRequired[List[TimestampGranularity]] - r"""Timings to return with the audio. When nonempty, the response is JSON instead of raw audio bytes: `{audio, media_type, words?, characters?}` with base64 audio, or `{url, expires_at, media_type, words?, characters?}` when `output_delivery` is `url`. If a signed URL cannot be issued (ZDR, no workspace, or storage failure), timed `url` requests fall back to the inline `{audio, media_type, ...}` envelope with no `url`. The audio defaults to `mp3` unless `response_format` is set. Each timing entry is `{text, start, end}` in seconds. Only routed to endpoints that support every requested granularity (`supported_parameters.timestamp_granularities` on the speech models list). A timed response is sent once the whole audio is generated, not streamed, and is capped at 10 MiB of decoded audio for both inline and `url` delivery (the provider timed response, including its alignment data, is capped too); longer outputs return an error, so use a shorter input or a smaller audio format. Generated SDKs still type the 200 response as binary audio for compatibility; call the HTTP endpoint directly and parse the JSON response when using `timestamp_granularities`. An empty array is treated as no timings.""" + r"""Timings to return with the audio. With the default `stream_format: \"audio\"`, the response is buffered JSON instead of raw audio bytes: `{audio, media_type, words?, characters?}` with base64 audio, or `{url, expires_at, media_type, words?, characters?}` when `output_delivery` is `url`. If a signed URL cannot be issued (ZDR, no workspace, or storage failure), timed `url` requests fall back to the inline `{audio, media_type, ...}` envelope with no `url`. Buffered timed responses are sent once the whole audio is generated and are capped at 10 MiB of decoded audio (the provider timed response, including its alignment data, is capped too); longer outputs return an error, so use a shorter input, a smaller audio format, or `stream_format: \"sse\"`. With `stream_format: \"sse\"`, the response is `text/event-stream` (`speech.audio.delta`, `speech.timestamps.delta`, `speech.audio.done`, and `error` on mid-stream failure) with the effective audio media type in `X-Audio-Media-Type` and no 10 MiB cap. The audio defaults to `mp3` unless `response_format` is set. Each timing entry is `{text, start, end}` in seconds. Only routed to endpoints that support every requested granularity for the requested `stream_format`. Generated SDKs still type the 200 response as binary audio for compatibility; call the HTTP endpoint directly and parse JSON (for `stream_format: \"audio\"`) or `text/event-stream` (for `stream_format: \"sse\"`). An empty array is treated as no timings.""" trace: NotRequired[TraceConfigTypedDict] r"""Metadata for observability and tracing. Known keys (trace_id, trace_name, span_name, generation_name, parent_span_id) have special handling. Additional keys are passed through as custom metadata to configured broadcast destinations.""" user: NotRequired[str] @@ -231,7 +243,7 @@ class SpeechRequest(BaseModel): r"""Delivery instructions for the whole request, such as tone, pacing, or emotion. For the selected endpoint in the [Speech Models API](https://openrouter.ai/docs/guides/overview/multimodal/tts#via-the-speech-models-api), look for `supported_parameters.instructions` in the `output_modalities` entry with `type: speech`.""" output_delivery: Optional[OutputDelivery] = None - r"""`stream` (default) streams the audio bytes directly in the response body (or returns inline base64 JSON when `timestamp_granularities` is nonempty). `url` stores the generated audio in OpenRouter storage and returns a JSON response with a signed download `url`, `expires_at`, and `media_type` (plus `words` and/or `characters` when `timestamp_granularities` is nonempty). The URL is a bearer link: anyone holding it can download the audio until it expires, up to 24 hours after the audio was stored (use `expires_at`); the stored copy is deleted by the storage lifecycle within the following day. When a URL cannot be issued (zero-data-retention via account settings, guardrails, `provider.zdr`, or a ZDR endpoint; no workspace; or storage failure), untimed requests fall back to streaming raw audio bytes (except on a storage failure for responses larger than 10 MiB, which returns an error), and timed requests fall back to inline base64 JSON (`{audio, media_type, words?, characters?}`) with no `url`.""" + r"""`stream` (default) streams the audio bytes directly in the response body (returns inline base64 JSON when `timestamp_granularities` is nonempty and `stream_format` is `\"audio\"`, or `text/event-stream` events when `stream_format` is `\"sse\"`). `url` stores the generated audio in OpenRouter storage and returns a JSON response with a signed download `url`, `expires_at`, and `media_type` (plus `words` and/or `characters` when `timestamp_granularities` is nonempty). The URL is a bearer link: anyone holding it can download the audio until it expires, up to 24 hours after the audio was stored (use `expires_at`); the stored copy is deleted by the storage lifecycle within the following day. When a URL cannot be issued (zero-data-retention via account settings, guardrails, `provider.zdr`, or a ZDR endpoint; no workspace; or storage failure), untimed requests fall back to streaming raw audio bytes (except on a storage failure for responses larger than 10 MiB, which returns an error), and timed requests fall back to inline base64 JSON (`{audio, media_type, words?, characters?}`) with no `url`.""" provider: Optional[SpeechRequestProvider] = None r"""Provider configuration: provider routing preferences (`order`, `only`, `ignore`, `allow_fallbacks`), data policy routing preferences (`zdr`, `data_collection`) and provider-specific passthrough options""" @@ -245,8 +257,11 @@ class SpeechRequest(BaseModel): speed: Optional[float] = None r"""Playback speed multiplier. Honored by models that support it (e.g. OpenAI TTS). Other providers either ignore it or return a 400 for a non-default value when the model has no speed control.""" + stream_format: Optional[StreamFormat] = None + r"""Wire framing for inline responses. `audio` (default) returns raw audio bytes (or a buffered JSON envelope when `timestamp_granularities` is nonempty). `sse` streams `text/event-stream` events (`speech.audio.delta`, `speech.timestamps.delta` when `timestamp_granularities` is nonempty, `speech.audio.done`, and `error` on mid-stream failure) with the effective audio media type in `X-Audio-Media-Type`. Cannot be combined with `output_delivery: \"url\"`. Only routed to endpoints that advertise `sse` in `supported_parameters.stream_format` (and every requested granularity when `timestamp_granularities` is nonempty). Generated SDKs still type the 200 response as binary audio for compatibility; when using `stream_format: \"sse\"`, call the HTTP endpoint directly and parse `text/event-stream`.""" + timestamp_granularities: Optional[List[TimestampGranularity]] = None - r"""Timings to return with the audio. When nonempty, the response is JSON instead of raw audio bytes: `{audio, media_type, words?, characters?}` with base64 audio, or `{url, expires_at, media_type, words?, characters?}` when `output_delivery` is `url`. If a signed URL cannot be issued (ZDR, no workspace, or storage failure), timed `url` requests fall back to the inline `{audio, media_type, ...}` envelope with no `url`. The audio defaults to `mp3` unless `response_format` is set. Each timing entry is `{text, start, end}` in seconds. Only routed to endpoints that support every requested granularity (`supported_parameters.timestamp_granularities` on the speech models list). A timed response is sent once the whole audio is generated, not streamed, and is capped at 10 MiB of decoded audio for both inline and `url` delivery (the provider timed response, including its alignment data, is capped too); longer outputs return an error, so use a shorter input or a smaller audio format. Generated SDKs still type the 200 response as binary audio for compatibility; call the HTTP endpoint directly and parse the JSON response when using `timestamp_granularities`. An empty array is treated as no timings.""" + r"""Timings to return with the audio. With the default `stream_format: \"audio\"`, the response is buffered JSON instead of raw audio bytes: `{audio, media_type, words?, characters?}` with base64 audio, or `{url, expires_at, media_type, words?, characters?}` when `output_delivery` is `url`. If a signed URL cannot be issued (ZDR, no workspace, or storage failure), timed `url` requests fall back to the inline `{audio, media_type, ...}` envelope with no `url`. Buffered timed responses are sent once the whole audio is generated and are capped at 10 MiB of decoded audio (the provider timed response, including its alignment data, is capped too); longer outputs return an error, so use a shorter input, a smaller audio format, or `stream_format: \"sse\"`. With `stream_format: \"sse\"`, the response is `text/event-stream` (`speech.audio.delta`, `speech.timestamps.delta`, `speech.audio.done`, and `error` on mid-stream failure) with the effective audio media type in `X-Audio-Media-Type` and no 10 MiB cap. The audio defaults to `mp3` unless `response_format` is set. Each timing entry is `{text, start, end}` in seconds. Only routed to endpoints that support every requested granularity for the requested `stream_format`. Generated SDKs still type the 200 response as binary audio for compatibility; call the HTTP endpoint directly and parse JSON (for `stream_format: \"audio\"`) or `text/event-stream` (for `stream_format: \"sse\"`). An empty array is treated as no timings.""" trace: Optional[TraceConfig] = None r"""Metadata for observability and tracing. Known keys (trace_id, trace_name, span_name, generation_name, parent_span_id) have special handling. Additional keys are passed through as custom metadata to configured broadcast destinations.""" @@ -268,6 +283,7 @@ def serialize_model(self, handler): "response_format", "session_id", "speed", + "stream_format", "timestamp_granularities", "trace", "user", diff --git a/src/openrouter/components/speechsupportedparameters.py b/src/openrouter/components/speechsupportedparameters.py index bea7e353..c99fcc56 100644 --- a/src/openrouter/components/speechsupportedparameters.py +++ b/src/openrouter/components/speechsupportedparameters.py @@ -19,6 +19,7 @@ class SpeechSupportedParametersTypedDict(TypedDict): response_format: NotRequired[SpeechEnumParameterTypedDict] speed: NotRequired[SpeechRangeParameterTypedDict] r"""The accepted `speed` range. Absent: the provider documents no range; some providers still forward `speed`.""" + stream_format: NotRequired[SpeechEnumParameterTypedDict] timestamp_granularities: NotRequired[SpeechEnumParameterTypedDict] voice: NotRequired[SpeechVoiceParameterTypedDict] r"""`enum` lists the documented voices in `values`; some providers also accept voice IDs not listed there (custom or cloned voices). `unknown` means the field is accepted but no voices are listed.""" @@ -32,6 +33,8 @@ class SpeechSupportedParameters(BaseModel): speed: Optional[SpeechRangeParameter] = None r"""The accepted `speed` range. Absent: the provider documents no range; some providers still forward `speed`.""" + stream_format: Optional[SpeechEnumParameter] = None + timestamp_granularities: Optional[SpeechEnumParameter] = None voice: Optional[SpeechVoiceParameter] = None @@ -44,6 +47,7 @@ def serialize_model(self, handler): "instructions", "response_format", "speed", + "stream_format", "timestamp_granularities", "voice", ] diff --git a/src/openrouter/tts.py b/src/openrouter/tts.py index d88e0167..3fc05547 100644 --- a/src/openrouter/tts.py +++ b/src/openrouter/tts.py @@ -38,6 +38,7 @@ def create_speech( response_format: Optional[components.SpeechRequestResponseFormat] = None, session_id: Optional[str] = None, speed: Optional[float] = None, + stream_format: Optional[components.StreamFormat] = None, timestamp_granularities: Optional[ Iterable[components.TimestampGranularity] ] = None, @@ -66,12 +67,13 @@ def create_speech( :param input_references: Reference content for stateless voice cloning or voice design. Audio mode: one to three `input_audio` parts, each optionally paired with a `text` part carrying its transcript (a single clip accepts its transcript before or after it; with multiple clips each transcript immediately follows its clip), plus at most one `image_url` part as a scene image on providers that condition the cloned voice on its setting; only routed to endpoints that support voice cloning (and multiple references or image references when those parts are sent). Image mode: exactly one `image_url` part; only routed to endpoints that support image references. Video mode: exactly one `video_url` part with a public http(s) URL, optionally with one to three `input_audio` parts (and their `text` transcripts) grouped as in audio mode, and no `image_url` part; Seed Audio 1.5 ignores those transcripts, so the words the voices speak go in `input`; only routed to endpoints that support video references (and voice cloning when clips are sent, plus multiple references for two or three clips). An empty array is treated as no reference. :param instructions: Delivery instructions for the whole request, such as tone, pacing, or emotion. For the selected endpoint in the [Speech Models API](https://openrouter.ai/docs/guides/overview/multimodal/tts#via-the-speech-models-api), look for `supported_parameters.instructions` in the `output_modalities` entry with `type: speech`. - :param output_delivery: `stream` (default) streams the audio bytes directly in the response body (or returns inline base64 JSON when `timestamp_granularities` is nonempty). `url` stores the generated audio in OpenRouter storage and returns a JSON response with a signed download `url`, `expires_at`, and `media_type` (plus `words` and/or `characters` when `timestamp_granularities` is nonempty). The URL is a bearer link: anyone holding it can download the audio until it expires, up to 24 hours after the audio was stored (use `expires_at`); the stored copy is deleted by the storage lifecycle within the following day. When a URL cannot be issued (zero-data-retention via account settings, guardrails, `provider.zdr`, or a ZDR endpoint; no workspace; or storage failure), untimed requests fall back to streaming raw audio bytes (except on a storage failure for responses larger than 10 MiB, which returns an error), and timed requests fall back to inline base64 JSON (`{audio, media_type, words?, characters?}`) with no `url`. + :param output_delivery: `stream` (default) streams the audio bytes directly in the response body (returns inline base64 JSON when `timestamp_granularities` is nonempty and `stream_format` is `\"audio\"`, or `text/event-stream` events when `stream_format` is `\"sse\"`). `url` stores the generated audio in OpenRouter storage and returns a JSON response with a signed download `url`, `expires_at`, and `media_type` (plus `words` and/or `characters` when `timestamp_granularities` is nonempty). The URL is a bearer link: anyone holding it can download the audio until it expires, up to 24 hours after the audio was stored (use `expires_at`); the stored copy is deleted by the storage lifecycle within the following day. When a URL cannot be issued (zero-data-retention via account settings, guardrails, `provider.zdr`, or a ZDR endpoint; no workspace; or storage failure), untimed requests fall back to streaming raw audio bytes (except on a storage failure for responses larger than 10 MiB, which returns an error), and timed requests fall back to inline base64 JSON (`{audio, media_type, words?, characters?}`) with no `url`. :param provider: Provider configuration: provider routing preferences (`order`, `only`, `ignore`, `allow_fallbacks`), data policy routing preferences (`zdr`, `data_collection`) and provider-specific passthrough options :param response_format: Audio output format. Defaults to `pcm`, or to `mp3` when `timestamp_granularities` is nonempty. :param session_id: A unique identifier for grouping related requests (e.g., a conversation or agent workflow). Used for observability grouping in Broadcast and private logging; never sent to the provider. If provided in both the request body and the x-session-id header, the body value takes precedence. Maximum of 256 characters. :param speed: Playback speed multiplier. Honored by models that support it (e.g. OpenAI TTS). Other providers either ignore it or return a 400 for a non-default value when the model has no speed control. - :param timestamp_granularities: Timings to return with the audio. When nonempty, the response is JSON instead of raw audio bytes: `{audio, media_type, words?, characters?}` with base64 audio, or `{url, expires_at, media_type, words?, characters?}` when `output_delivery` is `url`. If a signed URL cannot be issued (ZDR, no workspace, or storage failure), timed `url` requests fall back to the inline `{audio, media_type, ...}` envelope with no `url`. The audio defaults to `mp3` unless `response_format` is set. Each timing entry is `{text, start, end}` in seconds. Only routed to endpoints that support every requested granularity (`supported_parameters.timestamp_granularities` on the speech models list). A timed response is sent once the whole audio is generated, not streamed, and is capped at 10 MiB of decoded audio for both inline and `url` delivery (the provider timed response, including its alignment data, is capped too); longer outputs return an error, so use a shorter input or a smaller audio format. Generated SDKs still type the 200 response as binary audio for compatibility; call the HTTP endpoint directly and parse the JSON response when using `timestamp_granularities`. An empty array is treated as no timings. + :param stream_format: Wire framing for inline responses. `audio` (default) returns raw audio bytes (or a buffered JSON envelope when `timestamp_granularities` is nonempty). `sse` streams `text/event-stream` events (`speech.audio.delta`, `speech.timestamps.delta` when `timestamp_granularities` is nonempty, `speech.audio.done`, and `error` on mid-stream failure) with the effective audio media type in `X-Audio-Media-Type`. Cannot be combined with `output_delivery: \"url\"`. Only routed to endpoints that advertise `sse` in `supported_parameters.stream_format` (and every requested granularity when `timestamp_granularities` is nonempty). Generated SDKs still type the 200 response as binary audio for compatibility; when using `stream_format: \"sse\"`, call the HTTP endpoint directly and parse `text/event-stream`. + :param timestamp_granularities: Timings to return with the audio. With the default `stream_format: \"audio\"`, the response is buffered JSON instead of raw audio bytes: `{audio, media_type, words?, characters?}` with base64 audio, or `{url, expires_at, media_type, words?, characters?}` when `output_delivery` is `url`. If a signed URL cannot be issued (ZDR, no workspace, or storage failure), timed `url` requests fall back to the inline `{audio, media_type, ...}` envelope with no `url`. Buffered timed responses are sent once the whole audio is generated and are capped at 10 MiB of decoded audio (the provider timed response, including its alignment data, is capped too); longer outputs return an error, so use a shorter input, a smaller audio format, or `stream_format: \"sse\"`. With `stream_format: \"sse\"`, the response is `text/event-stream` (`speech.audio.delta`, `speech.timestamps.delta`, `speech.audio.done`, and `error` on mid-stream failure) with the effective audio media type in `X-Audio-Media-Type` and no 10 MiB cap. The audio defaults to `mp3` unless `response_format` is set. Each timing entry is `{text, start, end}` in seconds. Only routed to endpoints that support every requested granularity for the requested `stream_format`. Generated SDKs still type the 200 response as binary audio for compatibility; call the HTTP endpoint directly and parse JSON (for `stream_format: \"audio\"`) or `text/event-stream` (for `stream_format: \"sse\"`). An empty array is treated as no timings. :param trace: Metadata for observability and tracing. Known keys (trace_id, trace_name, span_name, generation_name, parent_span_id) have special handling. Additional keys are passed through as custom metadata to configured broadcast destinations. :param user: A unique identifier representing your end-user. Forwarded to Broadcast and private logging as the end-user id; never sent to the provider. :param voice: Voice identifier (provider-specific). Required by most providers; only Seed Audio, HeyGen, Fish Audio, AssemblyAI, Speechify accept requests without it. @@ -108,6 +110,7 @@ def create_speech( response_format=response_format, session_id=session_id, speed=speed, + stream_format=stream_format, timestamp_granularities=utils.unmarshal( timestamp_granularities, Optional[List[components.TimestampGranularity]], @@ -313,6 +316,7 @@ async def create_speech_async( response_format: Optional[components.SpeechRequestResponseFormat] = None, session_id: Optional[str] = None, speed: Optional[float] = None, + stream_format: Optional[components.StreamFormat] = None, timestamp_granularities: Optional[ Iterable[components.TimestampGranularity] ] = None, @@ -341,12 +345,13 @@ async def create_speech_async( :param input_references: Reference content for stateless voice cloning or voice design. Audio mode: one to three `input_audio` parts, each optionally paired with a `text` part carrying its transcript (a single clip accepts its transcript before or after it; with multiple clips each transcript immediately follows its clip), plus at most one `image_url` part as a scene image on providers that condition the cloned voice on its setting; only routed to endpoints that support voice cloning (and multiple references or image references when those parts are sent). Image mode: exactly one `image_url` part; only routed to endpoints that support image references. Video mode: exactly one `video_url` part with a public http(s) URL, optionally with one to three `input_audio` parts (and their `text` transcripts) grouped as in audio mode, and no `image_url` part; Seed Audio 1.5 ignores those transcripts, so the words the voices speak go in `input`; only routed to endpoints that support video references (and voice cloning when clips are sent, plus multiple references for two or three clips). An empty array is treated as no reference. :param instructions: Delivery instructions for the whole request, such as tone, pacing, or emotion. For the selected endpoint in the [Speech Models API](https://openrouter.ai/docs/guides/overview/multimodal/tts#via-the-speech-models-api), look for `supported_parameters.instructions` in the `output_modalities` entry with `type: speech`. - :param output_delivery: `stream` (default) streams the audio bytes directly in the response body (or returns inline base64 JSON when `timestamp_granularities` is nonempty). `url` stores the generated audio in OpenRouter storage and returns a JSON response with a signed download `url`, `expires_at`, and `media_type` (plus `words` and/or `characters` when `timestamp_granularities` is nonempty). The URL is a bearer link: anyone holding it can download the audio until it expires, up to 24 hours after the audio was stored (use `expires_at`); the stored copy is deleted by the storage lifecycle within the following day. When a URL cannot be issued (zero-data-retention via account settings, guardrails, `provider.zdr`, or a ZDR endpoint; no workspace; or storage failure), untimed requests fall back to streaming raw audio bytes (except on a storage failure for responses larger than 10 MiB, which returns an error), and timed requests fall back to inline base64 JSON (`{audio, media_type, words?, characters?}`) with no `url`. + :param output_delivery: `stream` (default) streams the audio bytes directly in the response body (returns inline base64 JSON when `timestamp_granularities` is nonempty and `stream_format` is `\"audio\"`, or `text/event-stream` events when `stream_format` is `\"sse\"`). `url` stores the generated audio in OpenRouter storage and returns a JSON response with a signed download `url`, `expires_at`, and `media_type` (plus `words` and/or `characters` when `timestamp_granularities` is nonempty). The URL is a bearer link: anyone holding it can download the audio until it expires, up to 24 hours after the audio was stored (use `expires_at`); the stored copy is deleted by the storage lifecycle within the following day. When a URL cannot be issued (zero-data-retention via account settings, guardrails, `provider.zdr`, or a ZDR endpoint; no workspace; or storage failure), untimed requests fall back to streaming raw audio bytes (except on a storage failure for responses larger than 10 MiB, which returns an error), and timed requests fall back to inline base64 JSON (`{audio, media_type, words?, characters?}`) with no `url`. :param provider: Provider configuration: provider routing preferences (`order`, `only`, `ignore`, `allow_fallbacks`), data policy routing preferences (`zdr`, `data_collection`) and provider-specific passthrough options :param response_format: Audio output format. Defaults to `pcm`, or to `mp3` when `timestamp_granularities` is nonempty. :param session_id: A unique identifier for grouping related requests (e.g., a conversation or agent workflow). Used for observability grouping in Broadcast and private logging; never sent to the provider. If provided in both the request body and the x-session-id header, the body value takes precedence. Maximum of 256 characters. :param speed: Playback speed multiplier. Honored by models that support it (e.g. OpenAI TTS). Other providers either ignore it or return a 400 for a non-default value when the model has no speed control. - :param timestamp_granularities: Timings to return with the audio. When nonempty, the response is JSON instead of raw audio bytes: `{audio, media_type, words?, characters?}` with base64 audio, or `{url, expires_at, media_type, words?, characters?}` when `output_delivery` is `url`. If a signed URL cannot be issued (ZDR, no workspace, or storage failure), timed `url` requests fall back to the inline `{audio, media_type, ...}` envelope with no `url`. The audio defaults to `mp3` unless `response_format` is set. Each timing entry is `{text, start, end}` in seconds. Only routed to endpoints that support every requested granularity (`supported_parameters.timestamp_granularities` on the speech models list). A timed response is sent once the whole audio is generated, not streamed, and is capped at 10 MiB of decoded audio for both inline and `url` delivery (the provider timed response, including its alignment data, is capped too); longer outputs return an error, so use a shorter input or a smaller audio format. Generated SDKs still type the 200 response as binary audio for compatibility; call the HTTP endpoint directly and parse the JSON response when using `timestamp_granularities`. An empty array is treated as no timings. + :param stream_format: Wire framing for inline responses. `audio` (default) returns raw audio bytes (or a buffered JSON envelope when `timestamp_granularities` is nonempty). `sse` streams `text/event-stream` events (`speech.audio.delta`, `speech.timestamps.delta` when `timestamp_granularities` is nonempty, `speech.audio.done`, and `error` on mid-stream failure) with the effective audio media type in `X-Audio-Media-Type`. Cannot be combined with `output_delivery: \"url\"`. Only routed to endpoints that advertise `sse` in `supported_parameters.stream_format` (and every requested granularity when `timestamp_granularities` is nonempty). Generated SDKs still type the 200 response as binary audio for compatibility; when using `stream_format: \"sse\"`, call the HTTP endpoint directly and parse `text/event-stream`. + :param timestamp_granularities: Timings to return with the audio. With the default `stream_format: \"audio\"`, the response is buffered JSON instead of raw audio bytes: `{audio, media_type, words?, characters?}` with base64 audio, or `{url, expires_at, media_type, words?, characters?}` when `output_delivery` is `url`. If a signed URL cannot be issued (ZDR, no workspace, or storage failure), timed `url` requests fall back to the inline `{audio, media_type, ...}` envelope with no `url`. Buffered timed responses are sent once the whole audio is generated and are capped at 10 MiB of decoded audio (the provider timed response, including its alignment data, is capped too); longer outputs return an error, so use a shorter input, a smaller audio format, or `stream_format: \"sse\"`. With `stream_format: \"sse\"`, the response is `text/event-stream` (`speech.audio.delta`, `speech.timestamps.delta`, `speech.audio.done`, and `error` on mid-stream failure) with the effective audio media type in `X-Audio-Media-Type` and no 10 MiB cap. The audio defaults to `mp3` unless `response_format` is set. Each timing entry is `{text, start, end}` in seconds. Only routed to endpoints that support every requested granularity for the requested `stream_format`. Generated SDKs still type the 200 response as binary audio for compatibility; call the HTTP endpoint directly and parse JSON (for `stream_format: \"audio\"`) or `text/event-stream` (for `stream_format: \"sse\"`). An empty array is treated as no timings. :param trace: Metadata for observability and tracing. Known keys (trace_id, trace_name, span_name, generation_name, parent_span_id) have special handling. Additional keys are passed through as custom metadata to configured broadcast destinations. :param user: A unique identifier representing your end-user. Forwarded to Broadcast and private logging as the end-user id; never sent to the provider. :param voice: Voice identifier (provider-specific). Required by most providers; only Seed Audio, HeyGen, Fish Audio, AssemblyAI, Speechify accept requests without it. @@ -383,6 +388,7 @@ async def create_speech_async( response_format=response_format, session_id=session_id, speed=speed, + stream_format=stream_format, timestamp_granularities=utils.unmarshal( timestamp_granularities, Optional[List[components.TimestampGranularity]], diff --git a/uv.lock b/uv.lock index 6ceccec0..6794d03a 100644 --- a/uv.lock +++ b/uv.lock @@ -231,7 +231,7 @@ wheels = [ [[package]] name = "openrouter" -version = "1.3.245" +version = "1.3.246" source = { editable = "." } dependencies = [ { name = "httpcore" },