Use the OpenAI SDK with Paxa

POST /v1/audio/speech and POST /v1/audio/transcriptions replace OpenAI's speech and transcription endpoints: point the SDK at Paxa and calls work unchanged.

View as Markdown

The Paxa API serves the OpenAI audio.speech request shape at POST /v1/audio/speech. Set the SDK's base URL to https://api.paxalabs.com/v1 and authenticate with a Paxa API key. Existing audio.speech.create calls then work unchanged. Pricing, headers, and error codes match POST /v1/tts. The transcription endpoint is served the same way.

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.paxalabs.com/v1",
    api_key=os.environ["PAXA_API_KEY"],
)

with client.audio.speech.with_streaming_response.create(
    model="paxa-tts-flash-v2",
    voice="khanomkrok",
    input="สวัสดีครับ ยินดีต้อนรับสู่ Paxa Labs",
) as response:
    response.stream_to_file("speech.mp3")

Field mapping#

FieldBehavior
modelRequired, same as on /v1/tts. A Paxa model id, for example paxa-tts-flash-v2. OpenAI's tts-1, tts-1-hd, gpt-4o-mini-tts, gpt-4o-mini-tts-2025-03-20, gpt-4o-mini-tts-2025-12-15 also work and run on paxa-tts-flash-v2.
inputThe text to synthesize. Same limits, pricing, direction tags, and emotion tags on paxa-tts-flash-v1 as text on /v1/tts.
voiceThe voice id from GET /v1/voices, for example "khanomkrok"; case is ignored, as for voice on /v1/tts. This endpoint also takes OpenAI's voice names, such as alloy, mapped to Paxa voices, and the x-voice-id response header names the voice that spoke.
response_formatmp3 (the default), opus, wav, pcm (16-bit little-endian mono at 24 kHz, as OpenAI's, unless sample_rate names another rate), mulaw, or alaw, as format on /v1/tts. Paxa TTS Flash answers mulaw and alaw with unsupported_format, and other OpenAI formats answer 400.
sample_rateA Paxa extension, read for pcm and wav as on /v1/tts and ignored with other formats, though any value must be one of Paxa TTS Flash v2's rates. It sets their rate in Hz, where Paxa TTS Flash v2 serves 8000, 16000, 22050, 24000, 32000, 44100, 48000 and Paxa TTS Flash only 24000. Set it when the platform playing the audio expects a fixed rate.
temperatureA Paxa extension, read as on /v1/tts: how much the reading varies from one request to the next, from 0 to 2 on Paxa TTS Flash v2. Temperature covers it.
streamDefaults to true, matching OpenAI delivery. Set false for a complete body with a content-length.

speed is served at this model's range. A value outside that range answers 400. A rate the model cannot reach is never applied silently. Fields the OpenAI API defines but Paxa does not serve, for example instructions, are ignored, and existing calls carrying them keep working. The reverse also holds. The timestamps extension exists only on /v1/tts, and timed speech requires the native endpoint.

Apps that fill a voice or model picker from the base URL read GET /v1/audio/voices and GET /v1/audio/models. They list Paxa TTS Flash v2 and its voices, and need no key.

Differences from POST /v1/tts#

The compatible endpoint covers the plain case: text in, audio out, streamed by default. Everything beyond it lives on the native endpoint: timestamps and language exist only on /v1/tts and /v1/tts/live, and the native request shape is what the API reference documents field by field. A timestamps or language sent here is ignored: the response is plain audio, and every request reads as auto.

Both endpoints accept an Idempotency-Key, state the cost in x-credits-charged from the first byte, and answer failures from the same error catalog. A stream refused after its audio began is not charged (Streaming). Retry and billing code written against one endpoint works against the other.

Transcription#

POST /v1/audio/transcriptions serves the OpenAI audio.transcriptions.create shape, under the same base URL and the same key. The recording rides as a multipart file part. Nothing is base64 encoded.

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.paxalabs.com/v1",
    api_key=os.environ["PAXA_API_KEY"],
)

with open("meeting.m4a", "rb") as file:
    subtitles = client.audio.transcriptions.create(
        file=file,
        model="paxa-stt-lite-v1-preview",
        response_format="srt",
    )

with open("meeting.srt", "w") as out:
    out.write(subtitles)
FieldBehavior
fileThe recording as a file part, in any of 7 containers; the format and the length come from the bytes. Same ceilings and pricing as audio on /v1/stt.
modelRequired. A Paxa model id, for example paxa-stt-lite-v1-preview. OpenAI's whisper-1, gpt-4o-transcribe, gpt-4o-mini-transcribe, gpt-4o-mini-transcribe-2025-03-20, gpt-4o-mini-transcribe-2025-12-15 also work and run on paxa-stt-lite-v1-preview.
languageA BCP 47 hint, the same field as on /v1/stt. Omitted, the model detects the language itself.
response_formatjson (the default), verbose_json, text, srt, or vtt. verbose_json adds the duration, the segments, and the words when timestamp_granularities names word.

The charge rides x-credits-charged, since OpenAI's body has nowhere to report it. prompt and temperature are ignored, and timestamp_granularities is read with verbose_json alone. stream set to true answers 400 validation; WS /v1/stt/live transcribes as the audio arrives. The two transcript conventions, the two styles, speaker turns, the vocabulary, and the subtitle line length are extensions of POST /v1/stt and are not read here. A recording long enough to run past a proxy's idle limit belongs on the native endpoint, whose JSON body is kept alive while it works.

Switch an existing integration#

  • Point the SDK's base URL at https://api.paxalabs.com/v1.
  • Swap the OpenAI key for an API key from the dashboard.
  • Keep OpenAI's model names, which run on paxa-tts-flash-v2, or set model to paxa-tts-flash-v2 or paxa-tts-flash-v1.
  • Keep OpenAI's voice names, or set voice to an id the chosen model serves, from GET /v1/voices. A voice off that model's roster answers 400 unknown_voice.
  • Set response_format to mp3, opus, wav, or pcm, or mulaw or alaw for phone lines; the other OpenAI containers are not served.

Note

Failures follow this API's error model. The SDK raises its usual HTTP error, and the response body carries the stable code in title.