{
  "openapi": "3.1.0",
  "info": {
    "title": "Arjen API — Unified Multi-Model AI Gateway",
    "version": "2.0.0",
    "description": "Commercial multi-model AI gateway implementing OpenAI Chat Completions, OpenAI Responses, Anthropic Messages, Embeddings, Image Generation & Multipart Edits, and Async Media Jobs with double-entry USD billing."
  },
  "servers": [
    {
      "url": "https://api.arjensoft.com",
      "description": "Production Gateway"
    },
    {
      "url": "http://localhost:3000",
      "description": "Local Development"
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "Arjen API Key (arj_live_...)"
      },
      "anthropicKey": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key"
      }
    }
  },
  "security": [{ "bearerAuth": [] }],
  "paths": {
    "/v1/models": {
      "get": {
        "summary": "List active models permitted for this API key",
        "responses": { "200": { "description": "OpenAI-compatible model list" } }
      }
    },
    "/v1/chat/completions": {
      "post": {
        "summary": "OpenAI-compatible Chat Completions (streaming SSE and non-streaming)",
        "responses": {
          "200": { "description": "Chat completion JSON or text/event-stream" },
          "402": { "description": "Insufficient commercial USD balance" },
          "429": { "description": "Rate limit or concurrency limit exceeded" }
        }
      }
    },
    "/v1/responses": {
      "post": {
        "summary": "OpenAI Responses API (Codex CLI compatible, parallel tool calls, structured outputs)",
        "responses": {
          "200": { "description": "Response object or SSE event stream" },
          "402": { "description": "Insufficient balance" }
        }
      }
    },
    "/v1/messages": {
      "post": {
        "summary": "Anthropic Messages API (Claude Code compatible, prompt caching, extended thinking)",
        "security": [{ "anthropicKey": [] }, { "bearerAuth": [] }],
        "responses": {
          "200": { "description": "Anthropic Message JSON or SSE stream" },
          "402": { "description": "Insufficient balance" }
        }
      }
    },
    "/v1/messages/count_tokens": {
      "post": {
        "summary": "Estimate token count for Anthropic Messages payload",
        "security": [{ "anthropicKey": [] }, { "bearerAuth": [] }],
        "responses": { "200": { "description": "Token estimate" } }
      }
    },
    "/v1/embeddings": {
      "post": {
        "summary": "Generate vector embeddings",
        "responses": { "200": { "description": "Embeddings vector list" } }
      }
    },
    "/v1/images/generations": {
      "post": {
        "summary": "Generate images with private tenant-isolated signed storage",
        "responses": { "200": { "description": "Image data array with signed private URLs or b64_json" } }
      }
    },
    "/v1/images/edits": {
      "post": {
        "summary": "Edit images via multipart/form-data (binary magic-byte & MIME validated) or JSON",
        "responses": { "200": { "description": "Edited image response" } }
      }
    },
    "/v1/media/jobs": {
      "post": {
        "summary": "Create an asynchronous media generation job (video, image, audio)",
        "responses": { "202": { "description": "Accepted async media job" } }
      },
      "get": {
        "summary": "List async media jobs for the authenticated account",
        "responses": { "200": { "description": "Media job list" } }
      }
    },
    "/v1/media/jobs/{jobId}": {
      "get": {
        "summary": "Inspect status and signed output assets of an async media job",
        "parameters": [{ "name": "jobId", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Media job status" } }
      }
    },
    "/v1/media/jobs/{jobId}/cancel": {
      "post": {
        "summary": "Cancel a queued or running async media job and release unused reservation",
        "parameters": [{ "name": "jobId", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Cancelled job" } }
      }
    },
    "/livez": {
      "get": {
        "summary": "Liveness probe",
        "security": [],
        "responses": { "200": { "description": "Process alive" } }
      }
    },
    "/readyz": {
      "get": {
        "summary": "Readiness probe verifying database and Redis connectivity",
        "security": [],
        "responses": { "200": { "description": "Ready" }, "503": { "description": "Not ready" } }
      }
    }
  }
}
