Prompts

Store a prompt under a stable name, add immutable versions as you revise it, and fetch a version at runtime to send to chat.

A prompt is a named container for template text that you revise over time. Each revision is an immutable, numbered version, so the text a release was tested with is always retrievable. Prompts live in the workspace your key names: there is no workspace or organization id in any path or body, and no way to address another workspace.

Create a prompt

POST /api/v1/prompts creates a prompt whose first version holds the content you send.

curl https://api.cruxy.ai/api/v1/prompts \
  -H "Authorization: Bearer $CRUXY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Code Review",
    "slug": "code-review",
    "content": "You are a meticulous code reviewer. Review this diff:\n\n{{diff}}"
  }'
FieldRequiredMeaning
nameYesThe display name, 1 to 128 bytes.
contentYesThe template text of version 1, 1 to 102,400 bytes. It is stored and returned verbatim.
slugNoA stable, URL-safe handle. Omitted, it is derived from the name: lowercased, with runs of other characters collapsed to hyphens. Send it yourself when the name has no usable characters.

A slug already used in the workspace is 409 prompt_slug_exists. The 201 is the prompt with its version 1 embedded under version.

Add a version

POST /api/v1/prompts/{id}/versions appends a new version. Its number is the previous highest plus one, and existing versions are never modified.

curl https://api.cruxy.ai/api/v1/prompts/$PROMPT_ID/versions \
  -H "Authorization: Bearer $CRUXY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "You are a meticulous code reviewer. Be concise. Review this diff:\n\n{{diff}}"
  }'

A version carries prompt_id, version, content, created_by, and created_at.

Read prompts and versions

CallReturns
GET /api/v1/promptsEvery prompt in the workspace, oldest first, each with its slug, latest_version, and version_count, without content.
GET /api/v1/prompts/{id}One prompt with a single version embedded: the latest, or the one version names, as in ?version=2.
GET /api/v1/prompts/{id}/versionsEvery version of the prompt, newest first, each with its content.
DELETE /api/v1/prompts/{id}Nothing: 204. The prompt and all of its versions are deleted.

A prompt id in another workspace or organization, or one that names nothing, is 404 prompt_not_found. A version the prompt does not have is 404 prompt_version_not_found.

Use a prompt in chat

A chat request has no field that names a stored prompt, and the gateway returns content verbatim. So your code fetches the version it wants, fills in any placeholders its own templates use, and sends the text as a message. Pin a version number in production, so that adding a version never changes what a deployed build sends.

# 1. Fetch version 2 of the prompt and read its content.
curl "https://api.cruxy.ai/api/v1/prompts/$PROMPT_ID?version=2" \
  -H "Authorization: Bearer $CRUXY_API_KEY"
 
# 2. Send the content, with your own values filled in, as the system message.
curl https://api.cruxy.ai/api/v1/chat \
  -H "Authorization: Bearer $CRUXY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "saga",
    "stream": false,
    "messages": [
      { "role": "system", "content": "You are a meticulous code reviewer. Be concise." },
      { "role": "user", "content": "Review this diff:\n\n- const retries = 3\n+ const retries = 30" }
    ]
  }'

The {{diff}} marker is this sample's own convention. Use whatever placeholder syntax suits your templates; the gateway treats the content as opaque text.

An eval suite can record which prompt it tests: prompt_id on POST /api/v1/evals/suites links a prompt in the same workspace. The link is advisory metadata, and an eval run sends each case's input as it is.

Errors

StatuscodeWhen
400invalid_requestA missing or empty name or content, or a field over its size.
404prompt_not_foundThe id is not a prompt in your workspace.
404prompt_version_not_foundThe prompt exists and has no such version.
409prompt_slug_existsThe slug is already used in the workspace.
413payload_too_largeThe request body is over the route's 64 KiB limit.

See Errors and retries for the envelope and what to retry.

Next steps

  • Chat: the request the prompt's content goes into.
  • Prompting basics: what to put in a prompt.
  • API Reference: every prompt operation with its exact request and response shape.

Was this page helpful?