# Sonilo Text to Music API

> Sonilo Text to Music composes an instrumental track from a text description. Set the length from 5 seconds to 6 minutes, change style at timed segments, and request several variants in one call.

- Model ID: `sonilo/text-to-music`
- Provider: Sonilo
- Tasks: Music Generation, Text to Music
- Price: $0.00225 per second of output, multiplied by the number of variants. A 30-second output costs $0.0675.
- Web page: https://scalingtensor.com/models/sonilo/text-to-music

## How to call it

Authenticate with the `apiKey` request header. Submit a job, then poll for the result:

1. `POST https://restapi.scalingtensor.com/api/media/generate` with JSON `{ "model": "<model ID>", "params": { ... } }`. The response `data.jobId` identifies the job.
2. `GET https://restapi.scalingtensor.com/api/media/result?jobId=<jobId>` until the status is `completed` or `failed`.
3. A response `code` of 0 means success; otherwise read `msg`.

```bash
curl --request POST 'https://restapi.scalingtensor.com/api/media/generate' \
  --header 'apiKey: YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data-raw '{
  "model": "sonilo/text-to-music",
  "params": {
    "prompt": "lofi hiphop beat with warm vinyl texture",
    "duration": 20,
    "variants_num": 1,
    "output_format": "m4a"
  }
}'
```

## Input parameters

Parameters go inside the `params` object.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `prompt` | string | true | Text prompt describing the music to generate. Max length 2000 characters. |
| `duration` | integer | true | Desired duration of the output track in seconds. Min 5, max 360. |
| `output_format` | string | false | Optional. `m4a` (default) returns AAC‑encoded audio. `wav` returns 16‑bit PCM WAV instead, transcoded server‑side after generation. `mp3` returns 320 kbps MP3. |
| `segments` | string | false | Optional JSON array of timed segment prompts; the music changes style at each boundary. Each item has `start` (seconds; the first must be 0, starts strictly increasing and at least 5 seconds apart, the last at least 5 seconds before `duration`), `prompt` (1‑200 characters), and an optional `label` that must be exactly one of these values — any other value is rejected with a 422 error, and it defaults to `none` when omitted: `intro`, `verse`, `pre‑chorus`, `chorus`, `bridge`, `break`, `silence`, `outro`, `none`. 1‑30 items. |
| `variants_num` | integer | false | Optional. How many distinct music variants to generate in one request, 1‑10 (default `1`). Each variant is a separate creative direction with its own title, returned as its own entry in `audio`. Cost scales linearly — `variants_num=3` costs three times a single‑variant request. Values above 1 are never covered by the free trial and are always billed. |

## FAQ

### How much does the Sonilo Text to Music API cost?

Sonilo Text to Music costs $0.00225 per second of output, multiplied by the number of variants on ScalingTensor. A 30-second output costs $0.0675. There is no subscription; usage is charged to your prepaid wallet.

### How do I call the Sonilo Text to Music API?

Send POST /api/media/generate with "model": "sonilo/text-to-music" and the parameters in a params object, using your apiKey header. The call returns a jobId. Poll GET /api/media/result?jobId=... until the status is completed, then read the output URL from the result.

### Which parameters does Sonilo Text to Music accept?

Required: prompt and duration. Optional: output_format, segments and variants_num. The parameter table on this page describes each one.

### Do I need a Sonilo account to use Sonilo Text to Music?

No. You call Sonilo Text to Music with your ScalingTensor API key and pay from your ScalingTensor wallet. The same key works for every other model in the catalog.
