Skip to Content

Jobs

Optimization jobs represent asynchronous DSPy compilation runs. When optimization is triggered (either automatically at threshold or via the Optimize endpoint), a job is created and processed by the Celery worker. You can poll the job status to track progress and retrieve the PR URL when done.

Endpoints

MethodPathDescription
GET/api/v1/jobsList optimization jobs
GET/api/v1/jobs/\{job_id\}Get job details
POST/api/v1/jobs/\{job_id\}/retry-prRetry PR creation

Job Statuses

StatusDescription
PENDINGJob created, waiting for worker to pick it up
RUNNINGWorker has started the optimization process
EVALUATINGRunning evaluation against the validation set
COMPILINGDSPy MIPROv2 compilation in progress
SUCCESSOptimization completed, PR created (if configured)
FAILEDOptimization failed (see error_message)
PR_FAILEDOptimization succeeded but PR creation failed — use retry-pr

GET /api/v1/jobs

List optimization jobs, optionally filtered by task. Returns newest jobs first.

Authentication: Required (X-API-Key)

Query Parameters

ParameterTypeDescription
task_idUUID (string)Filter by task ID
limitintegerNumber of results (default: 50, max: 200)
offsetintegerNumber of jobs to skip (default: 0)

Example Request

curl -H "X-API-Key: kaizen_abc123" \ "http://localhost:8000/api/v1/jobs?task_id=550e8400-e29b-41d4-a716-446655440000&limit=10"

Response — 200 OK

[ { "id": "f1e2d3c4-b5a6-7890-fedc-ba0987654321", "task_id": "550e8400-e29b-41d4-a716-446655440000", "prompt_version_id": "c3d4e5f6-a7b8-9012-cdef-012345678901", "status": "SUCCESS", "triggered_by": "auto_threshold", "feedback_count": 52, "pr_url": "https://github.com/myorg/myrepo/pull/42", "error_message": null, "job_metadata": { "teacher_model": "gpt-4o", "judge_model": "gpt-4o-mini", "trials_completed": 10, "duration_seconds": 184, "train_size": 41, "val_size": 11, "cost_usd": 0.34 }, "progress_step": "pr_created", "started_at": "2024-01-15T10:30:00Z", "completed_at": "2024-01-15T10:33:04Z", "created_at": "2024-01-15T10:29:55Z" } ]

GET /api/v1/jobs/{job_id}

Get details for a specific optimization job.

Authentication: Required (X-API-Key)

Path Parameters

ParameterTypeDescription
job_idUUIDThe job’s unique identifier

Example Request

curl -H "X-API-Key: kaizen_abc123" \ "http://localhost:8000/api/v1/jobs/f1e2d3c4-b5a6-7890-fedc-ba0987654321"

Response — 200 OK

Returns a single JobResponse object. See List Jobs for the full field list.

Response Fields

FieldTypeDescription
idUUIDJob unique identifier
task_idUUIDTask this job ran for
prompt_version_idUUIDID of the prompt version created by this job (null until completion)
statusstringCurrent job status (see Job Statuses)
triggered_bystring"auto_threshold" or "api_on_demand"
feedback_countintegerNumber of feedback entries used for training
pr_urlstringGitHub/GitLab PR URL (null if not yet created)
error_messagestringError details if job failed
job_metadataobjectOptimization metadata: models, trial count, duration, cost
progress_stepstringCurrent or final step description
started_atdatetimeWhen the worker started processing
completed_atdatetimeWhen the job finished
created_atdatetimeWhen the job was created

Polling Pattern

Use this pattern to poll until the job completes:

#!/bin/bash JOB_ID="f1e2d3c4-b5a6-7890-fedc-ba0987654321" API_KEY="kaizen_abc123" while true; do STATUS=$(curl -s -H "X-API-Key: $API_KEY" \ "http://localhost:8000/api/v1/jobs/$JOB_ID" | jq -r '.status') echo "Status: $STATUS" if [[ "$STATUS" == "SUCCESS" || "$STATUS" == "FAILED" || "$STATUS" == "PR_FAILED" ]]; then break fi sleep 5 done

Error Cases

StatusCondition
401Missing or invalid API key
404Job not found

POST /api/v1/jobs/{job_id}/retry-pr

Retry GitHub/GitLab PR creation for a job that completed optimization but failed to create the PR (status PR_FAILED). This re-uses the already-compiled prompt version.

Authentication: Required (X-API-Key)

Path Parameters

ParameterTypeDescription
job_idUUIDThe job’s unique identifier

Example Request

curl -X POST \ "http://localhost:8000/api/v1/jobs/f1e2d3c4-b5a6-7890-fedc-ba0987654321/retry-pr" \ -H "X-API-Key: kaizen_abc123"

Response — 200 OK

Returns the updated JobResponse object with status SUCCESS and the new pr_url if the retry succeeded.

Error Cases

StatusCondition
401Missing or invalid API key
404Job not found, or associated prompt version not found
409Job status is not PR_FAILED
502PR creation failed again (error in detail field)

If retry-pr returns 502, check your Git token permissions and repository configuration on the task. Ensure the token has write access to the repository.

Last updated on