Hangarx

API Reference

Chat Endpoint

POST/api/chat
// Headers
Authorization: Bearer <Firebase JWT>
Content-Type: application/json

// Request Body
{
  "messages": [
    { "role": "user", "content": "Research AI agents" }
  ],
  "model": "kimi-k2-thinking" | "huggingface-mixtral",
  "stream": true,
  "tools": ["search", "file", "image"] // optional
}

// Response: Server-Sent Events (SSE)
data: {"type":"text","content":"Based on..."}
data: {"type":"tool_call","name":"tavily_search",...}
data: {"type":"done"}

File Upload Endpoint

POST/api/files/upload
// Headers
Authorization: Bearer <Firebase JWT>
Content-Type: multipart/form-data

// Response
{
  "fileId": "blob_12345",
  "extractedText": "...",
  "metadata": {
    "pages": 12,
    "wordCount": 3456,
    "fileType": "application/pdf"
  }
}

Error Responses

401Invalid/expired Firebase token
402Subscription required or limit exceeded
413File too large
429Rate limit exceeded
500Service error (with error ID for support)

Retry Logic

// Built-in retry behavior
Tavily search:  3 retries with exponential backoff
Billing API:    5 retries with idempotency keys
Huggingface:    2 retries, fallback to alternative model