{
  "openapi": "3.0.3",
  "info": {
    "title": "CokeAPI",
    "description": "CokeAPI OpenAI 兼容接口。\n\n- 文档站: https://doc.cokeapi.com/\n- 模型价格: https://www.cokeapi.com/pricing\n- Base URL 推荐: https://www.cokeapi.com/v1\n- 鉴权: Authorization: Bearer sk-...\n\n模型以站点当前可售为准；图像/语音等能力视上游是否开放。",
    "version": "1.0.0",
    "contact": {
      "name": "CokeAPI",
      "url": "https://www.cokeapi.com"
    }
  },
  "servers": [
    {
      "url": "https://www.cokeapi.com/v1",
      "description": "推荐：带 /v1"
    },
    {
      "url": "https://www.cokeapi.com",
      "description": "部分客户端用根域名，自行拼接 /v1"
    }
  ],
  "tags": [
    {
      "name": "Models",
      "description": "模型列表"
    },
    {
      "name": "Chat",
      "description": "聊天补全"
    },
    {
      "name": "Images",
      "description": "图像生成（视上游是否开放）"
    },
    {
      "name": "Embeddings",
      "description": "向量嵌入"
    },
    {
      "name": "Audio",
      "description": "语音相关"
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API Key",
        "description": "控制台 → 令牌 创建的 sk- Key"
      }
    },
    "schemas": {
      "ChatMessage": {
        "type": "object",
        "required": [
          "role",
          "content"
        ],
        "properties": {
          "role": {
            "type": "string",
            "enum": [
              "system",
              "user",
              "assistant",
              "tool"
            ]
          },
          "content": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "type": "object"
                }
              }
            ]
          }
        }
      },
      "ChatCompletionRequest": {
        "type": "object",
        "required": [
          "model",
          "messages"
        ],
        "properties": {
          "model": {
            "type": "string",
            "description": "模型名，从 https://www.cokeapi.com/pricing 复制",
            "example": "gpt-5.4"
          },
          "messages": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ChatMessage"
            }
          },
          "stream": {
            "type": "boolean",
            "default": false
          },
          "temperature": {
            "type": "number"
          },
          "max_tokens": {
            "type": "integer"
          }
        }
      },
      "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": {
                  "$ref": "#/components/schemas/ChatMessage"
                },
                "finish_reason": {
                  "type": "string"
                }
              }
            }
          },
          "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"
              }
            }
          }
        }
      }
    }
  },
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/models": {
      "get": {
        "tags": [
          "Models"
        ],
        "summary": "列出可用模型",
        "operationId": "listModels",
        "responses": {
          "200": {
            "description": "模型列表",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "type": "string"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "object": {
                            "type": "string"
                          },
                          "owned_by": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "未授权",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/models/{model}": {
      "get": {
        "tags": [
          "Models"
        ],
        "summary": "获取单个模型",
        "operationId": "retrieveModel",
        "parameters": [
          {
            "name": "model",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "模型详情"
          },
          "404": {
            "description": "模型不存在"
          }
        }
      }
    },
    "/chat/completions": {
      "post": {
        "tags": [
          "Chat"
        ],
        "summary": "创建聊天补全",
        "description": "OpenAI 兼容聊天接口。支持 stream=true 流式返回。",
        "operationId": "createChatCompletion",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatCompletionRequest"
              },
              "examples": {
                "basic": {
                  "summary": "基础对话",
                  "value": {
                    "model": "gpt-5.4",
                    "messages": [
                      {
                        "role": "user",
                        "content": "你好，用一句话介绍你自己"
                      }
                    ]
                  }
                },
                "stream": {
                  "summary": "流式对话",
                  "value": {
                    "model": "gpt-5.4",
                    "stream": true,
                    "messages": [
                      {
                        "role": "user",
                        "content": "写一首四行小诗"
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "成功",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChatCompletionResponse"
                }
              }
            }
          },
          "401": {
            "description": "Key 无效",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "限流"
          },
          "500": {
            "description": "上游或服务错误"
          }
        }
      }
    },
    "/completions": {
      "post": {
        "tags": [
          "Chat"
        ],
        "summary": "文本补全（旧接口）",
        "operationId": "createCompletion",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "model",
                  "prompt"
                ],
                "properties": {
                  "model": {
                    "type": "string"
                  },
                  "prompt": {
                    "type": "string"
                  },
                  "max_tokens": {
                    "type": "integer"
                  },
                  "stream": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "成功"
          }
        }
      }
    },
    "/responses": {
      "post": {
        "tags": [
          "Chat"
        ],
        "summary": "Responses API",
        "description": "OpenAI Responses 格式。部分上游支持。",
        "operationId": "createResponse",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "model": {
                    "type": "string"
                  },
                  "input": {},
                  "stream": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "成功"
          }
        }
      }
    },
    "/images/generations": {
      "post": {
        "tags": [
          "Images"
        ],
        "summary": "图像生成",
        "description": "是否可用取决于当前上游；请先在模型页确认。",
        "operationId": "createImage",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "prompt"
                ],
                "properties": {
                  "model": {
                    "type": "string"
                  },
                  "prompt": {
                    "type": "string"
                  },
                  "n": {
                    "type": "integer",
                    "default": 1
                  },
                  "size": {
                    "type": "string",
                    "example": "1024x1024"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "成功"
          }
        }
      }
    },
    "/embeddings": {
      "post": {
        "tags": [
          "Embeddings"
        ],
        "summary": "创建嵌入向量",
        "operationId": "createEmbedding",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "model",
                  "input"
                ],
                "properties": {
                  "model": {
                    "type": "string"
                  },
                  "input": {
                    "oneOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "array",
                        "items": {
                          "type": "string"
                        }
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "成功"
          }
        }
      }
    },
    "/audio/speech": {
      "post": {
        "tags": [
          "Audio"
        ],
        "summary": "文本转语音",
        "operationId": "createSpeech",
        "responses": {
          "200": {
            "description": "音频二进制"
          }
        }
      }
    },
    "/audio/transcriptions": {
      "post": {
        "tags": [
          "Audio"
        ],
        "summary": "语音转文字",
        "operationId": "createTranscription",
        "responses": {
          "200": {
            "description": "成功"
          }
        }
      }
    },
    "/messages": {
      "post": {
        "tags": [
          "Chat"
        ],
        "summary": "Claude Messages API",
        "description": "Anthropic 兼容格式。部分渠道支持。",
        "operationId": "createMessage",
        "responses": {
          "200": {
            "description": "成功"
          }
        }
      }
    }
  },
  "externalDocs": {
    "description": "CokeAPI 开发者文档",
    "url": "https://doc.cokeapi.com/"
  }
}
