{
  "openapi": "3.1.0",
  "info": {
    "title": "DomiMuse API",
    "version": "1.4.3",
    "description": "Multi-tenant API for DomiMuse-35B with OpenAI Chat Completions and Anthropic Messages compatibility. Supports Claude Code tool use, text, vision, SSE streaming, structured output, URL grounding, and tenant-isolated usage."
  },
  "servers": [
    {
      "url": "https://DomiMuse.sonari.dev",
      "description": "Production"
    }
  ],
  "tags": [
    {
      "name": "Status"
    },
    {
      "name": "Models"
    },
    {
      "name": "Chat"
    },
    {
      "name": "Claude Code"
    },
    {
      "name": "Usage"
    }
  ],
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "DomiMuse API key"
      },
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "message",
              "type",
              "request_id"
            ],
            "properties": {
              "message": {
                "type": "string"
              },
              "type": {
                "type": "string"
              },
              "param": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "code": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "retryable": {
                "type": "boolean"
              },
              "retry_after_seconds": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "request_id": {
                "type": "string"
              }
            }
          }
        }
      },
      "TextPart": {
        "type": "object",
        "required": [
          "type",
          "text"
        ],
        "properties": {
          "type": {
            "const": "text"
          },
          "text": {
            "type": "string"
          }
        }
      },
      "ImagePart": {
        "type": "object",
        "required": [
          "type",
          "image_url"
        ],
        "properties": {
          "type": {
            "const": "image_url"
          },
          "image_url": {
            "type": "object",
            "required": [
              "url"
            ],
            "properties": {
              "url": {
                "type": "string",
                "description": "PNG or JPEG data URL; maximum one current image and 5 MB."
              }
            }
          }
        }
      },
      "Message": {
        "type": "object",
        "required": [
          "role",
          "content"
        ],
        "properties": {
          "role": {
            "type": "string",
            "enum": [
              "system",
              "user",
              "assistant"
            ]
          },
          "content": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/TextPart"
                    },
                    {
                      "$ref": "#/components/schemas/ImagePart"
                    }
                  ]
                }
              }
            ]
          }
        }
      },
      "ResponseFormat": {
        "oneOf": [
          {
            "type": "object",
            "required": [
              "type"
            ],
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "text",
                  "json_object"
                ]
              }
            }
          },
          {
            "type": "object",
            "required": [
              "type",
              "json_schema"
            ],
            "properties": {
              "type": {
                "const": "json_schema"
              },
              "json_schema": {
                "type": "object",
                "required": [
                  "name",
                  "schema"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 64
                  },
                  "strict": {
                    "type": "boolean",
                    "default": true
                  },
                  "schema": {
                    "type": "object",
                    "additionalProperties": true
                  }
                }
              }
            }
          }
        ]
      },
      "ChatCompletionRequest": {
        "type": "object",
        "required": [
          "model",
          "messages"
        ],
        "properties": {
          "model": {
            "type": "string",
            "enum": [
              "domimuse-35b"
            ]
          },
          "messages": {
            "type": "array",
            "minItems": 1,
            "items": {
              "$ref": "#/components/schemas/Message"
            }
          },
          "stream": {
            "type": "boolean",
            "default": false
          },
          "max_tokens": {
            "type": "integer",
            "minimum": 1,
            "maximum": 8192,
            "default": 1024
          },
          "temperature": {
            "type": "number",
            "minimum": 0,
            "maximum": 2,
            "default": 0.6
          },
          "top_p": {
            "type": "number",
            "minimum": 0,
            "maximum": 1,
            "default": 0.9
          },
          "seed": {
            "type": "integer"
          },
          "stop": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            ]
          },
          "frequency_penalty": {
            "type": "number",
            "minimum": -2,
            "maximum": 2
          },
          "presence_penalty": {
            "type": "number",
            "minimum": -2,
            "maximum": 2
          },
          "response_format": {
            "$ref": "#/components/schemas/ResponseFormat"
          },
          "thinking": {
            "type": "boolean",
            "default": false,
            "description": "DomiMuse extension. Enables thinking mode; reasoning content is not an authoritative data source."
          }
        }
      },
      "AnthropicError": {
        "type": "object",
        "required": [
          "type",
          "error"
        ],
        "properties": {
          "type": {
            "const": "error"
          },
          "error": {
            "type": "object",
            "required": [
              "type",
              "message"
            ],
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "invalid_request_error",
                  "authentication_error",
                  "not_found_error",
                  "rate_limit_error",
                  "api_error",
                  "overloaded_error"
                ]
              },
              "message": {
                "type": "string"
              },
              "code": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "retryable": {
                "type": "boolean"
              },
              "retry_after_seconds": {
                "type": [
                  "integer",
                  "null"
                ]
              }
            }
          },
          "request_id": {
            "type": "string"
          }
        }
      },
      "AnthropicContentBlock": {
        "oneOf": [
          {
            "type": "object",
            "required": [
              "type",
              "text"
            ],
            "properties": {
              "type": {
                "const": "text"
              },
              "text": {
                "type": "string"
              },
              "cache_control": {
                "type": "object"
              }
            }
          },
          {
            "type": "object",
            "required": [
              "type",
              "source"
            ],
            "properties": {
              "type": {
                "const": "image"
              },
              "source": {
                "type": "object",
                "required": [
                  "type",
                  "media_type",
                  "data"
                ],
                "properties": {
                  "type": {
                    "const": "base64"
                  },
                  "media_type": {
                    "type": "string",
                    "enum": [
                      "image/png",
                      "image/jpeg"
                    ]
                  },
                  "data": {
                    "type": "string"
                  }
                }
              }
            }
          },
          {
            "type": "object",
            "required": [
              "type",
              "id",
              "name",
              "input"
            ],
            "properties": {
              "type": {
                "const": "tool_use"
              },
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "input": {
                "type": "object",
                "additionalProperties": true
              }
            }
          },
          {
            "type": "object",
            "required": [
              "type",
              "tool_use_id",
              "content"
            ],
            "properties": {
              "type": {
                "const": "tool_result"
              },
              "tool_use_id": {
                "type": "string"
              },
              "content": {
                "oneOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "array"
                  }
                ]
              },
              "is_error": {
                "type": "boolean"
              }
            }
          }
        ]
      },
      "AnthropicMessageRequest": {
        "type": "object",
        "required": [
          "model",
          "max_tokens",
          "messages"
        ],
        "properties": {
          "model": {
            "type": "string",
            "enum": [
              "claude-domimuse-35b",
              "domimuse-35b"
            ]
          },
          "max_tokens": {
            "type": "integer",
            "minimum": 1,
            "maximum": 8192
          },
          "system": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array"
              }
            ]
          },
          "messages": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "object",
              "required": [
                "role",
                "content"
              ],
              "properties": {
                "role": {
                  "type": "string",
                  "enum": [
                    "system",
                    "user",
                    "assistant"
                  ]
                },
                "content": {
                  "oneOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/AnthropicContentBlock"
                      }
                    }
                  ]
                }
              }
            }
          },
          "stream": {
            "type": "boolean",
            "default": false
          },
          "temperature": {
            "type": "number",
            "minimum": 0,
            "maximum": 1
          },
          "top_p": {
            "type": "number",
            "minimum": 0,
            "maximum": 1
          },
          "top_k": {
            "type": "integer",
            "minimum": 0,
            "maximum": 500
          },
          "stop_sequences": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "tools": {
            "type": "array",
            "maxItems": 128,
            "items": {
              "type": "object",
              "required": [
                "name",
                "input_schema"
              ],
              "properties": {
                "name": {
                  "type": "string"
                },
                "description": {
                  "type": "string"
                },
                "input_schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "tool_choice": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "auto",
                  "any",
                  "none",
                  "tool"
                ]
              },
              "name": {
                "type": "string"
              }
            }
          }
        }
      },
      "AnthropicMessage": {
        "type": "object",
        "required": [
          "id",
          "type",
          "role",
          "model",
          "content",
          "stop_reason",
          "usage"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "type": {
            "const": "message"
          },
          "role": {
            "const": "assistant"
          },
          "model": {
            "type": "string"
          },
          "content": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AnthropicContentBlock"
            }
          },
          "stop_reason": {
            "type": "string",
            "enum": [
              "end_turn",
              "max_tokens",
              "tool_use"
            ]
          },
          "stop_sequence": {
            "type": [
              "string",
              "null"
            ]
          },
          "usage": {
            "type": "object",
            "properties": {
              "input_tokens": {
                "type": "integer"
              },
              "output_tokens": {
                "type": "integer"
              }
            }
          }
        }
      },
      "TokenUsage": {
        "type": "object",
        "properties": {
          "prompt_tokens": {
            "type": "integer"
          },
          "completion_tokens": {
            "type": "integer"
          },
          "total_tokens": {
            "type": "integer"
          }
        }
      },
      "ChatCompletion": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "object": {
            "type": "string"
          },
          "created": {
            "type": "integer"
          },
          "model": {
            "const": "domimuse-35b"
          },
          "choices": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "usage": {
            "$ref": "#/components/schemas/TokenUsage"
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "title": {
                  "type": "string"
                },
                "url": {
                  "type": "string",
                  "format": "uri"
                }
              }
            }
          }
        }
      },
      "Model": {
        "type": "object",
        "required": [
          "id",
          "object",
          "owned_by",
          "metadata"
        ],
        "properties": {
          "id": {
            "type": "string",
            "enum": [
              "domimuse-35b",
              "claude-domimuse-35b"
            ]
          },
          "object": {
            "const": "model"
          },
          "created": {
            "type": "integer"
          },
          "owned_by": {
            "const": "domimuse"
          },
          "metadata": {
            "type": "object",
            "properties": {
              "version": {
                "type": "string",
                "example": "1.0.0"
              },
              "context_length": {
                "type": "integer",
                "example": 32768
              },
              "modalities": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "example": [
                  "text",
                  "image"
                ]
              },
              "thinking": {
                "type": "boolean",
                "example": true
              },
              "alignment": {
                "type": "string",
                "example": "DomiMuse Private Alignment"
              },
              "deployment": {
                "type": "string",
                "example": "Self-hosted"
              }
            }
          }
        }
      },
      "Status": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "ready",
              "busy",
              "queueing",
              "loading",
              "offline"
            ]
          },
          "ready": {
            "type": "boolean"
          },
          "model": {
            "const": "domimuse-35b"
          },
          "queue": {
            "type": "object",
            "properties": {
              "active_requests": {
                "type": "integer"
              },
              "queued_requests": {
                "type": "integer"
              }
            }
          },
          "performance": {
            "type": "object",
            "properties": {
              "average_ttft_ms": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "sample_size": {
                "type": "integer"
              }
            }
          },
          "gateway_started_at": {
            "type": "string",
            "format": "date-time"
          },
          "last_ready_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "TenantUsage": {
        "type": "object",
        "properties": {
          "object": {
            "const": "tenant.usage"
          },
          "tenant_id": {
            "type": "string"
          },
          "period": {
            "type": "string",
            "example": "2026-07"
          },
          "requests": {
            "type": "integer"
          },
          "succeeded_requests": {
            "type": "integer"
          },
          "failed_requests": {
            "type": "integer"
          },
          "streamed_requests": {
            "type": "integer"
          },
          "image_requests": {
            "type": "integer"
          },
          "prompt_tokens": {
            "type": "integer"
          },
          "completion_tokens": {
            "type": "integer"
          },
          "total_tokens": {
            "type": "integer"
          },
          "current_concurrency": {
            "type": "integer"
          },
          "quota": {
            "type": "object"
          },
          "persistence": {
            "const": "monthly_jsonl"
          }
        }
      }
    }
  },
  "security": [
    {
      "BearerAuth": []
    },
    {
      "ApiKeyAuth": []
    }
  ],
  "paths": {
    "/status": {
      "get": {
        "tags": [
          "Status"
        ],
        "summary": "Get public service status",
        "description": "Returns model readiness, queue depth, and aggregate TTFT without exposing infrastructure identifiers.",
        "security": [],
        "responses": {
          "200": {
            "description": "Ready, busy, or queueing",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Status"
                }
              },
              "text/html": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "503": {
            "description": "Loading or offline",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Status"
                }
              }
            }
          }
        }
      }
    },
    "/v1/models": {
      "get": {
        "tags": [
          "Models"
        ],
        "summary": "List available models",
        "responses": {
          "200": {
            "description": "Model list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "const": "list"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Model"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/chat/completions": {
      "post": {
        "tags": [
          "Chat"
        ],
        "summary": "Create a chat completion",
        "description": "OpenAI Chat Completions base-compatible. Set stream=true for SSE. Tool calling is not enabled.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatCompletionRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Completion or SSE stream",
            "headers": {
              "X-Request-Id": {
                "schema": {
                  "type": "string"
                }
              },
              "X-RateLimit-Limit": {
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Reset": {
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChatCompletion"
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string"
                },
                "example": "data: {\"choices\":[{\"delta\":{\"content\":\"你\"}}]}\n\ndata: [DONE]\n\n"
              }
            }
          },
          "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": "Tenant rate or concurrency limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Model gateway error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/messages": {
      "post": {
        "tags": [
          "Claude Code"
        ],
        "summary": "Create an Anthropic Messages compatible response",
        "description": "Claude Code compatible text, image, streaming, tool_use, and tool_result endpoint. Query strings such as beta=true are accepted.",
        "parameters": [
          {
            "in": "header",
            "name": "anthropic-version",
            "required": false,
            "schema": {
              "type": "string",
              "example": "2023-06-01"
            }
          },
          {
            "in": "header",
            "name": "anthropic-beta",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AnthropicMessageRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Anthropic Message or named SSE stream",
            "headers": {
              "request-id": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnthropicMessage"
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string"
                },
                "example": "event: message_start\ndata: {\"type\":\"message_start\"}\n\nevent: message_stop\ndata: {\"type\":\"message_stop\"}\n\n"
              }
            }
          },
          "400": {
            "description": "Invalid Anthropic request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnthropicError"
                }
              }
            }
          },
          "401": {
            "description": "Invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnthropicError"
                }
              }
            }
          },
          "429": {
            "description": "Tenant rate or concurrency limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnthropicError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/messages/count_tokens": {
      "post": {
        "tags": [
          "Claude Code"
        ],
        "summary": "Estimate Anthropic Messages input tokens",
        "description": "Authenticated input-token estimate used by Claude Code for context management.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AnthropicMessageRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Input token estimate",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "input_tokens"
                  ],
                  "properties": {
                    "input_tokens": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnthropicError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/usage": {
      "get": {
        "tags": [
          "Usage"
        ],
        "summary": "Get current tenant monthly usage",
        "description": "Returns authenticated-tenant monthly counters reconstructed from persistent metadata-only JSONL audit records.",
        "responses": {
          "200": {
            "description": "Tenant-isolated monthly usage",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TenantUsage"
                }
              }
            }
          },
          "401": {
            "description": "Invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  }
}
