/optimize

Optimize your prompt from one LLM to work optimally across different target LLMs.

This endpoint automatically optimizes your prompt (system prompt + user message template) to improve accuracy on your use case across various models. Each model has unique characteristics, and what works well for GPT-5 might not work as well for Claude or Gemini.

How Prompt Optimization Works:

  1. You provide your current prompt and optionally your current origin model
  2. You specify the target models you want to optimize your prompt to
  3. You provide evaluation examples (golden records) with expected answers
  4. The system runs optimization to find the best prompt for each target model
  5. You receive optimized prompts that perform well on your target models

Evaluation Metrics: Choose either a standard metric or provide custom evaluation:

  • Standard metrics: LLMaaJ:Sem_Sim_1 (semantic similarity), JSON_Match
  • Custom evaluation: Provide evaluation_config with your own LLM judge, prompt, and cutoff

Dataset Requirements:

  • Minimum 25 examples in train_goldens (more examples = better optimization)
  • Prototype mode: Set prototype_mode: true to use as few as 3 examples for prototyping
    • Recommended when you don't have enough data yet to build a proof-of-concept
    • Note: Performance may be degraded compared to standard mode (25+ examples)
    • Trade-off: Faster iteration with less data vs. potentially less generalizability
  • Each example must have fields matching your template placeholders
  • Supervised evaluation requires 'answer' field in each golden record
  • Unsupervised evaluation can work without answers

Training Time:

  • Processing is asynchronous and typically takes 10-30 minutes
  • Time depends on: number of target models, dataset size, model availability
  • Use the returned optimization_run_id to check status and retrieve results

Example Workflow:

1. POST /v2/prompt/optimize - Submit optimization request
2. GET /v2/prompt/optimizeStatus/{id} - Poll status until completed
3. GET /v2/prompt/optimizeResults/{id} - Retrieve optimized prompts
4. Use optimized prompts in production with target models
Body Params
string
required

System prompt to use with the origin model. This sets the context and role for the LLM

string
required

User message template with placeholders for fields. Use curly braces for field substitution

fields
array of strings
required

List of field names that will be substituted into the template. Must match keys in golden records

Fields*
goldens

Training examples (legacy parameter). Use train_goldens and test_goldens for better control. Minimum 25 examples (or 3 with prototype_mode=true)

train_goldens

Training examples for prompt optimization. Minimum 25 examples required (or 3 with prototype_mode=true). Cannot be used with 'goldens' parameter

test_goldens

Test examples for evaluation. Required if train_goldens is provided. Used to measure final performance on held-out data

origin_model

The model your current prompt is optimized for (baseline).

target_models
array of objects
required

List of models to optimize the prompt for. Maximum count depends on your subscription tier (Free: 1, Starter: 3, Startup: 5, Enterprise: 10)

Target Models*

Optional baseline score for the origin model. If provided, can skip origin model evaluation

boolean
Defaults to false

Enable prototype mode to use as few as 3 training examples (instead of 25). Note: Performance may be degraded with fewer examples. Recommended for prototyping AI applications when you don't have enough data yet

Responses

404

Not found

Language
Credentials
Bearer
LoadingLoading…
Response
Click Try It! to start a request and see the response here! Or choose an example:
application/json