01
Generate your first media job
Create an API key in the Console, then submit a job for a media model from the catalog. The example uses sonilo/text-to-music. Save data.jobId from the response and poll the result endpoint every few seconds until status is completed or failed; the completed result contains the output URL.
# 1. Submit a job. The response contains data.jobId.
curl -X POST https://restapi.scalingtensor.com/api/media/generate \
-H "Content-Type: application/json" \
-H "apiKey: YOUR_API_KEY" \
-d '{
"model": "sonilo/text-to-music",
"params": {
"prompt": "lofi hiphop beat with warm vinyl texture",
"duration": 20,
"variants_num": 1
}
}'
# 2. Poll with that jobId until data.status is completed or failed.
curl "https://restapi.scalingtensor.com/api/media/result?jobId=YOUR_JOB_ID" \
-H "apiKey: YOUR_API_KEY"02
Fundamentals
Base URL
Use the production API root below. Requests and responses use JSON. Media generation currently accepts JSON URLs only; binary uploads are not supported.
https://restapi.scalingtensor.comAuthentication
Except for the model list, chat and media calls require the key created in the Console in the apiKey request header. Do not use Authorization or expose keys in browser code.
Content-Type: application/json
apiKey: YOUR_API_KEYResponse envelope
Every endpoint returns the same envelope. A request is successful only when code is 0; an HTTP success alone does not indicate business success. time and Long identifiers may be serialized as strings.
{
"code": 0,
"data": { ... },
"msg": "Success",
"time": "1788483942311",
"requestId": "",
"success": true
}03
API Reference
/api/chat/completionCreate a chat completion
This endpoint is synchronous and works with catalog models whose type is chat; replace YOUR_CHAT_MODEL_ID with one of their slugs. messages are passed to the active model adapter. The current controller accepts only model and messages as top-level fields.
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Slug of an enabled chat model |
messages | object[] | Yes | Message array; each item normally includes role and content |
curl -X POST https://restapi.scalingtensor.com/api/chat/completion \
-H "Content-Type: application/json" \
-H "apiKey: YOUR_API_KEY" \
-d '{
"model": "YOUR_CHAT_MODEL_ID",
"messages": [
{"role": "user", "content": "Hello!"}
]
}'Response data
| Field | Type | Description |
|---|---|---|
content | string | Generated model text |
tokensIn | integer | Actual input token count |
tokensOut | integer | Actual output token count |
costMicros | int64/string | Actual cost in microdollars (USD 1 = 1,000,000 microdollars) |
{
"code": 0,
"data": {
"content": "Hello! How can I help?",
"tokensIn": 8,
"tokensOut": 7,
"costMicros": "6"
},
"msg": "Success"
}/api/media/generateSubmit a media job
Media generation is asynchronous. Save the returned jobId and poll the result endpoint. params are forwarded according to the model provider, so available fields depend on the selected model.
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Slug of an enabled media model |
params | object | Yes | Model parameter object; cannot be null |
curl -X POST https://restapi.scalingtensor.com/api/media/generate \
-H "Content-Type: application/json" \
-H "apiKey: YOUR_API_KEY" \
-d '{
"model": "sonilo/text-to-music",
"params": {
"prompt": "Warm ambient music for a product demo",
"duration": 30,
"variants_num": 1
}
}'Response data
| Field | Type | Description |
|---|---|---|
jobId | int64/string | ScalingTensor job ID used to retrieve the result |
status | string | Initial status, normally pending |
{
"code": 0,
"data": { "jobId": "724958320123", "status": "pending" },
"msg": "Success"
}/api/media/resultRetrieve a media result
Poll with the jobId returned during submission. A job can only be read by the user that owns the API key used to create it. Poll every 2–5 seconds until completed or failed.
| Field | Type | Required | Description |
|---|---|---|---|
apiKey | header | Yes | A valid API key for the account that created the job |
jobId | query / int64 | Yes | jobId returned by media submission |
curl "https://restapi.scalingtensor.com/api/media/result?jobId=724958320123" \
-H "apiKey: YOUR_API_KEY"Job statuses
| Field | Description |
|---|---|
pending | Queued or processing; continue polling |
completed | Completed; resultData contains the provider result and output URL |
failed | Failed; stop polling. Precharged fixed cost is refunded according to service logic |
{
"code": 0,
"data": {
"status": "completed",
"resultData": {
"status": "completed",
"output_url": "https://.../result.mp3"
}
},
"msg": "Success"
}04
Common media parameters
params differ by model. Each model page lists its accepted parameters (Input Schema) and an example request. The Sonilo parameters below are validated before a job is accepted.
| Model | params fields and constraints |
|---|---|
sonilo/text-to-music | prompt (1–2,000 chars), duration (integer, 5–360 seconds); optional segments, output_format, variants_num (1–10) |
sonilo/text-to-sfx | prompt (1–2,000 chars), duration (integer, 1–180 seconds); optional audio_format: wav/mp3/aac/flac |
sonilo/video-to-music | video_url (public direct HTTP(S) video URL); optional prompt, segments, preserve_speech, isolate_vocals, output_format, ducking, variants_num, stems, prompt_influence, lyrics |
sonilo/video-to-sfx | video_url; optional prompt (up to 2,000 chars), audio_format, segments (1–30 contiguous items with start, end, prompt) |
sonilo/dubbing | video_url; optional languages (unique language-code array), ducking (boolean) |
05
Error handling
Business errors use the same response envelope. Check code before reading data. Common codes are listed below.
| code | Description |
|---|---|
0 | Success |
3 | Rate limited |
5 | Internal server error |
1000 | General business error |
1001 | Invalid parameters |
1003 | Model/job not found, or job belongs to another user |
1008 | Invalid or revoked API key |
1009 | Insufficient wallet balance |
1012 | Video is too large to inspect |
1013 | Could not determine a positive video duration |
Security and retry guidance
- Keep API keys on your server or in a secure secret manager.
- Decide carefully whether to retry chat calls to avoid duplicate charges.
- After a media submission succeeds, do not resubmit; store jobId and poll it.
- Use exponential backoff only for rate limits, network failures, and server errors.