Skip to content
中文

Export a rendition

A rendition is the form of a draft that one platform receives. One draft can have several, each tracking its own render state, validation issues and export state. The platforms open today are markdown@1 and text@1, both delivered by export; read the platforms open now and their limits with praxis.studio.platforms.list.

Before you start: finish the work, draft and written unit from the Quickstart. The snippet below builds a work with one unit, named with a docs-example prefix; api is a small function that calls curl with the auth header.

终端窗口
export BASE="${PRAXIS_API_BASE:-https://api.deepraxis.com}"
export TAG=$(date +%s)
api() { curl --fail-with-body -sS -H "Authorization: Bearer $PRAXIS_API_KEY" -H "Content-Type: application/json" "$@"; }
export WORK=$(api -X POST "$BASE/studio/v1/works" -d "$(jq -n --arg t "docs-example-export-$TAG" '{title: $t, goal: {reader: "Shop owners", outcome: "Decide on a support agent", message: "An agent takes the routine questions."}}')" | jq -er '.slug')
api -X POST "$BASE/studio/v1/works/$WORK/drafts" -d '{"genre": "blog_article", "key": "post", "outline": [{"kind": "section", "name": "Problem"}]}' > /dev/null
REV=$(api "$BASE/studio/v1/works/$WORK/units/1" | jq -er '.revision')
api -X PATCH "$BASE/studio/v1/works/$WORK/units/1" -d "$(jq -n --argjson rev "$REV" '{expected_revision: $rev, body: "The same question, nine times a day."}')" > /dev/null

1. Create the rendition

render: true creates and renders in one call; without it the rendition starts as pending and you call the render operation afterwards. request_id is your own unique key: resending the same value returns the first rendition instead of creating another.

终端窗口
RENDITION_JSON=$(api -X POST "$BASE/studio/v1/works/$WORK/drafts/post/renditions" \
-d '{"platform": "markdown@1", "render": true, "request_id": "docs-example-render-1"}')
export RENDITION=$(printf '%s' "$RENDITION_JSON" | jq -er '.id')
printf '%s\n' "$RENDITION_JSON" | jq '{id, platform, render_state, stale, issues: [.issues[] | .code], parts: [.parts[] | {index, text}], publish: .publish.state}'

Expected: HTTP 201, render_state rendered, stale false, publish.state none. parts[0].text is the full text; a heading_missing entry in issues is a warning that a unit has no published subheading yet. When rendering finds an error-level problem, render_state is invalid and the HTTP status is still a success: an empty draft gets draft_empty, and an unavailable render service gets failed with render_unavailable, so render again later. Read render_state and issues, not only the status code.

2. The rendition goes stale after an edit

After the draft changes, an existing rendition’s stale becomes true, and a stale rendition cannot be exported.

终端窗口
REV=$(api "$BASE/studio/v1/works/$WORK/units/1" | jq -er '.revision')
api -X PATCH "$BASE/studio/v1/works/$WORK/units/1" \
-d "$(jq -n --argjson rev "$REV" '{expected_revision: $rev, body: "The same question, ten times a day."}')" > /dev/null
api "$BASE/studio/v1/works/$WORK/renditions/$RENDITION" | jq '{stale, render_state}'
curl -sS -X POST "$BASE/studio/v1/works/$WORK/renditions/$RENDITION:publish" \
-H "Authorization: Bearer $PRAXIS_API_KEY" | jq -c '.error | {code, message}'

Expected: stale is true, and the export returns HTTP 409 RENDITION_STALE.

3. Render again, then export

终端窗口
api -X POST "$BASE/studio/v1/works/$WORK/renditions/$RENDITION:render" | jq '{render_state, parts: [.parts[].text]}'
api -X POST "$BASE/studio/v1/works/$WORK/renditions/$RENDITION:publish" | jq '{render_state, publish: {method: .publish.method, state: .publish.state}}'

Expected: the render answer’s parts[0].text is the new body; the export answer has publish.method export and publish.state exported. For markdown@1 and text@1 the output is parts[].text and there is no file, so praxis.studio.works.renditions.retrieveContent returns 409 RENDITION_NOT_RENDERED; that call is for platforms that produce files (such as card images), where it returns a url and its expire_time. Rendering again resets publish.state to none, so export once more.

The quick read that needs no rendition is praxis.studio.works.drafts.retrieveExport (format is markdown or text): it returns the full text synchronously and creates no rendition record.

Clean up

终端窗口
api -X DELETE "$BASE/studio/v1/works/$WORK/renditions/$RENDITION"
api -X PATCH "$BASE/studio/v1/works/$WORK" -d '{"update_mask": ["archived"], "archived": true}' | jq '.value | {slug, archived}'

Expected: the delete returns {"deleted": true} and leaves the draft untouched; once archived, the work no longer appears in the default list.

Do the same with the SDK

import { Praxis } from '@deepraxis/sdk';
const praxis = new Praxis({
apiKey: process.env.PRAXIS_API_KEY!,
baseUrl: process.env.PRAXIS_API_BASE ?? 'https://api.deepraxis.com',
});
// Prerequisite: a work "work" with a draft "post" whose unit 1 has a body (see the quickstart)
const rendition = await praxis.studio.works.drafts.renditions.create({
path: { work, draft: 'post' },
body: { platform: 'markdown@1', render: true, request_id: 'docs-example-render-1' },
});
console.log(rendition.render_state, rendition.parts[0]?.text);
// After the draft changes, the rendition is stale: render it again, then export
const stale = await praxis.studio.works.renditions.retrieve({ path: { work, rendition: rendition.id } });
if (stale.stale) {
await praxis.studio.works.renditions.render({ path: { work, rendition: rendition.id } });
}
const exported = await praxis.studio.works.renditions.publish({ path: { work, rendition: rendition.id } });
console.log(exported.publish.state, exported.parts[0]?.text);

Validation and limits

  • A rendition’s platform must be one the genre can produce: creating xiaohongshu@1 from a blog_article draft returns 400 PLATFORM_GENRE_MISMATCH.
  • Platform keys carry a version: docx returns 404 PLATFORM_NOT_FOUND.
  • Rendering or exporting the same rendition twice at once returns 409 REVISION_CONFLICT; retry after a few seconds.
  • Publishing to a platform account (X, WeChat and so on) is not available yet and returns PLATFORM_NOT_AVAILABLE; export instead.

Limits and errors →