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

# Layer an instrument

> Submit layer an instrument.

Layer requires `trackName` and the Base model. For seed, tempo, key or language controls, use `/apply` with `task: "lego"`.

Poll with the returned task kind `lego`. Completed edits remain pending until [activation or merge](/dev/guides/edit/takes).

## Headers and parameters

<ParamField header="Authorization" type="string" required>
  `Bearer $SESSION_TOKEN`. Use the complete token from your active [Rawchunks session](/dev/guides/payments).
</ParamField>

<ParamField header="x-session-user-address" type="string" required>
  Selected account address. Required for owner-scoped reads and writes. It identifies the account; your product must authenticate its own users.
</ParamField>

<ParamField header="x-network-id" type="string">
  Session network in CAIP-2 form, for example eip155:8453.
</ParamField>

## JSON body

<ParamField body="songId" type="string" required>
  Opaque ID returned by the API. Minimum length: `1`.
</ParamField>

<ParamField body="stemId" type="string">
  Optional target stem in this song. Omit to use the master.
</ParamField>

<ParamField body="userAddress" type="string" required>
  Wallet address for the selected account. Use the same address as the session owner. Minimum length: `10`.
</ParamField>

<ParamField body="srcAudioUrl" type="string">
  Optional source override, for example the url from Upload source. Use an HTTP(S) URL.
</ParamField>

<ParamField body="modelQuality" type="string">
  Select a mode listed for this task by GET /api/options. Defaults to base. Layer and Accompany require base. Values: `turbo`, `sft`, `base`.
</ParamField>

<ParamField body="modelVariant" type="string">
  Alternative to modelQuality. If both are sent they must match. Values: `turbo`, `sft`, `base`.
</ParamField>

<ParamField body="prompt" type="string" required>
  Description of the new instrument. Minimum length: `1`.
</ParamField>

<ParamField body="globalCaption" type="string">
  Description of the overall song.
</ParamField>

<ParamField body="trackName" type="string" required>
  Instrument name. Required by the Layer service. Minimum length: `1`.
</ParamField>

<ParamField body="trackClasses" type="string[]" />

<ParamField body="audioDuration" type="number">
  Minimum: `5`.
</ParamField>

<ParamField body="legoContextTrackIds" type="string[]" />

## Response (202)

Accepted; follow the returned task.

<ResponseField name="taskId" type="string" required />

<ResponseField name="songId" type="string" required />

<ResponseField name="stemId" type="string" />

<ResponseField name="task" type="string" required>
  Values: `repaint`, `lego`, `complete`, `extend`, `cover`, `extract`.
</ResponseField>

<ResponseField name="status" type="string" required>
  Values: `pending`, `processing`, `ready`, `error`.
</ResponseField>

<ResponseField name="stems" type="object[]">
  <Expandable title="Properties">
    <ResponseField name="id" type="string" required />

    <ResponseField name="song_id" type="string" required />

    <ResponseField name="name" type="string" required />

    <ResponseField name="url" type="string" required />

    <ResponseField name="volume" type="number">
      Linear gain, 1 is unity. Minimum: `0`.
    </ResponseField>

    <ResponseField name="pan" type="number">
      Range: `-1` to `1`.
    </ResponseField>

    <ResponseField name="is_muted" type="boolean" />

    <ResponseField name="is_solo" type="boolean" />

    <ResponseField name="waveform_peaks_url" type="string | null" />

    <ResponseField name="created_at" type="string" />
  </Expandable>
</ResponseField>

Budget headers use six-decimal USDC atomic units. See [session payments](/dev/guides/payments#track-or-end-a-session).

## Errors

Failed JSON responses contain an `error` string. Check the HTTP status before reading a successful result. See [job handling](/dev/guides/jobs) for interrupted or uncertain submissions.

| Status | Meaning |
| - | - |
| `400` | Invalid request. |
| `401` | Invalid or expired session token. |
| `402` | Payment required or insufficient session budget. |
| `403` | Account does not match resource. |
| `404` | Resource not found. |
| `409` | Resource conflict; reload state or open an editable version. |
| `500` | Request failed. |

<RequestExample>
  ```bash cURL theme={null}
  curl --fail-with-body -X POST "$RAWCHUNKS_API/api/editing/layer" \
    -H "Authorization: Bearer $SESSION_TOKEN" \
    -H "x-network-id: $NETWORK" \
    -H "x-session-user-address: $USER_ADDRESS" \
    -H "Content-Type: application/json" \
    --data "$(jq -nc --arg user "$USER_ADDRESS" --arg song "$SONG_ID" '{
    "songId": $song,
    "userAddress": $user,
    "prompt": "A syncopated electric bass line",
    "trackName": "bass",
    "modelQuality": "base"
  }')"
  ```
</RequestExample>

<ResponseExample>
  ```json 202 theme={null}
  {
    "songId": "sng-example",
    "taskId": "task-example",
    "status": "pending",
    "task": "lego"
  }
  ```
</ResponseExample>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.