{
  "openapi": "3.0.3",
  "info": {
    "title": "NowAI API",
    "description": "Developer resources and API description for NowAI models proxy. Allows secure and high-speed routing of LLM requests to Zhipu GLM, DeepSeek, and Agnes AI.",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://nowai.cc.cd",
      "description": "Production server"
    }
  ],
  "paths": {
    "/get-system-models": {
      "get": {
        "operationId": "getSystemModels",
        "summary": "Get list of available AI models",
        "description": "Retrieves active and supported system models including upstream settings.",
        "responses": {
          "200": {
            "description": "Success",
            "headers": {
              "X-RateLimit-Limit": {
                "schema": { "type": "integer" },
                "description": "The maximum number of requests allowed in the current period."
              },
              "X-RateLimit-Remaining": {
                "schema": { "type": "integer" },
                "description": "The number of remaining requests in the current period."
              },
              "X-RateLimit-Reset": {
                "schema": { "type": "integer" },
                "description": "The number of seconds remaining until the rate limit resets."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "models": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "model_key": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          },
                          "provider": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "headers": {
              "Retry-After": {
                "schema": { "type": "integer" },
                "description": "The number of seconds to wait before making another request."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/chat/completions": {
      "post": {
        "operationId": "createChatCompletion",
        "summary": "Create chat completion proxy",
        "description": "OpenAI-compatible chat completion endpoint. Forwards request to Zhipu GLM, DeepSeek, or Agnes AI backends based on selected model.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["model", "messages"],
                "properties": {
                  "model": {
                    "type": "string",
                    "description": "Model key, e.g. glm-4-flash, deepseek-chat, agnes-2.0-flash"
                  },
                  "messages": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "role": {
                          "type": "string",
                          "enum": ["system", "user", "assistant"]
                        },
                        "content": {
                          "type": "string"
                        }
                      }
                    }
                  },
                  "stream": {
                    "type": "boolean",
                    "default": false
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Completion response (or Server-Sent Events stream if stream=true)",
            "headers": {
              "X-RateLimit-Limit": {
                "schema": { "type": "integer" },
                "description": "The maximum number of requests allowed in the current period."
              },
              "X-RateLimit-Remaining": {
                "schema": { "type": "integer" },
                "description": "The number of remaining requests in the current period."
              },
              "X-RateLimit-Reset": {
                "schema": { "type": "integer" },
                "description": "The number of seconds remaining until the rate limit resets."
              }
            }
          },
          "400": {
            "description": "Invalid parameters",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "headers": {
              "Retry-After": {
                "schema": { "type": "integer" },
                "description": "The number of seconds to wait before making another request."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "502": {
            "description": "Upstream service error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/images/generations": {
      "post": {
        "operationId": "createImageGeneration",
        "summary": "Generate image proxy",
        "description": "OpenAI-compatible image generation endpoint.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["prompt"],
                "properties": {
                  "prompt": {
                    "type": "string",
                    "description": "Description of the image to generate"
                  },
                  "n": {
                    "type": "integer",
                    "default": 1
                  },
                  "size": {
                    "type": "string",
                    "default": "1024x1024"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Image generation response",
            "headers": {
              "X-RateLimit-Limit": {
                "schema": { "type": "integer" },
                "description": "The maximum number of requests allowed in the current period."
              },
              "X-RateLimit-Remaining": {
                "schema": { "type": "integer" },
                "description": "The number of remaining requests in the current period."
              },
              "X-RateLimit-Reset": {
                "schema": { "type": "integer" },
                "description": "The number of seconds remaining until the rate limit resets."
              }
            }
          },
          "400": {
            "description": "Invalid parameters",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "headers": {
              "Retry-After": {
                "schema": { "type": "integer" },
                "description": "The number of seconds to wait before making another request."
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ErrorResponse": {
        "type": "object",
        "required": ["error"],
        "properties": {
          "error": {
            "type": "object",
            "required": ["code", "message"],
            "properties": {
              "code": {
                "type": "string",
                "description": "A machine-readable error code"
              },
              "message": {
                "type": "string",
                "description": "A human-readable error description"
              },
              "resolution": {
                "type": "string",
                "description": "Suggested action to resolve the error"
              },
              "documentation_url": {
                "type": "string",
                "description": "Link to help resources"
              }
            }
          }
        }
      }
    }
  }
}
