CloseRouter

Audio

Send audio to a model or generate speech. Support depends on the selected model.

Audio input

Use a model that supports audio input. This example passes a file as a data URL; formats and limits depend on the selected provider.

curl
export AUDIO_BASE64="$(base64 -w 0 ./sample.wav)"

curl https://api.closerouter.dev/v1/chat/completions \
  -H "Authorization: Bearer $CLOSEROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "google/gemini-3.1-pro-preview",
    "messages": [
      {
        "role": "user",
        "content": [
          { "type": "text", "text": "Describe this audio in one sentence." },
          {
            "type": "input_audio",
            "input_audio": {
              "data": "'"$AUDIO_BASE64"'",
              "format": "wav"
            }
          }
        ]
      }
    ],
    "max_tokens": 80
  }'

Speech synthesis — /audio/speech

Choose a speech synthesis model. The response contains an audio file: save it for playback. Check voice and format support for the selected provider.

curl
curl https://api.closerouter.dev/v1/audio/speech \
  -H "Authorization: Bearer $CLOSEROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"your-speech-model-id","input":"Hello!","response_format":"mp3"}' \
  --output speech.mp3