{
  "openapi": "3.0.3",
  "info": {
    "title": "千流 API · 模型目录与首次调用",
    "version": "1.0.0",
    "description": "第一次接入千流，可以先匿名查询模型目录，按模型 ID 查看可选分组和协议。准备发送真实请求时，请在自己的本机环境填写千流令牌，先获取令牌可见的模型，再发送一条短消息。\n\n[查看分组价格](https://www.plusapi.cn/pricing) · [注册、首次调用与账单核对](https://www.plusapi.cn/news/focus/224) · [千流客服](https://www.plusapi.cn/customersupport)\n\n示例仅覆盖非流式文本对话。请将令牌保存在本地私密环境，避免写入共享项目、公开示例或云端环境。发送对话请求可能产生费用，以模型、所选分组和控制台记录为准。"
  },
  "servers": [
    {
      "url": "https://www.plusapi.cn",
      "description": "千流 API 官网和接口"
    }
  ],
  "tags": [
    {
      "name": "接入前"
    },
    {
      "name": "首次调用"
    }
  ],
  "paths": {
    "/api/pricing_new": {
      "get": {
        "operationId": "getPublicModelCatalog",
        "tags": [
          "接入前"
        ],
        "summary": "查询公开模型目录（无需令牌）",
        "description": "此接口供千流模型广场展示目录，无需注册。返回完整目录后，在 data 中按 model_name 查找模型。enable_groups 表示该模型列出的分组，supported_endpoint_types 表示接口类型。目录里的倍率不能直接当作美元单价。输入、输出、缓存及阶梯价以[模型广场](https://www.plusapi.cn/pricing)中所选分组的详情为准。",
        "security": [],
        "responses": {
          "200": {
            "description": "模型广场的公开目录。仅列出本示例使用的字段。",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "model_name": {
                            "type": "string"
                          },
                          "model_type": {
                            "type": "string"
                          },
                          "enable_groups": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            }
                          },
                          "supported_endpoint_types": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/models": {
      "get": {
        "operationId": "listTokenModels",
        "tags": [
          "首次调用"
        ],
        "summary": "查看当前令牌可用的模型",
        "description": "填写自己令牌的 Bearer 认证。从 data 中选取模型 ID，再在模型广场确认所用分组支持文本对话。公开目录中的模型与某一令牌能调用的模型范围可能不同。",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "返回当前令牌可见的模型。",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "type": "string"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/v1/chat/completions": {
      "post": {
        "operationId": "sendShortChat",
        "tags": [
          "首次调用"
        ],
        "summary": "发送一条短消息并核对费用",
        "description": "先核对令牌分组和[该模型的实际价格](https://www.plusapi.cn/pricing?keyword=gpt-4o-mini)。例子使用 gpt-4o-mini，请确认自己的令牌包含它，或换成支持 Chat Completions 和 max_tokens 的模型。手动发送一次即可，记录请求时间和模型 ID，在千流控制台的使用日志核对分组与扣费。\n\nmax_tokens 限制输出长度。输入也可能计费，重试会产生新的请求。",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "model",
                  "messages"
                ],
                "properties": {
                  "model": {
                    "type": "string"
                  },
                  "messages": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "type": "object",
                      "required": [
                        "role",
                        "content"
                      ],
                      "properties": {
                        "role": {
                          "type": "string",
                          "enum": [
                            "system",
                            "user",
                            "assistant"
                          ]
                        },
                        "content": {
                          "type": "string"
                        }
                      }
                    }
                  },
                  "max_tokens": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "stream": {
                    "type": "boolean",
                    "enum": [
                      false
                    ]
                  }
                }
              },
              "example": {
                "model": "gpt-4o-mini",
                "messages": [
                  {
                    "role": "user",
                    "content": "只回复 OK"
                  }
                ],
                "max_tokens": 16,
                "stream": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "非流式对话结果。usage 若返回，可用于核对 token 数。",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "model": {
                      "type": "string"
                    },
                    "choices": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "message": {
                            "type": "object",
                            "properties": {
                              "role": {
                                "type": "string"
                              },
                              "content": {
                                "type": "string",
                                "nullable": true
                              }
                            }
                          },
                          "finish_reason": {
                            "type": "string",
                            "nullable": true
                          }
                        }
                      }
                    },
                    "usage": {
                      "type": "object",
                      "properties": {
                        "prompt_tokens": {
                          "type": "integer"
                        },
                        "completion_tokens": {
                          "type": "integer"
                        },
                        "total_tokens": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "使用自己的千流令牌，仅在客户本机环境填写。"
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "服务端拒绝未通过认证的请求。",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                    "type": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
