Generate audio
The ShareAI endpoint returns a bounded JSON audio result.
On this page
https://api.shareai.now/api/v1/audio/generationsGenerate audio
- Base URL
https://api.shareai.now- Authentication
- Bearer API key or approved OAuth access token
- Required scope
inferenceormonetization_gateway
The ShareAI endpoint returns a bounded JSON audio result. Audio-generating requests with modalities:["text","audio"] can also use /api/v1/chat/completions. Your request is routed to the declared audio operation. This synchronous response is collected before return; incomplete provider streams do not become successful billed results. Audio output formats are mp3, wav, flac, pcm16 or pcm24, subject to the model. Raw PCM cannot support a duration tariff. Set either max_tokens or max_completion_tokens to bound generated tokens; do not supply both.
Before you start#
Set SHAREAI_API_KEY on your server and replace the model placeholder with a currently enabled model. Never expose the API key in browser code. The model, account, credential and provider must all permit this operation. Optional settings below require model support; the API safety bounds are not a promise that every model supports every value.
Send a request#
cURL
curl --fail-with-body --request POST "https://api.shareai.now/api/v1/audio/generations" \
-H "Authorization: Bearer $SHAREAI_API_KEY" \
-H "Content-Type: application/json" \
--data '{
"model": "YOUR_ENABLED_AUDIO_MODEL",
"messages": [
{
"role": "user",
"content": "A short instrumental melody."
}
],
"modalities": [
"text",
"audio"
],
"audio": {
"format": "mp3"
},
"max_completion_tokens": 1024
}'Python
import json
import os
import urllib.request
payload = {'model': 'YOUR_ENABLED_AUDIO_MODEL',
'messages': [{'role': 'user', 'content': 'A short instrumental melody.'}],
'modalities': ['text', 'audio'],
'audio': {'format': 'mp3'},
'max_completion_tokens': 1024}
headers = {'Content-Type': 'application/json'}
headers["Authorization"] = "Bearer " + os.environ["SHAREAI_API_KEY"]
request = urllib.request.Request('https://api.shareai.now/api/v1/audio/generations', data=json.dumps(payload).encode(), headers=headers, method="POST")
with urllib.request.urlopen(request, timeout=180) as response:
result = json.load(response)
print(result)TypeScript
const response = await fetch("https://api.shareai.now/api/v1/audio/generations", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.SHAREAI_API_KEY}`, ...{"Content-Type": "application/json"} },
body: JSON.stringify({
"model": "YOUR_ENABLED_AUDIO_MODEL",
"messages": [
{
"role": "user",
"content": "A short instrumental melody."
}
],
"modalities": [
"text",
"audio"
],
"audio": {
"format": "mp3"
},
"max_completion_tokens": 1024
}),
});
if (!response.ok) throw new Error(await response.text());
const result = await response.json();
console.log(result);Request fields#
| Field | Type | Meaning and limits |
|---|---|---|
model required | string | Exact enabled public model identifier. Must declare this operation and be allowed by your credential. |
messages required | array | 1–256 conversation messages with role/content. Use only content modalities supported by the selected audio model. |
modalities | array | One or two unique values from text and audio; audio is required. Defaults to audio. This synchronous endpoint does not accept stream. |
audio | object | Optional output options: voice and format only. format is mp3, wav, flac, pcm16 or pcm24, subject to model support. Raw PCM is incompatible with duration tariffs. |
temperature | number | Optional model-supported generation temperature. |
top_p | number | Optional model-supported nucleus sampling value. |
max_tokens | integer | Optional output-token bound, 1–262144. Do not combine with max_completion_tokens. |
max_completion_tokens | integer | Optional output-token bound, 1–262144. Do not combine with max_tokens. |
provider | object | Optional provider routing preferences. Use provider.only for accepted provider tags, not a prefix in the model ID. Account and credential restrictions still apply. |
Read the result#
Success returns HTTP 200 with JSON. The ShareAI endpoint returns a bounded JSON audio result. Audio-generating requests with modalities:["text","audio"] can also use /api/v1/chat/completions. Your request is routed to the declared audio operation. This synchronous response is collected before return; incomplete provider streams do not become successful billed results. Audio output formats are mp3, wav, flac, pcm16 or pcm24, subject to the model. Raw PCM cannot support a duration tariff. Set either max_tokens or max_completion_tokens to bound generated tokens; do not supply both.
Billing units#
Audio models can publish separate text-token and audio-token dimensions, duration, song or request rates. Inclusive token totals are split into disjoint text/audio counters; the same audio tokens are never charged again as text. Unsupported or missing usage is not approximated from encoded bytes.
Choose the exact enabled model identifier from Console. Its declared operation and input/output capabilities must match this endpoint; a text chat model cannot be substituted for another operation. Your credential, provider and account restrictions still apply.
Pricing and usage#
Rates are published in EUR AI credits for the selected model, provider, units and variants. Only the dimensions in its active tariff are charged. An estimate reserves credits before execution; final charges use measured usage. Prices can depend on resolution, output format or a usage band. Check Console Usage for the final ShareAI debit. Upstream cost fields and media bytes are not converted into invented token counts.
Access and errors#
Use inference for approved network-cost inference or monetization_gateway for an approved Builder markup and accepted billing terms. Identity-only access does not authorize spending. Validation, model authorization, insufficient credits, rate limits and execution failures return a structured error. After a timeout or uncertain submission, inspect Usage or the video job before creating another potentially paid request.
Last updated November 3, 2026