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

# Audio APIs

> Choose CometAPI audio routes for text-to-speech, transcription, and audio translation workflows.

Use CometAPI audio model docs by choosing whether your app needs speech output, transcription, or translation. Audio endpoints use the same CometAPI API key pattern as other OpenAI-compatible endpoints.

## Choose an audio API

<CardGroup cols={3}>
  <Card title="Create speech" icon="microphone" href="/api/audio/create-speech">
    Convert text to speech.
  </Card>

  <Card title="Create transcription" icon="message" href="/api/audio/create-transcription">
    Transcribe audio to text.
  </Card>

  <Card title="Create translation" icon="sparkles" href="/api/audio/create-translation">
    Translate audio to English text.
  </Card>
</CardGroup>

## Create speech

Use an audio-capable model ID from the [Models page](/overview/models) or the [model directory](https://www.cometapi.com/models/). The examples below call the speech endpoint.

<Note>
  These examples use the placeholder `your-audio-model-id`. Replace it with an available audio model ID from the [Models page](/overview/models) or [model directory](https://www.cometapi.com/models/) before you run the request.
</Note>

<Tip>
  Open [Create speech](/api/audio/create-speech) to use the playground and endpoint schema.
</Tip>

<CodeGroup>
  ```python Python theme={null}
  import os
  import requests

  response = requests.post(
      "https://api.cometapi.com/v1/audio/speech",
      headers={
          "Authorization": "Bearer " + os.environ["COMETAPI_KEY"],
          "Content-Type": "application/json",
      },
      json={
          "model": "your-audio-model-id",
          "input": "Welcome to CometAPI.",
          "voice": "alloy",
          "response_format": "mp3",
      },
      timeout=60,
  )

  response.raise_for_status()

  with open("speech.mp3", "wb") as audio_file:
      audio_file.write(response.content)
  ```

  ```javascript Node.js theme={null}
  import { writeFile } from "node:fs/promises";

  const response = await fetch("https://api.cometapi.com/v1/audio/speech", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      model: "your-audio-model-id",
      input: "Welcome to CometAPI.",
      voice: "alloy",
      response_format: "mp3",
    }),
  });

  if (!response.ok) {
    throw new Error(await response.text());
  }

  const audio = Buffer.from(await response.arrayBuffer());
  await writeFile("speech.mp3", audio);
  ```

  ```bash cURL theme={null}
  curl https://api.cometapi.com/v1/audio/speech \
    -H "Authorization: Bearer $COMETAPI_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "your-audio-model-id",
      "input": "Welcome to CometAPI.",
      "voice": "alloy",
      "response_format": "mp3"
    }' \
    --output speech.mp3
  ```
</CodeGroup>

## Response example

A successful speech response is binary audio. The HTTP response can look like this:

```text theme={null}
HTTP/1.1 200 OK
Content-Type: audio/mpeg

speech.mp3
```

## Example model records

<Info>
  This example model catalog response shows the `/api/models` envelope and one audio model record shape. It is not a complete model list.
</Info>

```bash cURL theme={null}
curl https://api.cometapi.com/api/models
```

```json theme={null}
{
  "success": true,
  "page": 1,
  "page_size": 20,
  "total": 302,
  "data": [
    {
      "created": 0,
      "id": "your-audio-model-id",
      "code": "your-audio-model-id",
      "provider": "ExampleProvider",
      "provider_code": "example",
      "name": "Example audio model",
      "model_type": "audio",
      "features": [
        "text-to-speech"
      ],
      "endpoints": [
        "openai"
      ],
      "pricing": {
        "currency": "USD / M Tokens",
        "input": 12,
        "output": 12,
        "per_request": null,
        "per_second": null
      }
    }
  ]
}
```

## Common errors

<AccordionGroup>
  <Accordion title="Unsupported audio format">
    Use the formats documented on the endpoint page.
  </Accordion>

  <Accordion title="Large upload rejected">
    Compress the audio file or split the job into smaller files.
  </Accordion>

  <Accordion title="Empty transcription">
    Confirm that the file contains speech and that the field name matches the docs.
  </Accordion>

  <Accordion title="Wrong base URL">
    Use `https://api.cometapi.com/v1`.
  </Accordion>
</AccordionGroup>

## Error codes and retry strategy

<AccordionGroup>
  <Accordion title="400">
    Do not retry until the text, file, model ID, voice, or format is fixed.
  </Accordion>

  <Accordion title="401">
    Do not retry until the API key is present and valid.
  </Accordion>

  <Accordion title="404">
    Check the base URL, path, and model ID before retrying.
  </Accordion>

  <Accordion title="413">
    Reduce upload size before retrying.
  </Accordion>

  <Accordion title="429">
    Retry with exponential backoff and reduce concurrency.
  </Accordion>

  <Accordion title="500 or 503">
    Retry with backoff for transient provider or service errors.
  </Accordion>
</AccordionGroup>

<Tip>
  For implementation patterns, see [Error codes and retry strategy](/guides/error-codes-and-retry-strategy) and [Rate limits and concurrency](/guides/rate-limits-and-concurrency).
</Tip>

## Pricing and model directory

<CardGroup cols={3}>
  <Card title="Models page" icon="list" href="/overview/models">
    Read how CometAPI exposes model IDs in the docs.
  </Card>

  <Card title="Model directory" icon="puzzle-piece" href="https://www.cometapi.com/models/">
    Browse model availability and capabilities.
  </Card>

  <Card title="Pricing" icon="tag" href="https://www.cometapi.com/pricing/">
    Check pricing before you call a model.
  </Card>
</CardGroup>
