Skip to content

Optimize API

Cost optimization endpoint. Analyzes LLM call patterns and returns model switch recommendations.

GET /api/optimize/recommendations

Returns cost optimization recommendations based on LLM call patterns in the specified period.

Query Parameters

ParameterTypeDefaultRangeDescription
agentIdstringFilter to a specific agent
periodnumber71–90Analysis period in days
limitnumber101–50Maximum recommendations to return

Response (200)

json
{
  "recommendations": [
    {
      "currentModel": "gpt-4o",
      "recommendedModel": "gpt-4o-mini",
      "complexityTier": "simple",
      "currentCostPerCall": 0.0120,
      "recommendedCostPerCall": 0.0003,
      "monthlySavings": 89.20,
      "callVolume": 1203,
      "currentSuccessRate": 0.98,
      "recommendedSuccessRate": 0.97,
      "confidence": "high",
      "agentId": "my-agent"
    },
    {
      "currentModel": "claude-3-opus",
      "recommendedModel": "claude-3-sonnet",
      "complexityTier": "moderate",
      "currentCostPerCall": 0.0450,
      "recommendedCostPerCall": 0.0120,
      "monthlySavings": 53.30,
      "callVolume": 644,
      "currentSuccessRate": 0.95,
      "recommendedSuccessRate": 0.93,
      "confidence": "medium",
      "agentId": "my-agent"
    }
  ],
  "totalPotentialSavings": 142.50,
  "period": 7,
  "analyzedCalls": 3847
}

Response Fields

FieldTypeDescription
recommendationsarraySorted by monthlySavings descending
recommendations[].currentModelstringModel currently in use
recommendations[].recommendedModelstringSuggested cheaper alternative
recommendations[].complexityTierstringsimple, moderate, or complex
recommendations[].currentCostPerCallnumberAverage cost per call with current model (USD)
recommendations[].recommendedCostPerCallnumberEstimated cost per call with recommended model (USD)
recommendations[].monthlySavingsnumberProjected monthly savings (USD)
recommendations[].callVolumenumberNumber of calls analyzed
recommendations[].currentSuccessRatenumberSuccess rate with current model (0–1)
recommendations[].recommendedSuccessRatenumberEstimated success rate with recommended model (0–1)
recommendations[].confidencestringlow, medium, or high
recommendations[].agentIdstringAgent this recommendation applies to
totalPotentialSavingsnumberSum of all recommendation savings (USD/month)
periodnumberAnalysis period used (days)
analyzedCallsnumberTotal LLM calls analyzed

Errors

StatusCondition
400Invalid period or limit parameter

Released under the MIT License.