{
  "openapi": "3.0.3",
  "info": {
    "title": "StreamingTelligence HTTP API",
    "version": "v1-preview",
    "description": "StreamingTelligence HTTP API 支持模型查询和对话补全，并通过服务器发送事件提供增量响应。模型访问范围由账号权限决定。",
    "contact": {
      "name": "StreamingTelligence",
      "email": "streamingtelligence@gmail.com"
    }
  },
  "servers": [
    {
      "url": "/v1",
      "description": "当前网站所在域名"
    }
  ],
  "security": [
    {
      "BearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "Inference",
      "description": "兼容 OpenAI 的 HTTP 请求。调用需要上游服务可用，且账号具有对应模型的访问权限。"
    }
  ],
  "paths": {
    "/models": {
      "get": {
        "tags": [
          "Inference"
        ],
        "operationId": "listModels",
        "summary": "列出可用模型",
        "description": "列出已连接网关提供的模型。模型访问权限同时受账号邀请码的授权范围限制。",
        "responses": {
          "200": {
            "description": "已连接上游返回的模型列表。",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "type": "string",
                      "enum": [
                        "list"
                      ]
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "id"
                        ],
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "object": {
                            "type": "string"
                          },
                          "owned_by": {
                            "type": "string"
                          }
                        },
                        "additionalProperties": true
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/chat/completions": {
      "post": {
        "tags": [
          "Inference"
        ],
        "operationId": "createChatCompletion",
        "summary": "创建对话补全",
        "description": "发送兼容 OpenAI 的对话请求。设置 stream=true 时，增量 JSON 数据块以 SSE data 事件返回，并以 [DONE] 结束。多模态内容格式和可选参数因模型而异，请以已发布的模型接口规范为准。",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "model",
                  "messages"
                ],
                "properties": {
                  "model": {
                    "type": "string",
                    "description": "邀请码授权使用的模型标识符。"
                  },
                  "messages": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "type": "object",
                      "required": [
                        "role",
                        "content"
                      ],
                      "properties": {
                        "role": {
                          "type": "string",
                          "enum": [
                            "system",
                            "user",
                            "assistant"
                          ]
                        },
                        "content": {
                          "type": "string",
                          "description": "文本消息。本预览版尚未定义各模型的多模态内容格式。"
                        }
                      }
                    }
                  },
                  "stream": {
                    "type": "boolean",
                    "default": false
                  }
                },
                "additionalProperties": true
              },
              "example": {
                "model": "MODEL_ALLOWED_BY_YOUR_INVITATION",
                "messages": [
                  {
                    "role": "user",
                    "content": "Describe this moment."
                  }
                ],
                "stream": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "根据 stream 字段返回完整补全结果或 SSE 流。可选字段由模型决定。",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "model": {
                      "type": "string"
                    },
                    "choices": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "index": {
                            "type": "integer"
                          },
                          "message": {
                            "type": "object",
                            "properties": {
                              "role": {
                                "type": "string"
                              },
                              "content": {
                                "type": "string",
                                "nullable": true
                              }
                            }
                          },
                          "finish_reason": {
                            "type": "string",
                            "nullable": true
                          }
                        },
                        "additionalProperties": true
                      }
                    },
                    "usage": {
                      "type": "object",
                      "additionalProperties": true
                    }
                  },
                  "additionalProperties": true
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string",
                  "description": "包含增量补全结果的 SSE 事件，以 data: [DONE] 结束。"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          },
          "default": {
            "description": "网关或模型特定错误。状态码和数据结构由上游返回。",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "有效的 API 密钥，不是网站登录密码或邀请码。"
      }
    },
    "schemas": {
      "IngressError": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          }
        }
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "API 密钥缺失、未激活、已过期或已撤销。",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/IngressError"
            },
            "example": {
              "error": "A valid active API key is required."
            }
          }
        }
      },
      "Unavailable": {
        "description": "上游连接错误。请查看错误详情，并对暂时性故障使用有次数上限的指数退避重试。",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/IngressError"
            }
          }
        }
      }
    }
  }
}