Docs v1.0
Documentation
HTTP API Specification
REST & SSE

Public API Reference

Complete endpoint documentation for the Flexlora AI Gateway. Base URL is https://api.flexlora.com/v1.

Authentication & Standard Headers

Every request requires a Bearer token in the Authorization header. Keys start with flx-.

Authorization: Bearer flx-live-1234567890abcdef12345678

Content-Type: application/json

Idempotency-Key: 9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d (Optional: prevents double-billing on network retry)

POST

/v1/chat/completions

OpenAI-compatible chat completion endpoint supporting standard JSON payloads and real-time Server-Sent Events (SSE) streaming.

Request Parameters

FieldTypeRequiredDescription
modelstring
Yes
Model alias, such as flexlora:fast or flexlora:smart.
messagesarray
Yes
Array of message objects ({role: "system"|"user"|"assistant", content: string}).
streamboolean
No
Defaults to false. Set to true to receive Server-Sent Events (SSE).
temperaturenumber
No
Sampling temperature between 0 and 2. Defaults to 0.7.
max_tokensinteger
No
Maximum number of completion tokens to generate.

Request Payload (JSON)

POST https://api.flexlora.com/v1/chat/completionsjson
{
  "model": "flexlora:fast",
  "messages": [
    { "role": "system", "content": "You are a concise engineering assistant." },
    { "role": "user", "content": "Write a high-throughput debounce function." }
  ],
  "temperature": 0.7,
  "max_tokens": 2048,
  "stream": false
}

Non-Streaming Response (200 OK)

Response (200 OK)json
{
  "id": "chatcmpl-flx-9a8b7c6d",
  "object": "chat.completion",
  "created": 1729000000,
  "model": "flexlora:fast",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Here is a type-safe debounce function in TypeScript..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 28,
    "completion_tokens": 142,
    "total_tokens": 170
  }
}

Streaming Response (SSE: stream=true)

SSE Stream (text/event-stream)http
data: {"id":"chatcmpl-flx-101","object":"chat.completion.chunk","created":1729000000,"model":"flexlora:fast","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}

data: {"id":"chatcmpl-flx-101","object":"chat.completion.chunk","created":1729000000,"model":"flexlora:fast","choices":[{"index":0,"delta":{"content":"2, "},"finish_reason":null}]}

data: {"id":"chatcmpl-flx-101","object":"chat.completion.chunk","created":1729000000,"model":"flexlora:fast","choices":[{"index":0,"delta":{"content":"3, 5, 7, 11."},"finish_reason":"stop"}]}

data: [DONE]
POST

/v1/messages

Anthropic-compatible messages endpoint. Directly accepts Anthropic prompt schemas, top-level system instructions, and tool calling arrays.

Anthropic Request Payload (JSON)

POST https://api.flexlora.com/v1/messagesjson
{
  "model": "flexlora:smart",
  "max_tokens": 4096,
  "system": "You are an expert technical architect.",
  "messages": [
    { "role": "user", "content": "Explain how edge semantic caching works." }
  ],
  "stream": false
}

Anthropic Response Payload (200 OK)

Response (200 OK)json
{
  "id": "msg-flx-5e4d3c2b",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "Edge semantic caching operates close to users..."
    }
  ],
  "model": "flexlora:smart",
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 34,
    "output_tokens": 380
  }
}
GET

/v1/models

Returns all available active models, alias definitions, context windows, and capability flags on your account.

GET https://api.flexlora.com/v1/modelsjson
{
  "object": "list",
  "data": [
    {
      "id": "flexlora:fast",
      "object": "model",
      "created": 1729000000,
      "owned_by": "flexlora",
      "context_window": 128000,
      "capabilities": ["chat", "streaming", "json_mode"]
    },
    {
      "id": "flexlora:smart",
      "object": "model",
      "created": 1729000000,
      "owned_by": "flexlora",
      "context_window": 200000,
      "capabilities": ["chat", "streaming", "vision", "reasoning"]
    }
  ]
}

Standard Error Envelopes & HTTP Status Codes

All gateway errors return a consistent JSON envelope with a machine-readable code and actionable message:

Error Envelope (JSON)json
{
  "error": {
    "message": "Daily budget limit of $5.00 exceeded for this API key.",
    "type": "budget_exceeded",
    "code": "DAILY_BUDGET_EXCEEDED"
  }
}
Status CodeError CodeResolution Guidance
401 UnauthorizedINVALID_API_KEYThe API key is missing, revoked, or invalid. Verify your key in the console.
402 Payment RequiredINSUFFICIENT_BALANCEActive FIFO credit batches are exhausted or expired. Top up credits via bKash or card.
403 ForbiddenACCOUNT_SUSPENDEDThe account or key has been locked. Contact support@flexlora.com.
429 Too Many RequestsBUDGET_EXCEEDEDThe key has reached its configured daily or monthly spend cap. Adjust caps in console.
429 Too Many RequestsRATE_LIMIT_EXCEEDEDRequest concurrency or RPM limit reached. Back off with exponential jitter.
502 Bad GatewayUPSTREAM_ERRORUpstream cluster timeout or failure. The gateway auto-retries across redundant replicas.