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}}"
}'const res = await fetch('https://api.cruxy.ai/api/v1/prompts', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.CRUXY_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: 'Code Review',
slug: 'code-review',
content: 'You are a meticulous code reviewer. Review this diff:\n\n{{diff}}',
}),
})
if (!res.ok) throw new Error(`create failed: ${res.status} ${await res.text()}`)
const prompt = await res.json()
console.log(prompt.id, prompt.slug, prompt.version.version) // version 1| Field | Required | Meaning |
|---|---|---|
name | Yes | The display name, 1 to 128 bytes. |
content | Yes | The template text of version 1, 1 to 102,400 bytes. It is stored and returned verbatim. |
slug | No | A 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}}"
}'const promptId = process.env.PROMPT_ID // the id a create returned
const res = await fetch(`https://api.cruxy.ai/api/v1/prompts/${promptId}/versions`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.CRUXY_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
content: 'You are a meticulous code reviewer. Be concise. Review this diff:\n\n{{diff}}',
}),
})
if (!res.ok) throw new Error(`add version failed: ${res.status} ${await res.text()}`)
const version = await res.json()
console.log(version.prompt_id, version.version, version.created_at)A version carries prompt_id, version, content, created_by, and
created_at.
Read prompts and versions
| Call | Returns |
|---|---|
GET /api/v1/prompts | Every 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}/versions | Every 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" }
]
}'const promptId = process.env.PROMPT_ID
const headers = {
Authorization: `Bearer ${process.env.CRUXY_API_KEY}`,
'Content-Type': 'application/json',
}
// 1. Fetch the pinned version.
const promptRes = await fetch(`https://api.cruxy.ai/api/v1/prompts/${promptId}?version=2`, {
headers,
})
if (!promptRes.ok) throw new Error(`prompt fetch failed: ${promptRes.status}`)
const prompt = await promptRes.json()
// 2. Fill in the placeholder. The gateway does not do this for you.
const diff = '- const retries = 3\n+ const retries = 30'
const content = prompt.version.content.replaceAll('{{diff}}', diff)
// 3. Send it to chat.
const chatRes = await fetch('https://api.cruxy.ai/api/v1/chat', {
method: 'POST',
headers,
body: JSON.stringify({
model: 'saga',
stream: false,
messages: [{ role: 'user', content }],
}),
})
if (!chatRes.ok) throw new Error(`chat failed: ${chatRes.status} ${await chatRes.text()}`)
const completion = await chatRes.json()
console.log(`prompt v${prompt.version.version}:`, completion.message.content)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
| Status | code | When |
|---|---|---|
400 | invalid_request | A missing or empty name or content, or a field over its size. |
404 | prompt_not_found | The id is not a prompt in your workspace. |
404 | prompt_version_not_found | The prompt exists and has no such version. |
409 | prompt_slug_exists | The slug is already used in the workspace. |
413 | payload_too_large | The 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.