{"openapi": "3.1.0", "info": {"title": "RelayLLM API", "version": "1.0.0", "description": "OpenAI-compatible chat completion API provided by RelayLLM."}, "servers": [{"url": "/", "description": "Current RelayLLM host"}], "components": {"securitySchemes": {"BearerAuth": {"type": "http", "scheme": "bearer", "description": "RELAY_API_KEY"}, "ApiKeyAuth": {"type": "apiKey", "in": "header", "name": "x-api-key"}, "AdminBearerAuth": {"type": "http", "scheme": "bearer", "description": "RELAY_ADMIN_KEY"}}, "schemas": {"ChatCompletionRequest": {"type": "object", "required": ["messages"], "properties": {"model": {"type": "string", "enum": ["flint-40b", "big-pickle", "beam", "deepseek-v4.1-flash", "glm-5.3-flash", "mimo-v2.6-flash", "nemotron-3.5-lightning"], "default": "flint-40b"}, "messages": {"type": "array", "items": {"$ref": "#/components/schemas/Message"}}, "stream": {"type": "boolean", "default": false}, "reasoning_effort": {"$ref": "#/components/schemas/Effort"}, "reasoning": {"type": "object", "properties": {"effort": {"$ref": "#/components/schemas/Effort"}}}, "effort": {"$ref": "#/components/schemas/Effort"}, "variant": {"$ref": "#/components/schemas/Effort"}}}, "Message": {"type": "object", "required": ["role", "content"], "properties": {"role": {"type": "string", "enum": ["system", "user", "assistant"]}, "content": {"oneOf": [{"type": "string"}, {"type": "array", "items": {"type": "object", "properties": {"text": {"type": "string"}}}}]}}}, "Effort": {"type": "string", "enum": ["default", "high", "low", "max", "medium", "minimal", "none"]}, "ModelList": {"type": "object", "required": ["object", "data"], "properties": {"object": {"const": "list"}, "data": {"type": "array", "items": {"$ref": "#/components/schemas/Model"}}}}, "Model": {"type": "object", "required": ["id", "object", "owned_by"], "properties": {"id": {"type": "string", "enum": ["flint-40b", "big-pickle", "beam", "deepseek-v4.1-flash", "glm-5.3-flash", "mimo-v2.6-flash", "nemotron-3.5-lightning"]}, "object": {"const": "model"}, "owned_by": {"const": "relayllm"}}}, "Usage": {"type": "object", "properties": {"prompt_tokens": {"type": "integer"}, "completion_tokens": {"type": "integer"}, "total_tokens": {"type": "integer"}}}, "ChatMessage": {"type": "object", "required": ["role", "content"], "properties": {"role": {"const": "assistant"}, "content": {"type": ["string", "null"]}, "reasoning_content": {"type": "string"}}}, "ChatChoice": {"type": "object", "required": ["index", "message", "finish_reason"], "properties": {"index": {"type": "integer"}, "message": {"$ref": "#/components/schemas/ChatMessage"}, "finish_reason": {"type": "string", "const": "stop"}}}, "ChatCompletion": {"type": "object", "required": ["id", "object", "created", "model", "choices", "usage"], "properties": {"id": {"type": "string", "example": "chatcmpl-abc123"}, "object": {"type": "string", "const": "chat.completion"}, "created": {"type": "integer"}, "model": {"type": "string"}, "choices": {"type": "array", "items": {"$ref": "#/components/schemas/ChatChoice"}}, "usage": {"$ref": "#/components/schemas/Usage"}}}, "ChatCompletionChunk": {"type": "object", "required": ["id", "object", "created", "model", "choices"], "properties": {"id": {"type": "string"}, "object": {"type": "string", "const": "chat.completion.chunk"}, "created": {"type": "integer"}, "model": {"type": "string"}, "choices": {"type": "array", "items": {"type": "object"}}}}, "Error": {"type": "object", "required": ["error"], "properties": {"error": {"type": "object", "required": ["message", "type"], "properties": {"message": {"type": "string"}, "type": {"type": "string"}, "code": {"type": ["string", "null"]}, "param": {"type": ["string", "null"]}, "details": {"type": "string"}}}}}}}, "security": [{"BearerAuth": []}, {"ApiKeyAuth": []}], "paths": {"/v1/models": {"get": {"summary": "List available models", "responses": {"200": {"description": "OpenAI-compatible model list", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ModelList"}}}}, "401": {"description": "Invalid API key", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}}}}, "/v1/chat/completions": {"post": {"summary": "Create a chat completion", "description": "Supports model, messages, stream, and per-request effort/variant. SSE chunks are forwarded as emitted by the generation process; the current CLI may emit the completed answer as one text event, so token-by-token delivery is not guaranteed.", "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ChatCompletionRequest"}}}}, "responses": {"200": {"description": "Chat completion; SSE chunks when stream=true", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ChatCompletion"}}, "text/event-stream": {"schema": {"type": "string", "description": "OpenAI SSE events ending with data: [DONE]"}}}}, "400": {"description": "Invalid request", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}, "401": {"description": "Invalid API key", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}, "429": {"description": "Relay concurrency limit or upstream rate limit", "headers": {"Retry-After": {"schema": {"type": "integer"}, "description": "Seconds to wait before retrying"}}, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}, "502": {"description": "All upstream attempts failed", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}, "504": {"description": "Upstream generation timed out", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}}}}, "/health": {"get": {"summary": "Health check", "security": [], "responses": {"200": {"description": "Relay health and counters"}}}}, "/admin/stats": {"get": {"summary": "Get per-key usage metrics", "security": [{"AdminBearerAuth": []}], "parameters": [{"name": "hours", "in": "query", "schema": {"type": "integer", "default": 24, "minimum": 1, "maximum": 720}}], "responses": {"200": {"description": "Aggregated request and routing metrics"}, "401": {"description": "Invalid admin key"}}}}, "/admin/audit": {"get": {"summary": "List security audit events", "security": [{"AdminBearerAuth": []}], "parameters": [{"name": "limit", "in": "query", "schema": {"type": "integer", "default": 100, "minimum": 1, "maximum": 500}}], "responses": {"200": {"description": "Sanitized administrative and authentication events"}, "401": {"description": "Invalid admin key"}}}}, "/admin/invites": {"get": {"summary": "List invite code status", "security": [{"AdminBearerAuth": []}], "responses": {"200": {"description": "Invite IDs and redemption status"}, "401": {"description": "Invalid admin key"}}}, "post": {"summary": "Generate random invite codes", "security": [{"AdminBearerAuth": []}], "requestBody": {"required": true, "content": {"application/json": {"schema": {"type": "object", "properties": {"count": {"type": "integer", "minimum": 1, "maximum": 100}}}}}}, "responses": {"201": {"description": "Generated codes are returned once"}, "401": {"description": "Invalid admin key"}}}}, "/admin": {"get": {"summary": "Operations dashboard UI", "security": [], "responses": {"200": {"description": "Admin dashboard HTML; metrics require admin authentication"}}}}}}