> ## Documentation Index
> Fetch the complete documentation index at: https://developers.meshapi.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Audio

> Send audio into chat completions and request audio output from supported models.

Mesh API supports audio through `POST /v1/chat/completions`.

Use this page for:

* audio input with `input_audio`
* audio output with `modalities` and `audio`

## Audio input

Send audio as a content part inside a chat message.

<Tabs>
  <Tab title="curl">
    ```bash theme={null}
    curl https://api.meshapi.ai/v1/chat/completions \
      -H "Authorization: Bearer <YOUR_RSK_KEY>" \
      -H "Content-Type: application/json" \
      -d '{
        "model": "google/gemini-3-flash-preview",
        "messages": [
          {
            "role": "user",
            "content": [
              { "type": "text", "text": "Transcribe this clip." },
              {
                "type": "input_audio",
                "input_audio": {
                  "data": "<BASE64_AUDIO>",
                  "format": "wav"
                }
              }
            ]
          }
        ]
      }'
    ```
  </Tab>

  <Tab title="Node.js SDK">
    ```ts theme={null}
    const response = await client.chat.completions.create({
      model: "google/gemini-3-flash-preview",
      messages: [
        {
          role: "user",
          content: [
            { type: "text", text: "Transcribe this clip." },
            {
              type: "input_audio",
              input_audio: {
                data: "<BASE64_AUDIO>",
                format: "wav",
              },
            },
          ],
        },
      ],
    });
    ```
  </Tab>

  <Tab title="Python SDK">
    ```python theme={null}
    from meshapi import ChatCompletionParams, ChatMessage, ContentPartAudio, ContentPartText, InputAudio, MeshAPI

    client = MeshAPI(base_url="https://api.meshapi.ai", token="rsk_...")

    response = client.chat.completions.create(
        ChatCompletionParams(
            model="google/gemini-3-flash-preview",
            messages=[
                ChatMessage(
                    role="user",
                    content=[
                        ContentPartText(type="text", text="Transcribe this clip."),
                        ContentPartAudio(
                            type="input_audio",
                            input_audio=InputAudio(data="<BASE64_AUDIO>", format="wav"),
                        ),
                    ],
                )
            ],
        )
    )
    ```
  </Tab>

  <Tab title="Go SDK">
    ```go theme={null}
    params := meshapi.ChatCompletionParams{
        Model: meshapi.String("google/gemini-3-flash-preview"),
        Messages: []meshapi.ChatMessage{
            {
                Role: "user",
                Content: []meshapi.ContentPart{
                    {Type: "text", Text: meshapi.String("Transcribe this clip.")},
                    {
                        Type: "input_audio",
                        InputAudio: &meshapi.InputAudio{
                            Data:   "<BASE64_AUDIO>",
                            Format: "wav",
                        },
                    },
                },
            },
        },
    }

    _, err := client.Chat.Completions.Create(ctx, params)
    ```
  </Tab>

  <Tab title="Java SDK">
    ```java theme={null}
    MeshAPI client = MeshAPI.builder()
        .baseUrl("https://api.meshapi.ai")
        .token("rsk_...")
        .build();

    ChatCompletionRequest request = ChatCompletionRequest.builder()
        .model("google/gemini-3-flash-preview")
        .addMessage(
            ChatMessage.builder()
                .role("user")
                .content(java.util.List.of(
                    java.util.Map.of("type", "text", "text", "Transcribe this clip."),
                    java.util.Map.of(
                        "type", "input_audio",
                        "input_audio", java.util.Map.of("data", "<BASE64_AUDIO>", "format", "wav")
                    )
                ))
                .build()
        )
        .build();

    client.chat().completions().create(request);
    ```
  </Tab>
</Tabs>

## Audio output

Request text and audio together when the model supports audio output.

```bash theme={null}
curl https://api.meshapi.ai/v1/chat/completions \
  -H "Authorization: Bearer <YOUR_RSK_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-4o-audio-preview",
    "messages": [
      { "role": "user", "content": "Read this back to me in a calm voice." }
    ],
    "modalities": ["text", "audio"],
    "audio": {
      "voice": "alloy",
      "format": "wav"
    }
  }'
```

The same request shape is available through all four SDKs by setting chat-completions fields for `modalities` and `audio`.

## Translate audio to English

`POST /v1/audio/translations` accepts audio in any language and returns the speech **translated to English**. It returns the same `TranscriptionResponse` (with a `.text` field) as transcription.

<Info>
  This is a distinct endpoint from the transcribe-and-translate helper at `POST /v1/audio/transcriptions/translate`. Check `GET /v1/models` for models that support translation — `model` is required.
</Info>

<Tabs>
  <Tab title="Python SDK">
    ```python theme={null}
    from meshapi import MeshAPI, AudioTranslationsParams

    client = MeshAPI(base_url="https://api.meshapi.ai", token="rsk_...")

    with open("french_audio.mp3", "rb") as f:
        audio_bytes = f.read()

    result = client.audio.audio_translate(
        audio_bytes,
        AudioTranslationsParams(model="openai/whisper-large-v3"),
        filename="french_audio.mp3",
    )

    print(result.text)  # English translation
    ```
  </Tab>

  <Tab title="Node.js SDK">
    ```ts theme={null}
    import { readFileSync } from "fs";

    const audio = readFileSync("french_audio.mp3");

    const result = await client.audio.translations(
      audio,
      { model: "openai/whisper-large-v3" },
      { filename: "french_audio.mp3" },
    );

    console.log(result.text); // English translation
    ```
  </Tab>

  <Tab title="Go SDK">
    ```go theme={null}
    audioBytes, _ := os.ReadFile("french_audio.mp3")

    result, err := client.Audio.Translations(ctx, audioBytes, "french_audio.mp3", meshapi.AudioTranslationParams{
        Model: "openai/whisper-large-v3",
    })
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(result.Text) // English translation
    ```
  </Tab>
</Tabs>

Optional parameters: `prompt` (context hint for the model), `response_format` (`json`, `text`, or `verbose_json`), and `temperature` (0–2).

## SDK coverage

* Node: `client.chat.completions.create(...)`
* Python: `client.chat.completions.create(...)`
* Go: `client.Chat.Completions.Create(...)`
* Java: `client.chat().completions().create(...)`

## Notes

* Audio payloads are base64 encoded in the request body.
* Check `GET /v1/models` to find models that accept or produce audio.
* Keep payload sizes reasonable, especially for browser-based clients.
