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
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
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)Interactive API Sandbox & Tester
Test Gateway endpoints live inside your browser. Select an endpoint to inspect payloads, execute requests, and examine response headers.
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
}
}Authentication & Security
All HTTP requests must include a Bearer Token in the `Authorization` header, or an `x-api-key` header.
Authorization: Bearer sylex_gw_live_xxxxxxxxxxxxx-api-key: sylex_gw_live_xxxxxxxxxxxxSecurity 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.
Routing Modes & Tiers
When you pass `model: "auto"`, Sylex dynamically evaluates prompt complexity and applies your specified `routing_mode`.
Auto Balanced (Default)
Evaluates prompt complexity, tool schemas, and output length to pick the optimal price-performance model.
Quality First
Prioritizes top intelligence models like Claude 3.5 Sonnet, GPT-4o, or DeepSeek R1.
Cost Optimized
Routes prompts to low-cost Flash/Mini models (GPT-4o-mini, Gemini 1.5 Flash) whenever capabilities permit.
Speed & Latency Priority
Selects the model region and provider with the lowest current p95 time-to-first-token.
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.
{
"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
}
}Budget & Cost Control Guardrails
Prevent runaway spending or unintentional looping scripts. Sylex calculates token costs before dispatching requests.
{
"model": "auto",
"messages": [{"role": "user", "content": "Bulk data processing..."}],
"sylex": {
"max_cost_usd": 0.02,
"budget_policy": "downgrade_or_reject"
}
}API Endpoint Reference
Create chat completions with SSE streaming, tool schema calling, and smart routing.
Generate vector embeddings using OpenAI or Gemini embedding models.
List active provider models, health status, and per-token pricing tiers.
Retrieve token consumption, monetary spend (USD), and latency metrics.
Circuit breaker status and uptime ping for OpenAI, Anthropic, Gemini, DeepSeek, and Mistral.
Response Metadata Headers
Every completion returned by Sylex AI Gateway includes HTTP diagnostic headers:
Error Codes & Status Payloads
Sylex returns standard HTTP status codes along with a JSON error payload matching OpenAI error formatting.
{
"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"
}
}