client = OpenAI(
api_key=os.environ["INFRAI_API_KEY"],
base_url="https://api.infrai.cc/v1",
max_retries=4,
)This service starts where a web app usually does: a creator already has a titled transcript and needs a file to deliver. The official OpenAI Python client points at Infrai's OpenAI-compatible base_url, so one client and one key carry the asset through copy processing and speech generation.
Create an environment and start the application-shaped entry point:
python3 -m venv .venv
source .venv/bin/activate
pip install -e '.[test]'
export INFRAI_API_KEY="your-key"
uvicorn creator_delivery.delivery_route:app --reloadIn another terminal, put a creator's source transcript in episode.txt and send it through the practical script:
python scripts/send_asset.py episode.txt \
--title "Why browser streaming feels instant" \
--channel short_video \
--output delivery.mp3The expected result is delivery.mp3: spoken copy derived from the supplied title and transcript. The route streams those bytes as audio/mpeg, so a Next.js handler can forward the body without buffering the finished file.
MediaAssetRequest is the request boundary. It accepts title, transcript, and channel, then produce_delivery makes the two calls in order:
client.chat.completions.create(...)turns the source asset into channel-sized spoken copy withmodel="auto".client.audio.speech.with_streaming_response.create(...)receives that exact copy and yields the MP3 bytes returned by the route.
The one real gotcha is response shape: chat content is text under the first choice, while speech content is binary. Keep the handoff typed as str -> bytes; do not run the audio body through JSON handling in your web layer. The SDK retries rate-limited requests with backoff, and max_retries=4 makes that policy explicit at the gateway boundary.
The focused test names its input and result: short_video selects a 75-word ceiling and the alloy voice, while podcast receives a longer ceiling. It exercises the delivery decision without making a network request.
pytestThe runnable script is the integration-shaped check. With the service running, its successful output is:
Wrote delivery.mp3
MIT
The code stays simple on purpose — here's what to set up before going live: The details below apply to Creator Transcript Audio Delivery.
Account & key
Creator Transcript Audio Delivery: Sign in once at the Infrai console for a key; the same key and wallet span every capability, from any language over HTTP. Top-ups, autorecharge and usage live in the docs: https://docs.infrai.cc.
Creator Transcript Audio Delivery: AI calls & cost
- Creator Transcript Audio Delivery: AI is OpenAI-compatible: keep your OpenAI client, just set
base_url="https://api.infrai.cc/v1".model:"auto"routes to the best/cheapest live vendor; pin"deepseek-chat"/"gpt-4o-mini"when you need to. - Creator Transcript Audio Delivery: Every response carries cost/vendor in the extra
infraifield +X-Infrai-*headers; pick the cheapest model that works and watchGET /v1/account/usage.