ContextRail AI Docs
API v1.2.0

ContextRail Developer API

ContextRail AI provides a semantic context routing and long-term memory fabric for autonomous AI agents powered by the Anthropic Claude API (Sonnet & Haiku).

All HTTP API requests must include your secret API key in the Authorization header:

Authorization: Bearer cr_live_your_api_key_here
Content-Type: application/json

1. Route & Compress Agent Context

Slices and compresses multi-turn conversation and tool inputs, inserting Anthropic prompt caching breakpoints (cache_control: {"type": "ephemeral"}) to minimize latency and token expenditure.

POST https://api.contextrail.cloud/v1/context/route

Example cURL Request:

curl -X POST https://api.contextrail.cloud/v1/context/route \
  -H "Authorization: Bearer cr_live_example" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-6",
    "agent_id": "nexus-agent-12",
    "messages": [
      {"role": "user", "content": "Review repository dependencies and summarize breaking changes."}
    ],
    "cache_optimization": true,
    "max_compression_ratio": 0.75
  }'

Success Response (HTTP 200 OK):

{
  "status": "success",
  "routed_tokens": 1420,
  "original_tokens": 5840,
  "cache_read_ratio": 0.82,
  "optimized_payload": {
    "system": [{"type": "text", "text": "...", "cache_control": {"type": "ephemeral"}}],
    "messages": [...]
  }
}

3. Model Context Protocol (MCP) Setup

Connect ContextRail directly to Claude Desktop or Claude Code CLI via our standardized MCP server card.

GET https://contextrail.cloud/.well-known/mcp/server-card.json
{
  "mcpServers": {
    "contextrail": {
      "command": "npx",
      "args": ["-y", "@contextrail/mcp-server"],
      "env": {
        "CONTEXTRAIL_API_KEY": "cr_live_your_key"
      }
    }
  }
}