1617 words
8 minutes

One API for Multiple TTS Providers: OpenAI Standard Parameter Mapping (MOSS Example)

One API for Multiple TTS Providers: OpenAI Standard Parameter Mapping (MOSS Example)

For the past two months of doing short-video voiceovers, I've used Edge TTS, ChatTTS, Gemini TTS and MOSS. Every provider's interface is different: some call it voice, others call it voice_id; some return the audio directly, others return a download URL; some let you adjust the speaking rate, others don't have that parameter at all. Every time I switch providers in a script I have to rewrite the request code — really annoying.

Later I just added a /v1/audio/speech to my own AI relay station: the client always sends requests in OpenAI's standard format, and all the differences are handled by the gateway's "parameter mapping". This post documents how I did it, using MOSS as the example.

1. The Origin: Same Path, Different Field Names

The first time I got MOSS's endpoint URL, my first reaction was "same as OpenAI" — both are POST /v1/audio/speech. But looking closer at the docs, the voice field isn't called voice, it's called voice_id, and it's required.

At the time the relay station only passed through the image generation endpoint (/v1/images/generations), with no speech channel. I had two options:

  1. Write a separate forwarding piece of code for MOSS;
  2. Have the gateway uniformly accept the OpenAI format, and each provider configures a "field renaming table" in the console.

I chose the second. Providers on the standard interface don't need to fill in anything; for MOSS I only fill in one line, voice → voice_id. When I connect other providers later, it'll most likely just mean filling in a few more lines, with no code changes. As for the actual implementation, I settled on the approach and handed it to Codex to write; after it went live I checked it over myself.

2. Parameter Comparison Between OpenAI and MOSS

The table below was checked item by item against both official docs (sources: OpenAI Create speech, MOSS single-speaker speech generation, consulted 2026-11-16):

OpenAI field MOSS field Notes
model model MOSS optionally supports moss-tts-1.5-flash, moss-tts-1.0-pro and their snapshot versions
input input OpenAI caps at 4096 characters; MOSS's 1.5-flash supports pause markers like [pause 0.8s], while 1.0-pro does not
voice voice_id The only field that must be mapped. OpenAI uses built-in names like alloy, nova, or the { "id": ... } object; MOSS only accepts voice ID strings
response_format response_format Both support mp3 / opus / aac / flac / wav / pcm; MOSS streaming must use pcm
stream_format stream_format Both have audio / sse; MOSS also requires passing stream: true at the same time
speed None OpenAI supports 0.25–4.0; MOSS docs have no speaking-rate parameter
instructions None OpenAI uses it to control tone (not supported by the tts-1 series); MOSS's single-speaker endpoint has no corresponding field
None language Exclusive to MOSS 1.5-flash; must be written as the full English name, e.g. Chinese, and does not accept zh
None delivery_method MOSS-exclusive: audio returns binary directly, url returns JSON and a download URL
None expected_duration_sec, async, webhook_url MOSS-exclusive: expected duration and async tasks

III. How the Gateway Does the Mapping

The core logic is just one function: rename fields in the request body according to the mapping table configured for the provider. I've simplified the actual code:

provider-mapping.js (simplified)
function mapRequestParameters(body, provider) {
const mapping = provider?.parameterMapping || {};
if (!Object.keys(mapping).length) return body; // Standard providers: forward as-is
const result = { ...body };
for (const [from, to] of Object.entries(mapping)) {
if (!(from in result)) continue;
// If the client has explicitly passed an upstream native field (e.g. voice_id), use that value.
if (!(to in result)) result[to] = result[from];
delete result[from];
}
return result;
}

The real version also supports dotted paths like reasoning.effort; that's omitted here. There are a few other rules I added after running into problems:

  • Native fields take priority. If the client passes voice_id directly, the mapping won't overwrite it. That way people familiar with MOSS can still use the native syntax.
  • model and stream are not allowed in parameter mapping. Model name rewriting goes through a separate "model mapping" so routing fields don't get scrambled.
  • Mappings can't be nested or chained (e.g. a→b, b→c), and each provider can have at most 40 entries.
  • The default voice is only supplied for single-speaker speech. When the request has neither voice nor voice_id, the gateway adds the default voice set in the console; multi-speaker conversations and the voice design endpoint won't have a default forced on them.

When forwarding, the gateway skips the proxy used by the chat endpoint and finds the provider directly by model, passing the audio stream back to the client as-is without transcoding. If the client disconnects midway, the gateway cancels the upstream download.

IV. Call Examples

The client follows OpenAI's syntax entirely and doesn't need to know the upstream is MOSS:

curl
curl https://api.example.com/v1/audio/speech \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "moss-tts-1.5-flash",
"input": "This is a speech API test.",
"voice": "94aa4989-c7e9-5007-ae42-ab401823e6c9",
"response_format": "mp3"
}' \
--output test.mp3

voice is filled with the voice ID from the MOSS account (the one above is the example ID from MOSS's official docs), and the gateway rewrites it to voice_id before forwarding. Omit voice and the default voice is used.

The same goes for the official OpenAI Python SDK; just change base_url (this snippet follows the SDK's official usage; I haven't run it separately on the gateway):

tts_demo.py
from openai import OpenAI
client = OpenAI(base_url="https://api.example.com/v1", api_key="YOUR_API_KEY")
with client.audio.speech.with_streaming_response.create(
model="moss-tts-1.5-flash",
input="This is a speech API test.",
voice="YOUR_VOICE_ID",
response_format="mp3",
) as resp:
resp.stream_to_file("test.mp3")

After launch I checked the request log: all 3 speech requests returned 200, and transcription and image generation worked normally too.

V. Pitfalls I Hit

1. Not every model name in the docs can actually be called. MOSS's catalog lists moss-speech and moss-speech-enhance, but sending them to the speech endpoint returns "model does not exist." I didn't delete them; I just marked them in the console as "upstream temporarily unavailable," so I won't have to re-add them if the official side enables them later.

2. What to do without speed.** The gateway doesn't simulate speed on MOSS's behalf; speed is passed through as-is. When I make video narration, I get the mp3 and adjust it myself with ffmpeg:

Command used in build_audio.py
ffmpeg -y -i m0.mp3 -af atempo=1.06 -ar 48000 -ac 1 a0.wav

The narration for episode 1 of the tutorial uses 1.06x. atempo only changes speed, not pitch.

3. Upstream errors may bring the Key back with them. The gateway passes the upstream error body to the client as-is, so before forwarding it must replace any upstream Key appearing in it with "[hidden]," and truncate error bodies over 64 KB. This has its own test coverage.

4. When there's no usage info, write the cost as "unknown" rather than 0. Binary audio responses contain no usage. The gateway estimates a reference cost by Unicode character count, but the actual charge is based on the MOSS credit bill; if it can't get that, it shows "cost unavailable" instead of treating it as free. The MOSS model page currently states that both moss-tts-1.5-flash and 1.0-pro are ¥1.20 per 10,000 characters (marked as a 60% discount); prices change, so refer to the official page.

5. Speech parameter errors shouldn't drag down chat models. My relay has a mechanism that automatically takes a model offline after too many errors. Bad speech request parameters are the caller's fault, so these errors are excluded and won't trigger delisting.

6. delivery_method: url doesn't return audio. In my script that connects directly to MOSS, I use url mode, which returns JSON, requiring another download. Through the gateway, the gateway doesn't rewrite this JSON, so the client has to check content-type itself.

6. Who It's For and What's Still Missing

Who it's for: people who have several TTS providers on hand and want to call them all with the same OpenAI SDK; or people building a relay service who want to add a voice channel at low cost.

What's not done yet:

  • OpenAI's voice can also accept a { "id": "..." } object. I haven't tested how this form maps to MOSS, so I recommend passing a string ID directly.
  • speed and instructions have not been converted across providers.
  • MOSS's voice creation and cloning are outside the scope of this integration; the voice list only supports reading (GET /v1/audio/voices).

If you only use one TTS provider, calling the official API directly is simpler. The value of parameter mapping lies in "switching providers without changing client code"—the more providers you connect, the more worthwhile it is.

Share Article

If this article helped you, please share it with others!

One API for Multiple TTS Providers: OpenAI Standard Parameter Mapping (MOSS Example)
https://codqor.com/posts/openai-tts-api-mapping-moss/
Author
Liam
Published at
Related PostsSmart
1
My 256MB Router Can’t Run OpenClash, So I Built TinyLane and Open-Sourced It
TechThe Xiaomi AX3000T has only 256 MB of RAM, making OpenClash too much of a strain, so I packaged the sing-box core, a Go daemon, and a mobile panel into a single binary called TinyLane, with my daily readings at about 35 MB for the core and 20–28 MB for the panel. This article explains why I wrote it, what it can do, the memory pitfalls I hit, and how to install it; the project is open-sourced under GPL-3.0.
2
Self-Hosting an Astro Blog: Pitfalls with R2 Image Hosting, D1, Caddy, and SEO
Techcodqor.com is itself an Astro static blog: posts are stored in Cloudflare D1, images in R2, pages are served from its own server via Caddy, comments use Turnstile, and there is an English mirror. This article records the build process and pitfalls in real chronological order, including overly long Bing titles, missed noindex directives, a build machine being cooled down, and the remediation approach after AdSense rejected the site for "low-value content."
3
Resend Email Sending from 0 to Launch: Domain Verification, Sending Relay, and Bounce Monitoring
TechA complete record of moving server notification emails from QQ Mail SMTP to Resend: choosing a new account and domain, DKIM/SPF/DMARC on Cloudflare, a sending API where only one relay holds the key, the gotchas that quota resets at UTC and receiving also consumes quota, Bark alerts for bounces, and protection against duplicate sends. Together with the previous post on Cloudflare receiving, it covers both sending and receiving.
4
Xiaomi AX3000T Follow-up: OpenClash Primary/Backup Routing, WireGuard Coexistence, and Lag Troubleshooting
TechTwo weeks after flashing OpenWrt on the AX3000T: switching routing from HomeProxy to OpenClash (Meta core) with primary/backup lines, running WireGuard remote management alongside OpenClash, and tracing cross-ocean link lag from 41 KB/s to 7–8 MB/s.
5
Building a WeChat Mini Game with AI in Two Days: From Topic Selection to Submission and the Filing Rejection Pitfalls
TechFor the individually operated, ad-only single-player WeChat Mini Game Eat Up, Big Fat Fish, AI collaboration was used from topic selection through submission: original characters, a web demo, a 30-level official release, account-type pitfalls, privacy guidelines, and correcting the Filing item by item against the official text after it was rejected over the Age Rating Notice.
Random PostsRandom

Comments

Leave a comment

Share your thoughts

Shown after review
Leave the name empty to post as “Anonymous”0 / 3000

Comments

Newest first · 5 at a time

Loading comments…

Profile Image of the Author
Liam
Notes on tech, life, and thoughts.
Categories
Tags
Latest Moments
Site Statistics
Posts
21
Categories
4
Tags
72
Total Words
87,292
Running Days
0 days
Last Activity
0 days ago
Table of Contents