{
  "openapi": "3.1.0",
  "info": {
    "title": "AIWave API",
    "version": "2026-09-13",
    "description": "OpenAI-compatible chat completions, key-scoped model discovery, a dated public pricing snapshot, and a public operational snapshot. Model capabilities remain route-specific and must be verified with the selected model ID.",
    "contact": {
      "name": "AIWave support",
      "email": "support@aiwave.live"
    },
    "license": {
      "name": "AIWave Terms",
      "url": "https://aiwave.live/terms"
    }
  },
  "servers": [
    {
      "url": "https://aiwave.live"
    }
  ],
  "externalDocs": {
    "description": "Human-readable complete reference",
    "url": "https://aiwave.live/docs/complete-reference/"
  },
  "tags": [
    {
      "name": "Completions",
      "description": "OpenAI-shaped chat completions."
    },
    {
      "name": "Models",
      "description": "Model IDs visible to the current key."
    },
    {
      "name": "Public data",
      "description": "Unauthenticated pricing and status snapshots."
    }
  ],
  "paths": {
    "/v1/chat/completions": {
      "post": {
        "tags": [
          "Completions"
        ],
        "summary": "Create a chat completion",
        "description": "Send an OpenAI-shaped chat request. Route-dependent fields must be verified with the selected model.",
        "operationId": "createChatCompletion",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatCompletionRequest"
              },
              "examples": {
                "firstCall": {
                  "value": {
                    "model": "deepseek-flash",
                    "messages": [
                      {
                        "role": "user",
                        "content": "Reply with OK"
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Completion or server-sent event stream.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChatCompletion"
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/v1/models": {
      "get": {
        "tags": [
          "Models"
        ],
        "summary": "List model IDs visible to the current key",
        "operationId": "listModels",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "OpenAI-shaped model list",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ModelList"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    },
    "/api/v1/pricing": {
      "get": {
        "tags": [
          "Public data"
        ],
        "summary": "Get the dated public pricing snapshot",
        "description": "Returns gateway base rates in USD per 1M text tokens. Account-group multipliers can change the effective charge.",
        "operationId": "getPricingSnapshot",
        "security": [],
        "responses": {
          "200": {
            "description": "Current dated snapshot",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PricingSnapshot"
                },
                "example": {
                  "checked": "2026-09-10",
                  "currency": "USD",
                  "unit": "per_1m_text_tokens",
                  "models": [
                    {
                      "id": "deepseek-flash",
                      "provider": "DeepSeek",
                      "input_usd_per_1m_tokens": 0.7,
                      "cache_hit_usd_per_1m_tokens": 0.0233,
                      "output_usd_per_1m_tokens": 2.1,
                      "effective_date": "2026-09-10"
                    }
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/status-metrics.json": {
      "get": {
        "tags": [
          "Public data"
        ],
        "summary": "Get the current public operational snapshot",
        "description": "Returns sampled public-contract checks and aggregate completion latency. Null success-rate and uptime fields mean the available denominator or sampling interval is not sufficient for a defensible percentage.",
        "operationId": "getStatusMetrics",
        "security": [],
        "responses": {
          "200": {
            "description": "Current privacy-safe operational snapshot",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StatusMetrics"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API key"
      }
    },
    "schemas": {
      "ChatMessage": {
        "type": "object",
        "required": [
          "role",
          "content"
        ],
        "properties": {
          "role": {
            "type": "string",
            "enum": [
              "system",
              "developer",
              "user",
              "assistant",
              "tool"
            ]
          },
          "content": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            ]
          },
          "name": {
            "type": "string"
          },
          "tool_call_id": {
            "type": "string"
          }
        },
        "additionalProperties": true
      },
      "ChatCompletionRequest": {
        "type": "object",
        "required": [
          "model",
          "messages"
        ],
        "properties": {
          "model": {
            "type": "string"
          },
          "messages": {
            "type": "array",
            "minItems": 1,
            "items": {
              "$ref": "#/components/schemas/ChatMessage"
            }
          },
          "stream": {
            "type": "boolean",
            "default": false
          },
          "temperature": {
            "type": "number"
          },
          "top_p": {
            "type": "number"
          },
          "max_tokens": {
            "type": "integer",
            "minimum": 1
          },
          "tools": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "tool_choice": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "object",
                "additionalProperties": true
              }
            ]
          },
          "response_format": {
            "type": "object",
            "additionalProperties": true
          }
        },
        "additionalProperties": true
      },
      "Usage": {
        "type": "object",
        "properties": {
          "prompt_tokens": {
            "type": "integer"
          },
          "completion_tokens": {
            "type": "integer"
          },
          "total_tokens": {
            "type": "integer"
          }
        },
        "additionalProperties": true
      },
      "ChatCompletion": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "object": {
            "type": "string"
          },
          "model": {
            "type": "string"
          },
          "choices": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "usage": {
            "$ref": "#/components/schemas/Usage"
          }
        },
        "additionalProperties": true
      },
      "ModelList": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string"
          },
          "data": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                }
              },
              "additionalProperties": true
            }
          }
        },
        "additionalProperties": true
      },
      "PricingRow": {
        "type": "object",
        "required": [
          "id",
          "provider",
          "input_usd_per_1m_tokens",
          "output_usd_per_1m_tokens",
          "effective_date"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "provider": {
            "type": "string"
          },
          "input_usd_per_1m_tokens": {
            "type": "number"
          },
          "cache_hit_usd_per_1m_tokens": {
            "type": [
              "number",
              "null"
            ]
          },
          "output_usd_per_1m_tokens": {
            "type": "number"
          },
          "effective_date": {
            "type": "string",
            "format": "date"
          }
        }
      },
      "PricingSnapshot": {
        "type": "object",
        "required": [
          "checked",
          "currency",
          "unit",
          "models"
        ],
        "properties": {
          "checked": {
            "type": "string",
            "format": "date"
          },
          "currency": {
            "type": "string",
            "const": "USD"
          },
          "unit": {
            "type": "string",
            "const": "per_1m_text_tokens"
          },
          "models": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PricingRow"
            }
          }
        },
        "additionalProperties": true
      },
      "LatencyRow": {
        "type": "object",
        "required": [
          "model_id",
          "mean_seconds",
          "p50_seconds",
          "p95_seconds"
        ],
        "properties": {
          "model_id": {
            "type": "string"
          },
          "mean_seconds": {
            "type": "number",
            "minimum": 0
          },
          "p50_seconds": {
            "type": "number",
            "minimum": 0
          },
          "p95_seconds": {
            "type": "number",
            "minimum": 0
          }
        }
      },
      "StatusMetrics": {
        "type": "object",
        "required": [
          "schema_version",
          "generated_at",
          "public_contract_samples",
          "historical_uptime",
          "end_to_end_success_rate",
          "latency"
        ],
        "properties": {
          "schema_version": {
            "type": "integer",
            "const": 1
          },
          "generated_at": {
            "type": "string",
            "format": "date-time"
          },
          "public_contract_samples": {
            "type": "object",
            "additionalProperties": true
          },
          "historical_uptime": {
            "type": "object",
            "additionalProperties": true
          },
          "end_to_end_success_rate": {
            "type": "object",
            "additionalProperties": true
          },
          "latency": {
            "type": "object",
            "properties": {
              "models": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/LatencyRow"
                }
              }
            },
            "additionalProperties": true
          }
        },
        "additionalProperties": true
      },
      "ErrorDetail": {
        "type": "object",
        "properties": {
          "message": {
            "type": "string",
            "description": "Human-readable error message."
          },
          "type": {
            "type": [
              "string",
              "null"
            ],
            "description": "Stable error category when supplied."
          },
          "code": {
            "type": [
              "string",
              "null"
            ],
            "description": "Route-specific error code when supplied."
          },
          "param": {
            "type": [
              "string",
              "null"
            ],
            "description": "Related request field when supplied."
          }
        },
        "required": [
          "message"
        ],
        "additionalProperties": true
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "$ref": "#/components/schemas/ErrorDetail"
              }
            ]
          }
        },
        "required": [
          "error"
        ],
        "additionalProperties": true
      }
    },
    "responses": {
      "BadRequest": {
        "description": "The request body, model ID, or route-specific field is invalid.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "examples": {
              "error": {
                "value": {
                  "error": {
                    "message": "The request body, model ID, or route-specific field is invalid.",
                    "type": "request_error",
                    "code": null
                  }
                }
              }
            }
          }
        }
      },
      "Unauthorized": {
        "description": "The bearer key is missing, malformed, revoked, or invalid.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "examples": {
              "error": {
                "value": {
                  "error": {
                    "message": "The bearer key is missing, malformed, revoked, or invalid.",
                    "type": "request_error",
                    "code": null
                  }
                }
              }
            }
          }
        }
      },
      "PaymentRequired": {
        "description": "The account does not have enough balance or quota for this request.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "examples": {
              "error": {
                "value": {
                  "error": {
                    "message": "The account does not have enough balance or quota for this request.",
                    "type": "request_error",
                    "code": null
                  }
                }
              }
            }
          }
        }
      },
      "Forbidden": {
        "description": "The account, key, group, or policy does not allow this request.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "examples": {
              "error": {
                "value": {
                  "error": {
                    "message": "The account, key, group, or policy does not allow this request.",
                    "type": "request_error",
                    "code": null
                  }
                }
              }
            }
          }
        }
      },
      "TooManyRequests": {
        "description": "The request exceeded a rate or concurrency limit.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "examples": {
              "error": {
                "value": {
                  "error": {
                    "message": "The request exceeded a rate or concurrency limit.",
                    "type": "request_error",
                    "code": null
                  }
                }
              }
            }
          }
        },
        "headers": {
          "Retry-After": {
            "description": "Suggested delay before retrying, when supplied by the route.",
            "schema": {
              "type": "string"
            }
          }
        }
      },
      "ServerError": {
        "description": "The gateway or upstream route could not complete the request.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "examples": {
              "error": {
                "value": {
                  "error": {
                    "message": "The gateway or upstream route could not complete the request.",
                    "type": "request_error",
                    "code": null
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
