API Reference
Routing Rules API

Routing Rules API

Routing rules determine which LLM handles each incoming query. Each rule maps a trigger phrase to a model, with optional caching and sample queries for evaluation. Use these endpoints to create, list, update, and delete routing rules.

Rule Object

{
  "id": "rule_01HXYZ",
  "name": "Code generation",
  "trigger_phrase": "write code",
  "llm_id": "gpt-4o",
  "cache_enabled": true,
  "sample_queries": [
    "Write a Python function to reverse a string",
    "Create a React component for a login form"
  ],
  "created_at": "2025-01-15T10:30:00Z",
  "updated_at": "2025-01-15T10:30:00Z"
}

Endpoints

MethodPathDescription
GET/routing-rulesList all routing rules
POST/routing-rulesCreate a new routing rule
PUT/routing-rules/{id}Update an existing rule
DELETE/routing-rules/{id}Delete a routing rule

List Routing Rules

GET /api/v1/routing-rules

Returns all routing rules for your organization.

Response

[
  {
    "id": "rule_01HXYZ",
    "name": "Code generation",
    "trigger_phrase": "write code",
    "llm_id": "gpt-4o",
    "cache_enabled": true,
    "sample_queries": [
      "Write a Python function to reverse a string"
    ],
    "created_at": "2025-01-15T10:30:00Z",
    "updated_at": "2025-01-15T10:30:00Z"
  }
]

cURL

curl https://api.xilos.ai/api/v1/routing-rules \
  -H "Authorization: Bearer YOUR_X..._KEY"

Create Routing Rule

POST /api/v1/routing-rules

Request Body

FieldTypeRequiredDescription
namestringYesHuman-readable name for the rule.
trigger_phrasestringYesPhrase that activates this rule when matched in the query.
llm_idstringYesModel ID to route matching queries to (e.g., gpt-4o).
cache_enabledbooleanNoWhether responses for this rule are cached. Default: false.
sample_queriesarrayNoList of example queries for evaluation and testing.

cURL

curl -X POST https://api.xilos.ai/api/v1/routing-rules \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_X..._KEY" \
  -d '{
    "name": "Code generation",
    "trigger_phrase": "write code",
    "llm_id": "gpt-4o",
    "cache_enabled": true,
    "sample_queries": [
      "Write a Python function to reverse a string",
      "Create a React component for a login form"
    ]
  }'

Response

{
  "id": "rule_01HXYZ",
  "name": "Code generation",
  "trigger_phrase": "write code",
  "llm_id": "gpt-4o",
  "cache_enabled": true,
  "sample_queries": [
    "Write a Python function to reverse a string",
    "Create a React component for a login form"
  ],
  "created_at": "2025-01-15T10:30:00Z",
  "updated_at": "2025-01-15T10:30:00Z"
}

Update Routing Rule

PUT /api/v1/routing-rules/{id}

Updates an existing routing rule. All fields are optional — only provided fields are updated.

Request Body

FieldTypeRequiredDescription
namestringNoUpdated name.
trigger_phrasestringNoUpdated trigger phrase.
llm_idstringNoUpdated model ID.
cache_enabledbooleanNoToggle caching.
sample_queriesarrayNoUpdated sample queries.

cURL

curl -X PUT https://api.xilos.ai/api/v1/routing-rules/rule_01HXYZ \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_X..._KEY" \
  -d '{
    "llm_id": "claude-3-5-sonnet",
    "cache_enabled": false
  }'

Response

Returns the updated rule object with the same fields as the Rule Object.


Delete Routing Rule

DELETE /api/v1/routing-rules/{id}

Deletes a routing rule. This action cannot be undone.

cURL

curl -X DELETE https://api.xilos.ai/api/v1/routing-rules/rule_01HXYZ \
  -H "Authorization: Bearer YOUR_X..._KEY"

Response

{
  "id": "rule_01HXYZ",
  "deleted": true
}

Warning: Deleting a routing rule is permanent. Any queries that previously matched this rule will fall back to the default routing behavior.

Working With Routing Rules

Create a Rule

Define a trigger phrase and the model that should handle matching queries.

Add Sample Queries

Include representative sample queries so you can evaluate routing accuracy in Eval Datasets.

Enable Caching

Turn on cache_enabled for queries with predictable, repeatable responses to reduce cost and latency.

Monitor and Adjust

Review query logs in the dashboard and update rules as your traffic patterns evolve.