We use cookies. Cookies and browser storage keep you signed in and remember your preferences. With your permission we also measure how the site is used. You can any time. See our cookie policy.

Music & audio

Endpoints

Music & audio

Generate music and spoken audio on api14 with audio-output chat models, including the audio parameters, formats and response handling.

Try it in the playground

Music and audio-output models (Lyria 3, GPT Audio and others) don't have a dedicated endpoint: you call them through Chat completions and ask for audio output with modalities. The generated audio comes back base64-encoded in the assistant message.

POST https://api14.com/api/v1/chat/completions

Request

All chat completion parameters apply. The audio-specific ones:

ParameterTypeRequiredDescription
modelstringyesAn audio model id, e.g. google/lyria-3 or openai/gpt-audio.
messagesarrayyesDescribe the music or the speech you want.
modalitiesstring[]yes["text", "audio"] to receive audio.
audioobjectnoOutput options for speech models: { "voice": "alloy", "format": "wav" }.
streambooleannoStream audio chunks as server-sent events where supported.

Example

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api14.com/api/v1",
  apiKey: process.env.API14_API_KEY,
});

const result = await client.chat.completions.create({
  "model": "google/lyria-3",
  "messages": [
    {
      "role": "user",
      "content": "Explain vector databases in two sentences."
    }
  ]
});
console.log(result.choices[0].message.content);

A raw request:

{
  "model": "google/lyria-3",
  "modalities": ["text", "audio"],
  "messages": [
    { "role": "user", "content": "A 30-second lo-fi hip hop loop with soft piano and vinyl crackle." }
  ]
}

Response

{
  "id": "gen-1791100000-xyz",
  "object": "chat.completion",
  "model": "google/lyria-3",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Here is your loop.",
        "audio": { "id": "audio_01", "data": "UklGRiQAAABXQVZFZm10...", "format": "wav" }
      },
      "finish_reason": "stop"
    }
  ],
  "usage": { "prompt_tokens": 24, "completion_tokens": 1500, "total_tokens": 1524, "cost": 0.06 }
}

Decode choices[0].message.audio.data from base64 and save it with the given format extension.

Audio input

To send audio into a model (e.g. "summarize this recording"), use an input_audio content part, see Vision & files. For plain speech-to-text, Transcription is simpler and cheaper; for text-to-speech, use Speech.

Listing audio models

curl "https://api14.com/api/v1/models?category=audio"

Pricing

Audio models are billed at their listed price (per audio token, per second or per request, depending on the model). The exact cost is in usage.cost.

Errors

StatusCodeWhen
402insufficient_balanceYour USD balance is $0.
403plan_requiredYour plan does not include audio models.
404model_not_foundUnknown or disabled model id.

See Errors.