{
  "openapi": "3.1.0",
  "info": {
    "title": "HardysAPI",
    "description": "Unified AI API gateway. OpenAI-compatible endpoints serving 26 active pricing tiers across Claude, GPT, Gemini, Grok, DeepSeek, GLM, Kimi, MiMo. USD-denominated balance, no lock-in, Alipay accepted.",
    "version": "2026.08.06",
    "contact": {"email": "support@hardysapi.com", "url": "https://hardysapi.com"},
    "license": {"name": "Proprietary"}
  },
  "servers": [{"url": "https://hardysapi.com/v1", "description": "Production"}],
  "tags": [
    {"name": "Chat", "description": "Chat completions (OpenAI compatible)"},
    {"name": "Models", "description": "List available models"},
    {"name": "Images", "description": "Image generation"},
    {"name": "Usage", "description": "Account usage statistics"}
  ],
  "paths": {
    "/chat/completions": {
      "post": {
        "tags": ["Chat"],
        "summary": "Create chat completion",
        "operationId": "createChatCompletion",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {"$ref": "#/components/schemas/ChatCompletionRequest"}
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {"schema": {"$ref": "#/components/schemas/ChatCompletionResponse"}},
              "text/event-stream": {"schema": {"type": "string", "description": "SSE stream of ChatCompletionChunk"}}
            }
          },
          "401": {"$ref": "#/components/responses/Unauthorized"},
          "402": {"$ref": "#/components/responses/InsufficientBalance"},
          "429": {"$ref": "#/components/responses/RateLimited"},
          "502": {"$ref": "#/components/responses/UpstreamError"}
        },
        "security": [{"BearerAuth": []}]
      }
    },
    "/models": {
      "get": {
        "tags": ["Models"],
        "summary": "List available models",
        "operationId": "listModels",
        "responses": {
          "200": {
            "description": "List of model IDs",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {"type": "string", "example": "list"},
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {"type": "string", "example": "claude-opus-4-8"},
                          "object": {"type": "string", "example": "model"},
                          "created": {"type": "integer"},
                          "owned_by": {"type": "string", "example": "anthropic"}
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "security": [{"BearerAuth": []}]
      }
    },
    "/images/generations": {
      "post": {
        "tags": ["Images"],
        "summary": "Generate image",
        "operationId": "createImage",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["prompt", "model"],
                "properties": {
                  "prompt": {"type": "string"},
                  "model": {"type": "string", "example": "gpt-image-2"},
                  "n": {"type": "integer", "default": 1, "minimum": 1, "maximum": 10},
                  "size": {"type": "string", "enum": ["1024x1024", "1024x1792", "1792x1024"], "default": "1024x1024"}
                }
              }
            }
          }
        },
        "responses": {"200": {"description": "Image URL or base64"}}
      }
    },
    "/usage": {
      "get": {
        "tags": ["Usage"],
        "summary": "Get current API key usage statistics",
        "operationId": "getUsage",
        "responses": {"200": {"description": "Daily usage aggregation"}}
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "sk-hardy-..."
      }
    },
    "schemas": {
      "ChatCompletionRequest": {
        "type": "object",
        "required": ["model", "messages"],
        "properties": {
          "model": {"type": "string", "description": "Model ID (e.g. claude-opus-4-8, gpt-5, gemini-3-pro-high)"},
          "messages": {
            "type": "array",
            "items": {
              "type": "object",
              "required": ["role", "content"],
              "properties": {
                "role": {"type": "string", "enum": ["system", "user", "assistant", "tool"]},
                "content": {"type": "string"}
              }
            }
          },
          "max_tokens": {"type": "integer", "minimum": 1, "maximum": 200000, "default": 1024},
          "temperature": {"type": "number", "minimum": 0, "maximum": 2, "default": 1},
          "top_p": {"type": "number", "minimum": 0, "maximum": 1, "default": 1},
          "stream": {"type": "boolean", "default": false},
          "tools": {"type": "array"},
          "tool_choice": {"type": "string", "enum": ["none", "auto", "required"]},
          "user": {"type": "string", "description": "End-user tracking ID"}
        }
      },
      "ChatCompletionResponse": {
        "type": "object",
        "properties": {
          "id": {"type": "string"},
          "object": {"type": "string", "example": "chat.completion"},
          "created": {"type": "integer"},
          "model": {"type": "string"},
          "choices": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "index": {"type": "integer"},
                "message": {
                  "type": "object",
                  "properties": {
                    "role": {"type": "string"},
                    "content": {"type": "string"},
                    "tool_calls": {"type": "array"}
                  }
                },
                "finish_reason": {"type": "string", "enum": ["stop", "length", "tool_calls", "content_filter"]}
              }
            }
          },
          "usage": {
            "type": "object",
            "properties": {
              "prompt_tokens": {"type": "integer"},
              "completion_tokens": {"type": "integer"},
              "total_tokens": {"type": "integer"}
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "message": {"type": "string"},
              "type": {"type": "string"},
              "code": {"type": "string"}
            }
          }
        }
      }
    },
    "responses": {
      "Unauthorized": {"description": "Invalid API key", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}},
      "InsufficientBalance": {"description": "Balance insufficient", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}},
      "RateLimited": {"description": "Rate limit exceeded", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}},
      "UpstreamError": {"description": "Upstream API error", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}
    }
  }
}