> ## 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.

# Compose a Code pattern

> Compose a new Strudel part or transform the current pattern.

Compose a new Strudel part or transform the current pattern.

Use [request setup](https://docs.rawchunks.space/dev/guides/connect.md) for account headers.

## JSON body

**prompt** `string` *required*

Nonempty musical request.

**songId** `string`

Saved project to supply metadata.

**currentCode** `string`

Existing pattern to transform.

**bpm** `number`

30 to 300.

**keyScale** `string`

For example, A minor.

**stylePrompt** `string`

Song style.

**timeSignature** `string`

For example, 4/4.

**selectedTrack** `string`

Reference track name.

**selection** `object`

Nonnegative `start`, `end` in seconds; optional `trackId`.

**playhead** `number`

Nonnegative position in seconds.

**stems** `string[]`

Active stem names.

**tracks** `object[]`

Each requires `id`, `name`, `type`; optional boolean `muted`, `solo`.

**songContext** `string`

Context, at most 4,000 characters. Takes precedence over the aliases.

**musicalContext** `string`

Context alias, at most 4,000 characters.

**musical\_context** `string`

Second context alias, at most 4,000 characters.

**stream** `boolean`

Enable NDJSON. `Accept: application/x-ndjson` also enables it.

## JSON response

**code** `string`

Validated pattern.

**reasoning** `string`

Short musical rationale.

**graph** `object`

Routing summary described below.

## Graph summary

| Field | Type | Use |
| - | - | - |
| `intent` | string | `compose` or `transform`. |
| `targetLayers` | string\[] | `drums`, `bass`, `chords`, `arp`. |
| `mountedLibraries` | string\[] | Library slices selected for this request. |
| `archetypeId / archetypeLabel` | string | Selected genre reference. |
| `refRole` | string | `drums`, `bass`, `vocals`, `keys`, `master`. |
| `sectionNode` | string | `intro`, `verse`, `build`, `drop`, `breakdown`. |
| `estimatedTokens` | integer | Character-based estimate of the prepared messages. |

## NDJSON events

| Field | Type | Use |
| - | - | - |
| `graph` | event | Routing summary. |
| `status` | event | `step` describes current work. |
| `reasoning` | event | `text` explains the musical choices. |
| `code` | event | `code` updates the REPL. |
| `done` | event | Final `code` and optional `reasoning`. |
| `error` | event | `message` describes a failed run. |

## Use the result

[Integrate Composer](https://docs.rawchunks.space/dev/guides/edit/strudel.md). JSON is the default; consume streamed events by `type`. The `/strudel/` alias has the same contract.


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