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

# Integrate Algorithmic Composer

> Compose playable patterns around the current project or transform existing code.

Call `POST /api/strudel/` with a nonempty `prompt`. Supply project context so the new part fits the arrangement. [Complete request fields](https://docs.rawchunks.space/dev/endpoints/strudel/compose.md).

```json theme={"theme":{"light":"github-dark","dark":"github-dark"}}
{
  "prompt": "A sparse bass part around the drums",
  "bpm": 110,
  "keyScale": "A minor",
  "timeSignature": "4/4",
  "selectedTrack": "Drums",
  "selection": { "start": 15, "end": 30 },
  "stream": true
}
```

## Supply context

Send `songId` to load song metadata. Add `stylePrompt`, active `stems` and `tracks`, plus `musicalContext` extracted by your client. Track entries require `id`, `name` and `type`; `muted` and `solo` are optional.

Use `selection` for a region or `playhead` for the current position. Send `currentCode` to transform a pattern. Context aliases resolve in this order: `songContext`, `musicalContext`, `musical_context`.

## Read and play the pattern

JSON returns `code`, optional `reasoning` and a `graph` summary. Enable NDJSON with `stream: true` or `Accept: application/x-ndjson`. Reuse the [NDJSON reader](https://docs.rawchunks.space/dev/guides/jobs.md#generation-edit-and-voice-streams).

| Event | Client action |
| - | - |
| `graph` | Show the chosen layers and musical reference if useful. |
| `status` | Show `step`. |
| `reasoning` | Show the short musical rationale in `text`. |
| `code` | Update the editor with `code`. |
| `done` | Commit final `code` and optional `reasoning`. |
| `error` | Show `message`; retain the current pattern. |

Rawchunks validates the final pattern with its client parser and schedules it locally at the project BPM. Your integration supplies its own player or reuses the open-source app's parser and audio engine.

![Code pattern with reference selector, AI Code action, Run, macros and Composer log.](https://mintcdn.com/rawchunks/ma13LU4xVjl9w_v5/images/app/editor-strudel.png?fit=max\&auto=format\&n=ma13LU4xVjl9w_v5\&q=85\&s=1a3d695e3c3a6e8a032785405426b29e)

Current Code REPL with Composer output and local playback controls.

## Inspect before generating

Use [graph routing](https://docs.rawchunks.space/dev/endpoints/strudel/graph.md) to inspect selected libraries and theory references without model generation. [Validation](https://docs.rawchunks.space/dev/endpoints/strudel/validate.md) cleans code and checks supported notation. Drum, harmony, synth and archetype library routes expose the musical references.

`POST /api/editing/strudel` accepts the same context fields and returns only `{ code }`. Use the primary route for streaming and graph details.

The [Code walkthrough](https://docs.rawchunks.space/app/live-code.md) covers versions and macros. [Composer architecture](https://docs.rawchunks.space/ai-ml/composer.md) explains graph routing and ReAct.


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