{
  "openapi": "3.1.0",
  "info": {
    "title": "Zettalgor AI API",
    "version": "1.0.0",
    "description": "High-performance Apple Silicon Unified Memory LLM & Agent Platform API (OpenAI Compatible, v0.39.115).",
    "contact": {
      "name": "Zettalgor Developer Platform",
      "url": "https://zettalgor.com/zai_apidocs",
      "email": "support@zettalgor.com"
    }
  },
  "servers": [
    {
      "url": "https://api.zettalgor.com",
      "description": "Production REST API (Gunicorn Port 8030)"
    },
    {
      "url": "http://127.0.0.1:8030",
      "description": "Local Direct Host"
    }
  ],
  "paths": {
    "/v1/chat/completions": {
      "post": {
        "summary": "Create chat completion",
        "description": "Generate streaming or non-streaming responses with support for Fast-lane profiles, thinking controls, JSON schema outputs, and asynchronous webhooks.",
        "security": [
          {
            "BearerAuth": []
          },
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "name": "X-Zetta-Profile",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "fast",
                "coding",
                "deep",
                "balanced"
              ],
              "default": "fast"
            },
            "description": "Fast-lane task profile preset"
          },
          {
            "name": "X-Webhook-URL",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uri"
            },
            "description": "Callback URL to receive completion asynchronously"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatCompletionRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful completion",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChatCompletionResponse"
                }
              },
              "text/event-stream": {
                "description": "Server-Sent Events streaming chunks"
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/400Error"
          },
          "401": {
            "$ref": "#/components/responses/401Error"
          },
          "429": {
            "$ref": "#/components/responses/429Error"
          }
        }
      }
    },
    "/v1/completions": {
      "post": {
        "summary": "Create text completion",
        "security": [
          {
            "BearerAuth": []
          },
          {
            "ApiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CompletionRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful text completion"
          }
        }
      }
    },
    "/v1/models": {
      "get": {
        "summary": "List available models",
        "description": "List all active models identified strictly by their canonical 'id' without raw filepaths.",
        "security": [
          {
            "BearerAuth": []
          },
          {
            "ApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "List of models",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ModelListResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/agents/runs": {
      "post": {
        "summary": "Launch autonomous background agent task",
        "description": "Enqueues an autonomous multi-step agent task on Celery background workers. Returns 202 Accepted with a run ID.",
        "security": [
          {
            "BearerAuth": []
          },
          {
            "ApiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AgentRunRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Agent task enqueued",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentRunResponse"
                }
              }
            }
          }
        }
      },
      "get": {
        "summary": "List recent agent runs",
        "security": [
          {
            "BearerAuth": []
          },
          {
            "ApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "List of recent agent runs"
          }
        }
      }
    },
    "/v1/agents/runs/{run_id}": {
      "get": {
        "summary": "Get agent run status and result",
        "description": "Poll the progress (queued, in_progress, completed, failed) and retrieve the final completion result.",
        "security": [
          {
            "BearerAuth": []
          },
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "name": "run_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Agent run detail",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentRunDetailResponse"
                }
              }
            }
          },
          "404": {
            "description": "Run not found or expired"
          }
        }
      }
    },
    "/v1/performance_mode": {
      "get": {
        "summary": "Inspect performance mode",
        "description": "Get current cluster execution profile (turbo vs balanced).",
        "security": [
          {
            "BearerAuth": []
          },
          {
            "ApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Performance mode info"
          }
        }
      },
      "post": {
        "summary": "Configure performance mode",
        "security": [
          {
            "BearerAuth": []
          },
          {
            "ApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Updated performance mode"
          }
        }
      }
    },
    "/v1/thinking/config": {
      "get": {
        "summary": "Get thinking and reasoning configuration",
        "description": "Returns supported reasoning_effort levels and thinking parameters.",
        "security": [
          {
            "BearerAuth": []
          },
          {
            "ApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Thinking configuration parameters"
          }
        }
      }
    },
    "/v1/concurrency/status": {
      "get": {
        "summary": "Get real-time concurrency status",
        "description": "Returns real-time active slots, queued requests, and queue wait times.",
        "security": [
          {
            "BearerAuth": []
          },
          {
            "ApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Concurrency slot status"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API Key",
        "description": "Zettalgor API key as Bearer token"
      },
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "Zettalgor API key via custom header"
      }
    },
    "schemas": {
      "ChatCompletionRequest": {
        "type": "object",
        "required": [
          "model",
          "messages"
        ],
        "properties": {
          "model": {
            "type": "string",
            "enum": [
              "QWEN3.6-35B-MLX",
              "QWEN3.5-9B-MLX"
            ],
            "example": "ALL TASK"
          },
          "messages": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "role",
                "content"
              ],
              "properties": {
                "role": {
                  "type": "string",
                  "enum": [
                    "system",
                    "user",
                    "assistant",
                    "tool"
                  ]
                },
                "content": {
                  "type": "string"
                }
              }
            }
          },
          "stream": {
            "type": "boolean",
            "default": false
          },
          "temperature": {
            "type": "number",
            "default": 0.7
          },
          "max_tokens": {
            "type": "integer",
            "default": 2048
          },
          "response_format": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "text",
                  "json_object",
                  "json_schema"
                ]
              },
              "json_schema": {
                "type": "object"
              }
            }
          },
          "profile": {
            "type": "string",
            "enum": [
              "fast",
              "coding",
              "deep",
              "balanced"
            ],
            "default": "fast"
          },
          "webhook_url": {
            "type": "string",
            "format": "uri"
          }
        }
      },
      "ChatCompletionResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "object": {
            "type": "string",
            "example": "chat.completion"
          },
          "created": {
            "type": "integer"
          },
          "model": {
            "type": "string"
          },
          "choices": {
            "type": "array"
          },
          "usage": {
            "type": "object",
            "properties": {
              "prompt_tokens": {
                "type": "integer"
              },
              "completion_tokens": {
                "type": "integer"
              },
              "total_tokens": {
                "type": "integer"
              },
              "prompt_tokens_details": {
                "type": "object",
                "properties": {
                  "cached_tokens": {
                    "type": "integer"
                  }
                }
              }
            }
          }
        }
      },
      "CompletionRequest": {
        "type": "object",
        "required": [
          "model",
          "prompt"
        ],
        "properties": {
          "model": {
            "type": "string",
            "enum": [
              "QWEN3.6-35B-MLX",
              "QWEN3.5-9B-MLX"
            ],
            "example": "ALL TASK"
          },
          "prompt": {
            "type": "string"
          },
          "max_tokens": {
            "type": "integer",
            "default": 2048
          },
          "temperature": {
            "type": "number",
            "default": 0.7
          }
        }
      },
      "AgentRunRequest": {
        "type": "object",
        "required": [
          "messages"
        ],
        "properties": {
          "model": {
            "type": "string",
            "enum": [
              "QWEN3.6-35B-MLX",
              "QWEN3.5-9B-MLX"
            ],
            "default": "ALL TASK"
          },
          "messages": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "instructions": {
            "type": "string"
          },
          "agent_id": {
            "type": "string"
          },
          "profile": {
            "type": "string",
            "enum": [
              "fast",
              "coding",
              "deep",
              "balanced"
            ],
            "default": "fast"
          },
          "webhook_url": {
            "type": "string",
            "format": "uri"
          }
        }
      },
      "AgentRunResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "run_a1b2c3d4e5f67890"
          },
          "object": {
            "type": "string",
            "example": "agent.run"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "in_progress",
              "completed",
              "failed"
            ]
          },
          "created_at": {
            "type": "integer"
          },
          "model": {
            "type": "string"
          }
        }
      },
      "AgentRunDetailResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "result": {
            "$ref": "#/components/schemas/ChatCompletionResponse"
          },
          "elapsed_seconds": {
            "type": "number"
          }
        }
      },
      "ModelListResponse": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "example": "list"
          },
          "data": {
            "type": "array"
          }
        }
      }
    },
    "responses": {
      "400Error": {
        "description": "Invalid request parameter or syntax"
      },
      "401Error": {
        "description": "Missing or invalid API key"
      },
      "429Error": {
        "description": "Concurrency slot limit reached, queue wait timeout"
      }
    }
  }
}