### Local Installation and Running Qwen-Proxy Source: https://github.com/rfym21/qwen2api/blob/main/README.md This guide details the steps for setting up Qwen-Proxy on a local machine. It includes cloning the repository, installing Node.js dependencies using npm, copying and configuring the `.env` file, and starting the service using `npm start` for intelligent startup or `npm run dev` for development mode. ```bash # 克隆项目 git clone https://github.com/Rfym21/Qwen2API.git cd Qwen2API # 安装依赖 npm install # 配置环境变量 cp .env.example .env # 编辑 .env 文件 # 智能启动 (推荐 - 自动判断单进程/多进程) npm start # 开发模式 npm run dev ``` -------------------------------- ### Docker Compose for Qwen-Proxy Deployment Source: https://github.com/rfym21/qwen2api/blob/main/README.md This section provides instructions for deploying Qwen-Proxy using Docker Compose. It involves downloading a `docker-compose.yml` file and then using `docker compose` commands to pull images and start the service. This method is suitable for more complex deployments or for managing multiple related services. ```bash # 下载配置文件 curl -o docker-compose.yml https://raw.githubusercontent.com/Rfym21/Qwen2API/refs/heads/main/docker-compose.yml # 启动服务 docker compose pull && docker compose up -d ``` -------------------------------- ### API Authentication Example (Bash) Source: https://github.com/rfym21/qwen2api/blob/main/README.md Demonstrates how to authenticate API requests using both administrator and regular API keys via curl. The Authorization header is used to pass the API key. ```bash # 使用管理员密钥 curl -H "Authorization: Bearer sk-admin123" http://localhost:3000/v1/models # 使用普通密钥 curl -H "Authorization: Bearer sk-user456" http://localhost:3000/v1/chat/completions ``` -------------------------------- ### GET /v1/models Source: https://github.com/rfym21/qwen2api/blob/main/README.md Retrieves a list of all available AI models supported by the API. ```APIDOC ## 🔍 获取模型列表 获取所有可用的 AI 模型列表。 ```http GET /v1/models Authorization: Bearer sk-your-api-key ``` ```http GET /models (免认证) ``` **响应示例:** ```json { "object": "list", "data": [ { "id": "qwen-max-latest", "object": "model", "created": 1677610602, "owned_by": "qwen" } ] } ``` ``` -------------------------------- ### Get Model List API Request (HTTP) Source: https://github.com/rfym21/qwen2api/blob/main/README.md Shows how to make a GET request to retrieve a list of available AI models. Authentication is required for some endpoints, while others are publicly accessible. ```http GET /v1/models Authorization: Bearer sk-your-api-key ``` ```http GET /models (免认证) ``` -------------------------------- ### Chat Completion Request Body (JSON) Source: https://github.com/rfym21/qwen2api/blob/main/README.md Provides an example JSON payload for the chat completions API. It specifies the model to use, the conversation history (messages), and generation parameters. ```json { "model": "qwen-max-latest", "messages": [ { "role": "system", "content": "你是一个有用的助手。" }, { "role": "user", "content": "你好,请介绍一下自己。" } ], "stream": false, "temperature": 0.7, "max_tokens": 2000 } ``` -------------------------------- ### Image Generation Request Body (JSON) Source: https://github.com/rfym21/qwen2api/blob/main/README.md An example JSON payload for image generation. It includes the model, user prompt, and optional parameters like 'size' for image dimensions and 'stream' for response format. ```json { "model": "qwen-max-latest-image", "messages": [ { "role": "user", "content": "画一只在花园里玩耍的小猫咪,卡通风格" } ], "size": "1:1", "stream": false } ``` -------------------------------- ### Docker Run Command for Qwen-Proxy Source: https://github.com/rfym21/qwen2api/blob/main/README.md This command demonstrates how to run the Qwen-Proxy service using Docker. It maps ports, sets necessary environment variables for API keys, data saving, and cache modes, and mounts a volume for cache persistence. This is a direct way to deploy the service in a containerized environment. ```bash docker run -d \ -p 3000:3000 \ -e API_KEY=sk-admin123,sk-user456,sk-user789 \ -e DATA_SAVE_MODE=none \ -e CACHE_MODE=file \ -e ACCOUNTS= \ -v ./caches:/app/caches \ --name qwen2api \ rfym21/qwen2api:latest ``` -------------------------------- ### Configure Environment Variables for Qwen-Proxy Source: https://github.com/rfym21/qwen2api/blob/main/README.md This snippet shows the essential environment variables required to configure the Qwen-Proxy service. These variables control network settings, security, performance optimizations, and data persistence. Ensure these are set in a `.env` file for local deployments or passed as environment variables in containerized environments. ```bash # 🌐 服务配置 LISTEN_ADDRESS=localhost # 监听地址 SERVICE_PORT=3000 # 服务端口 # 🔐 安全配置 API_KEY=sk-123456,sk-456789 # API 密钥 (必填,支持多密钥) ACCOUNTS= # 账户配置 (格式: user1:pass1,user2:pass2) # 🚀 PM2 多进程配置 PM2_INSTANCES=1 # PM2进程数量 (1/数字/max) PM2_MAX_MEMORY=1G # PM2内存限制 (100M/1G/2G等) # 注意: PM2集群模式下所有进程共用同一个端口 # 🔍 功能配置 SEARCH_INFO_MODE=table # 搜索信息展示模式 (table/text) OUTPUT_THINK=true # 是否输出思考过程 (true/false) SIMPLE_MODEL_MAP=false # 简化模型映射 (true/false) # 🗄️ 数据存储 DATA_SAVE_MODE=none # 数据保存模式 (none/file/redis) REDIS_URL= # Redis 连接地址 (可选) # 📸 缓存配置 CACHE_MODE=default # 图片缓存模式 (default/file) ``` -------------------------------- ### POST /v1/chat/completions (Image Generation/Editing) Source: https://github.com/rfym21/qwen2api/blob/main/README.md Enables text-to-image generation using `-image` models and image editing using `-image-edit` models. Allows specifying image size and stream options. ```APIDOC ## 🎨 图像生成/编辑 使用 `-image` 模型启用文本到图像生成功能。 使用 `-image-edit` 模型启用图像修改功能。 当使用``-image` 时你可以通过在请求体中添加 `size` 参数或在消息内容中包含特定关键词 `1:1`, `4:3`, `3:4`, `16:9`, `9:16` 来控制图片尺寸。 ```http POST /v1/chat/completions Content-Type: application/json Authorization: Bearer sk-your-api-key ``` **请求体:** ```json { "model": "qwen-max-latest-image", "messages": [ { "role": "user", "content": "画一只在花园里玩耍的小猫咪,卡通风格" } ], "size": "1:1", "stream": false } ``` **支持的参数:** - `size`: 图片尺寸,支持 `"1:1"`、`"4:3"`、`"3:4"`、`"16:9"`、`"9:16"` - `stream`: 支持流式和非流式响应 **响应示例:** ```json { "created": 1677652288, "model": "qwen-max-latest", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "![image](https://example.com/generated-image.jpg)" }, "finish_reason": "stop" } ] } ``` ``` -------------------------------- ### API Authentication Source: https://github.com/rfym21/qwen2api/blob/main/README.md Explains the API's multi-key authentication mechanism and how to include the API key in requests. ```APIDOC ## 🔐 API 认证说明 本API支持多密钥认证机制,所有API请求都需要在请求头中包含有效的API密钥: ```http Authorization: Bearer sk-your-api-key ``` **支持的密钥类型:** - **管理员密钥**: 第一个配置的API_KEY,拥有完整权限 - **普通密钥**: 其他配置的API_KEY,仅可调用API接口 **认证示例:** ```bash # 使用管理员密钥 curl -H "Authorization: Bearer sk-admin123" http://localhost:3000/v1/models # 使用普通密钥 curl -H "Authorization: Bearer sk-user456" http://localhost:3000/v1/chat/completions ``` ``` -------------------------------- ### Chat Completion API Request (HTTP) Source: https://github.com/rfym21/qwen2api/blob/main/README.md Defines the structure for making a POST request to the chat completions endpoint. This includes the model, messages, and optional parameters like temperature and max_tokens. ```http POST /v1/chat/completions Content-Type: application/json Authorization: Bearer sk-your-api-key ``` -------------------------------- ### POST /v1/chat/completions Source: https://github.com/rfym21/qwen2api/blob/main/README.md Allows users to send chat messages and receive AI-generated responses. Supports various parameters for controlling the conversation. ```APIDOC ## 💬 聊天对话 发送聊天消息并获取 AI 回复。 ```http POST /v1/chat/completions Content-Type: application/json Authorization: Bearer sk-your-api-key ``` **请求体:** ```json { "model": "qwen-max-latest", "messages": [ { "role": "system", "content": "你是一个有用的助手。" }, { "role": "user", "content": "你好,请介绍一下自己。" } ], "stream": false, "temperature": 0.7, "max_tokens": 2000 } ``` **响应示例:** ```json { "id": "chatcmpl-123", "object": "chat.completion", "created": 1677652288, "model": "qwen-max-latest", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "你好!我是一个AI助手..." }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 20, "completion_tokens": 50, "total_tokens": 70 } } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.