Audio chat API

Ask a short question about WAV audio with GPT Audio Mini and receive text and speech.

Use gpt-audio-mini with your own official-group API key. Availability is shown on the model page. The page supports upload, playback and WAV download; playground requests are billed normally.

Request

Send one user message with two content parts: text first, then Base64 input_audio with format: "wav". Input must be a complete mono PCM16 WAV, at most 6 seconds and 600000 bytes. Supported sample rates are 8000, 16000, 22050, 24000, 44100 and 48000 Hz. Text is limited to 256 UTF-8 bytes.

import base64
import json
import os
import urllib.request

with open("speech.wav", "rb") as source:
    audio = base64.b64encode(source.read()).decode("ascii")
body = {
    "model": "gpt-audio-mini",
    "messages": [{"role": "user", "content": [
        {"type": "text", "text": "Listen to the clip. Reply only OK."},
        {"type": "input_audio", "input_audio": {"data": audio, "format": "wav"}}
    ]}],
    "modalities": ["text", "audio"],
    "audio": {"voice": "alloy", "format": "pcm16"},
    "max_completion_tokens": 256,
    "stream": True,
    "stream_options": {"include_usage": True}
}
request = urllib.request.Request(
    "https://app.apipool.dev/v1/chat/completions",
    data=json.dumps(body).encode(),
    headers={"Authorization": "Bearer " + os.environ["APIPOOL_API_KEY"],
             "Content-Type": "application/json"}
)
with urllib.request.urlopen(request, timeout=180) as response:
    events = response.read().decode("utf-8")
    print(events)

Keep stream=true, include_usage=true, the two modalities, alloy and pcm16. max_completion_tokens must be between 1 and 256; use 256 with brief reply instructions. A lower cap can truncate speech before it finishes. Conversation history, other voices/formats, tools, caching, other endpoints and extra parameters are not accepted.

Delivery and usage

The service validates the complete result and settles the request before delivering SSE. This is not a low-latency realtime call. Completion is marked by data: [DONE].

Decode each choices[0].delta.audio.data Base64 fragment separately, then concatenate the bytes in order. The result is 24 kHz, 16-bit little-endian mono PCM. Do not concatenate encoded fragments before decoding. Join the audio.transcript fragments for reply text. The playground wraps PCM in a playable WAV container.

prompt_tokens_details and completion_tokens_details contain text_tokens and audio_tokens. These four actual quantities are billed independently. Prompt/completion totals include audio; do not charge those totals again. Audio duration and file size are not token estimates. Usage history displays total input/output, while the original four-part usage remains attached to the request.

Pricing and failures

MeterEffective customer price, USD / million tokens
Text input0.51
Text output2.04
Audio input8.50
Audio output17.00

The price version at submission is used for settlement. Add the four amounts, then round the request total up to US$0.000001. For text input/output 20/6 and audio input/output 60/23, the customer charge is US$0.000924.

At these prices, admission requires at least US$1.092352 of available balance, conservatively based on the model context boundary and the supported output cap. This is a balance check, not a charge or hold; final billing uses actual usage. Concurrent and pending requests count toward account request limits. This check does not guarantee that aggregate concurrent exposure stays within the balance.

If usage is missing or inconsistent, the stream is interrupted, the request times out or the result is outside supported bounds, the API returns an error and the request is not charged. Partial audio is not delivered and tokens are not estimated. Keep the x-apipool-request-id header if you need to contact support.