Generation

Generation endpoints run the AI pipeline. They all require the generation:run scope and may consume Anthropic, Perplexity, and ElevenLabs credits.

Generate an outline

POST/v1/books/{bookId}/outlinescope: generation:run

Synchronous. Runs the optional Perplexity research pass (if enabled on the instance), then asks the model for a structured outline and seeds chapter rows from it. Replaces any existing chapters and bumps book status to writing.

Returns the updated book and the freshly seeded chapter list. Takes ~10–60 seconds depending on the model tier and whether research ran.

Write a chapter (stream)

POST/v1/books/{bookId}/chapters/{chapterId}/writescope: generation:run

Streams the chapter prose back as text/plain. When the stream closes the persisted chapter is updated and the book status advances to ready if every chapter now has content.

Call chapters in order — the writer reads the tail of the previous chapter for continuity.

curl -N -X POST "$ANTHRA_BASE/books/$BOOK/chapters/$CH/write" \
  -H "authorization: Bearer $ANTHRA_TOKEN"

The response header x-chapter-id echoes the chapter id so clients consuming several streams in parallel can correlate.

Rewrite a chapter (stream)

POST/v1/books/{bookId}/chapters/{chapterId}/rewritescope: generation:run

Same streaming contract as /write, but takes a directive in the body and uses the chapter’s existing prose as the source. The prior content is snapshotted before being overwritten — see the studio’s revision history to roll back.

curl -N -X POST "$ANTHRA_BASE/books/$BOOK/chapters/$CH/rewrite" \
  -H "authorization: Bearer $ANTHRA_TOKEN" \
  -H "content-type: application/json" \
  -d '{ "directive": "Punch up the dialogue. Cut filler. End on a hook." }'

Narrate a chapter

POST/v1/books/{bookId}/chapters/{chapterId}/narratescope: generation:run

Synthesizes ElevenLabs narration for the chapter, uploads the MP3 to Vercel Blob, and stores its URL on the chapter row. The response is the updated chapter (with audioUrl, audioStatus, audioDurationSec).

Requires ELEVENLABS_API_KEY and BLOB_READ_WRITE_TOKEN to be configured on the Anthra instance; otherwise returns 503 feature_disabled.