Sylex AI GatewayDeveloper Documentation

    AI Gateway & Router API Docs

    Integrate, route, govern, and optimize LLM requests across OpenAI, Anthropic, Gemini, DeepSeek, and open-source providers.

    API v1.0 Production Gateway
    1

    Quickstart SDK Integration

    Sylex AI Gateway acts as a high-performance, protocol-compatible proxy for official OpenAI SDKs in TypeScript/Node.js, Python, Go, and cURL. Update your SDK `baseURL` and provide your Sylex Gateway Key.

    TypeScript / Node.js SDK

    typescript
    import OpenAI from "openai";
    
    const openai = new OpenAI({
      apiKey: process.env.SYLEX_GATEWAY_KEY,
      baseURL: "https://api.sylexhq.com/api/v1/ai-gateway"
    });
    
    async function main() {
      const completion = await openai.chat.completions.create({
        model: "auto", // Sylex dynamically selects the optimal model
        messages: [
          { role: "system", content: "You are an assistant." },
          { role: "user", content: "Summarize this PDF report." }
        ],
        stream: true
      });
    
      for await (const chunk of completion) {
        process.stdout.write(chunk.choices[0]?.delta?.content || "");
      }
    }
    
    main();

    Python SDK

    python
    from openai import OpenAI
    import os
    
    client = OpenAI(
        api_key=os.environ.get("SYLEX_GATEWAY_KEY"),
        base_url="https://api.sylexhq.com/api/v1/ai-gateway"
    )
    
    response = client.chat.completions.create(
        model="auto",
        messages=[
            {"role": "user", "content": "Extract action items from transcript."}
        ],
        extra_body={
            "sylex": {
                "routing_mode": "quality",
                "max_cost_usd": 0.05
            }
        }
    )
    
    print(response.choices[0].message.content)
    2

    Interactive API Sandbox & Tester

    Test Gateway endpoints live inside your browser. Select an endpoint to inspect payloads, execute requests, and examine response headers.

    POST/api/v1/ai-gateway/chat/completions

    Request Payload

    {
      "model": "auto",
      "messages": [
        { "role": "system", "content": "You are an assistant." },
        { "role": "user", "content": "Analyze account #9482 risk telemetry." }
      ],
      "sylex": {
        "routing_mode": "quality",
        "max_cost_usd": 0.05,
        "fallback_chain": ["claude-3-5-sonnet", "gpt-4o", "gemini-1.5-pro"]
      }
    }

    Response Headers

    x-sylex-routed-model: claude-3-5-sonnet

    x-sylex-cost-usd: 0.00342

    x-sylex-latency-ms: 420

    x-sylex-fallback-position: 0

    Response JSON Body

    {
      "id": "sylex_chat_948201",
      "object": "chat.completion",
      "created": 1756598000,
      "model": "claude-3-5-sonnet",
      "choices": [
        {
          "index": 0,
          "message": {
            "role": "assistant",
            "content": "Account #9482 displays normal transaction velocity. Risk score: 0.02 (Low Risk)."
          },
          "finish_reason": "stop"
        }
      ],
      "usage": {
        "prompt_tokens": 145,
        "completion_tokens": 32,
        "total_tokens": 177
      }
    }
    3

    Authentication & Security

    All HTTP requests must include a Bearer Token in the `Authorization` header, or an `x-api-key` header.

    Standard HeaderAuthorization: Bearer sylex_gw_live_xxxxxxxxxxxx
    Alternative Headerx-api-key: sylex_gw_live_xxxxxxxxxxxx

    Security Guidance

    Never expose your secret `SYLEX_GATEWAY_KEY` in client-side browser code. Route requests through your backend services or use scope-restricted public app tokens with per-user rate limits.

    4

    Routing Modes & Tiers

    When you pass `model: "auto"`, Sylex dynamically evaluates prompt complexity and applies your specified `routing_mode`.

    mode: "auto"

    Auto Balanced (Default)

    Evaluates prompt complexity, tool schemas, and output length to pick the optimal price-performance model.

    mode: "quality"

    Quality First

    Prioritizes top intelligence models like Claude 3.5 Sonnet, GPT-4o, or DeepSeek R1.

    mode: "cost"

    Cost Optimized

    Routes prompts to low-cost Flash/Mini models (GPT-4o-mini, Gemini 1.5 Flash) whenever capabilities permit.

    mode: "latency"

    Speed & Latency Priority

    Selects the model region and provider with the lowest current p95 time-to-first-token.

    5

    Zero-Downtime Fallback Chains

    If your primary provider encounters rate limits (`429`), timeouts, or internal errors (`5xx`), Sylex retries through your fallback chain automatically in milliseconds.

    json
    {
      "model": "gpt-4o",
      "messages": [{"role": "user", "content": "Generate quarterly report"}],
      "sylex": {
        "fallback_chain": ["claude-3-5-sonnet", "gemini-1.5-pro", "deepseek-r1"],
        "max_retries": 3,
        "timeout_ms": 5000
      }
    }
    6

    Budget & Cost Control Guardrails

    Prevent runaway spending or unintentional looping scripts. Sylex calculates token costs before dispatching requests.

    json
    {
      "model": "auto",
      "messages": [{"role": "user", "content": "Bulk data processing..."}],
      "sylex": {
        "max_cost_usd": 0.02,
        "budget_policy": "downgrade_or_reject"
      }
    }
    7

    API Endpoint Reference

    POST/api/v1/ai-gateway/chat/completions

    Create chat completions with SSE streaming, tool schema calling, and smart routing.

    POST/api/v1/ai-gateway/embeddings

    Generate vector embeddings using OpenAI or Gemini embedding models.

    GET/api/v1/ai-gateway/models

    List active provider models, health status, and per-token pricing tiers.

    GET/api/v1/ai-gateway/usage

    Retrieve token consumption, monetary spend (USD), and latency metrics.

    GET/api/v1/ai-gateway/health

    Circuit breaker status and uptime ping for OpenAI, Anthropic, Gemini, DeepSeek, and Mistral.

    8

    Response Metadata Headers

    Every completion returned by Sylex AI Gateway includes HTTP diagnostic headers:

    HeaderDescription
    x-sylex-routed-modelThe exact provider model that executed the request (e.g. claude-3-5-sonnet)
    x-sylex-routed-providerThe underlying provider (openai, anthropic, google, deepseek)
    x-sylex-cost-usdCalculated monetary cost of the prompt + completion in USD
    x-sylex-latency-msTotal round-trip latency in milliseconds
    x-sylex-fallback-indexZero-indexed fallback position (0 = primary provider succeeded)
    9

    Error Codes & Status Payloads

    Sylex returns standard HTTP status codes along with a JSON error payload matching OpenAI error formatting.

    json
    {
      "error": {
        "message": "Monthly spending limit of $100.00 reached for Organization #402.",
        "type": "sylex_budget_exceeded_error",
        "param": "max_cost_usd",
        "code": "budget_cap_reached"
      }
    }

    We use cookies

    We use analytics cookies to understand how the site is used and improve it. They are only set if you accept. Cookie policy