Skip to Content

Prompts

The prompts endpoints let you retrieve the active prompt for a task and manage prompt versions. Active prompts are served from Redis cache for low-latency reads, making them suitable for use in the hot path of your LLM application.

Endpoints

MethodPathDescription
GET/api/v1/prompts/\{task_id\}Get the active prompt (Redis-cached)
POST/api/v1/prompts/\{task_id\}/activateActivate a prompt version
GET/api/v1/prompts/\{task_id\}/versionsList all prompt versions

GET /api/v1/prompts/{task_id}

Return the active prompt for a task. The response is served from Redis cache when available, falling back to PostgreSQL on a cache miss.

Authentication: Required (X-API-Key)

Path Parameters

ParameterTypeDescription
task_idUUIDThe task’s unique identifier

Active prompts are cached in Redis with a 5-minute TTL. Activating a new version immediately invalidates the cache so the next request always returns the latest active prompt.

Example Request

curl -H "X-API-Key: kaizen_abc123" \ "http://localhost:8000/api/v1/prompts/550e8400-e29b-41d4-a716-446655440000"

Response — 200 OK

{ "id": "c3d4e5f6-a7b8-9012-cdef-012345678901", "task_id": "550e8400-e29b-41d4-a716-446655440000", "version_number": 3, "prompt_text": "You are an expert support engineer. Given a support ticket, write a concise summary...", "eval_score": 0.87, "status": "active", "optimizer": "MIPROv2", "dspy_version": "2.4.1", "created_at": "2024-01-15T09:00:00Z" }

Response Fields

FieldTypeDescription
idUUIDPrompt version unique identifier
task_idUUIDTask this prompt belongs to
version_numberintegerMonotonically increasing version number
prompt_textstringThe full prompt text
eval_scorefloatEvaluation score from optimization (0.0–1.0)
statusstring"active", "draft", or "archived"
optimizerstringOptimizer used (e.g., "MIPROv2")
dspy_versionstringDSPy version used during optimization
created_atdatetimeWhen this version was created

Error Cases

StatusCondition
401Missing or invalid API key
404Task not found, or task has no active prompt

POST /api/v1/prompts/{task_id}/activate

Promote a draft prompt version to active status. The current active version is archived automatically. The Redis cache for this task is invalidated immediately.

Authentication: Required (X-API-Key)

Path Parameters

ParameterTypeDescription
task_idUUIDThe task’s unique identifier

Query Parameters

ParameterTypeRequiredDescription
version_idUUIDThe ID of the draft prompt version to activate

Example Request

curl -X POST \ "http://localhost:8000/api/v1/prompts/550e8400-e29b-41d4-a716-446655440000/activate?version_id=d4e5f6a7-b8c9-0123-defa-123456789012" \ -H "X-API-Key: kaizen_abc123"

Response — 200 OK

Returns the newly activated PromptResponse object.

Error Cases

StatusCondition
401Missing or invalid API key
404Task not found, or prompt version not found for this task
409The version is not in "draft" status (e.g., already "active" or "archived")

GET /api/v1/prompts/{task_id}/versions

List all prompt versions for a task, ordered by version number descending (newest first).

Authentication: Required (X-API-Key)

Path Parameters

ParameterTypeDescription
task_idUUIDThe task’s unique identifier

Example Request

curl -H "X-API-Key: kaizen_abc123" \ "http://localhost:8000/api/v1/prompts/550e8400-e29b-41d4-a716-446655440000/versions"

Response — 200 OK

[ { "id": "c3d4e5f6-a7b8-9012-cdef-012345678901", "task_id": "550e8400-e29b-41d4-a716-446655440000", "version_number": 3, "prompt_text": "You are an expert support engineer...", "eval_score": 0.87, "status": "active", "optimizer": "MIPROv2", "dspy_version": "2.4.1", "created_at": "2024-01-15T09:00:00Z" }, { "id": "b3c4d5e6-a7b8-9012-cdef-012345678900", "task_id": "550e8400-e29b-41d4-a716-446655440000", "version_number": 2, "prompt_text": "Given a support ticket, summarize the issue in one sentence.", "eval_score": 0.79, "status": "archived", "optimizer": "MIPROv2", "dspy_version": "2.4.1", "created_at": "2024-01-10T14:00:00Z" }, { "id": "a3b4c5d6-e7f8-9012-abcd-ef1234567899", "task_id": "550e8400-e29b-41d4-a716-446655440000", "version_number": 1, "prompt_text": "Summarize this support ticket.", "eval_score": null, "status": "archived", "optimizer": null, "dspy_version": null, "created_at": "2024-01-05T12:00:00Z" } ]

Prompt Statuses

StatusDescription
activeCurrently serving prompt (only one per task)
draftCreated by optimization, awaiting manual activation or auto-PR review
archivedPreviously active, now superseded

Error Cases

StatusCondition
401Missing or invalid API key
404Task not found
Last updated on