中文文档 | English
一个用 Rust 编写的统一逆向 API 包装器,提供对多个 AI 服务的无缝访问,包括 ChatGPT、Grok、DeepSeek、Qwen 等(示例只支持Qwen,其他暂时集成,自测使用)
- 多模型支持:统一接口支持
ChatGPT、Grok (XAI)、DeepSeek、Qwen 模型 - 多模态能力:支持文本、图片、视频、音频和文档(通过 Qwen)
- RESTful API:简洁的、兼容 OpenAI 的 API 设计
- 流式响应:实时流式传输,提供更好的用户体验
- 媒体生成:图片和视频生成功能
- 文件上传:支持上传和处理各种文件类型
- 代理支持:可配置的代理设置,提供网络灵活性
- Web 仪表板:内置监控和统计仪表板
- 线程管理:对话历史跟踪
- 浏览器模拟:高级 HTTP 客户端,带有浏览器模拟功能
- Rust:1.70 或更高版本
- 操作系统:Linux、macOS 或 Windows
- 网络:互联网连接(支持代理)
git clone https://github.com/map-A/qwen2api.git
cd qwen2apicargo build --release您需要从要使用的服务获取 token:
#### DeepSeek Token
1. 访问 https://chat.deepseek.com/
2. 登录并开始对话
3. 打开开发者工具(F12)→ Application → LocalStorage
4. 找到
userToken 并复制其值5. 保存到 .deepseek_token 文件或通过 API 设置
- 访问 https://chat.qwen.ai/
- 登录您的账户
- 打开开发者工具(F12)→ Application → Cookies
- 找到
tokencookie 并复制其值 - 保存到
.qwen_token文件或通过 API 设置
# 基础使用
./target/release/api_server
# 自定义端口和主机
./target/release/api_server --host 127.0.0.1 --port 8080
# 使用环境变量
export API_HOST=0.0.0.0
export API_PORT=6969
./target/release/api_server~~# 配置 DeepSeek token~~
~~curl -X POST http://localhost:6969/v1/config/deepseek \~~
~~-H "Content-Type: application/json" \~~
~~-d '{"token": "your_deepseek_token"}'~~
# 配置 Qwen token
curl -X POST http://localhost:6969/v1/config/qwen \
-H "Content-Type: application/json" \
-d '{"token": "your_qwen_token"}'http://localhost:6969
GET /health响应:
{
"status": "ok",
"active_threads": 5,
"version": "0.1.0"
}GET /v1/models响应:
{
"data": [
{
"id": "grok-3-auto",
"object": "model",
"created": 1677610602,
"owned_by": "xai"
},
~~{~~
~~"id": "deepseek-r1",~~
~~"object": "model",~~
~~"created": 1677610602,~~
~~"owned_by": "deepseek"~~
~~},~~
{
"id": "qwen3-max",
"object": "model",
"created": 1677610602,
"owned_by": "alibaba"
}
]
}POST /v1/threads
Content-Type: application/json
{
"model": "qwen3-max",
"messages": [
{
"role": "user",
"content": "你好!"
}
],
"metadata": {} // 可选
}响应:
{
"id": "thread-uuid-123",
"object": "thread",
"created_at": 1234567890,
"metadata": null
}POST /v1/threads/{thread_id}/messages
Content-Type: application/json
{
"role": "user",
"content": "你能做什么?"
}POST /v1/responses
Content-Type: application/json
{
"thread_id": "thread-uuid-123",
"model": "qwen3-max",
"file_ids": ["file-uuid-456"], // 可选,用于多模态
}响应:
{
"response": "我可以帮助您完成各种任务...",
"extra_data": { ... }
}POST /v1/files/upload
Content-Type: multipart/form-data
file: <二进制文件数据>响应:
{
"id": "file-uuid-456",
"filename": "image.jpg",
"type": "image/jpeg"
}POST /v1/images/generate
Content-Type: application/json
{
"prompt": "一只可爱的橙色小猫",
"size": "1:1", // 选项:1:1, 16:9, 9:16
"model": "qwen3-max",
"download": true // 自动下载到 ./generated/
}响应:
{
"image_url": "https://...",
"local_path": "./generated/images/1234567890.png"
}POST /v1/videos/generate
Content-Type: application/json
{
"prompt": "一只小猫在草地上玩耍",
"size": "16:9", // 选项:16:9, 9:16
"model": "qwen3-max",
"download": true // 自动下载到 ./generated/
}响应:
{
"video_url": "https://...",
"local_path": "./generated/videos/1234567890.mp4"
}GET /v1/threadsGET /v1/threads/{thread_id}DELETE /v1/threads/{thread_id}GET /v1/threads/{thread_id}/messages# 上传图片
FILE_ID=$(curl -s -X POST http://localhost:6969/v1/files/upload \
-F "file=@test_image.jpg" | jq -r '.id')
# 创建线程
THREAD_ID=$(curl -s -X POST http://localhost:6969/v1/threads \
-H "Content-Type: application/json" \
-d '{"model": "qwen3-max"}' | jq -r '.id')
# 添加消息
curl -s -X POST http://localhost:6969/v1/threads/$THREAD_ID/messages \
-H "Content-Type: application/json" \
-d '{"role": "user", "content": "请描述这张图片"}'
# 获取带文件的响应
curl -s -X POST http://localhost:6969/v1/responses \
-H "Content-Type: application/json" \
-d "{\"thread_id\": \"$THREAD_ID\", \"model\": \"qwen3-max\", \"file_ids\": [\"$FILE_ID\"]}"curl -s -X POST http://localhost:6969/v1/images/generate \
-H "Content-Type: application/json" \
-d '{
"prompt": "海洋上美丽的日落",
"size": "16:9",
"model": "qwen3-max",
"download": true
}'use reverse_api::qwen::client::qwen::QwenClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// 使用 token 创建客户端
let client = QwenClient::with_token("your_token")?;
// 开始对话
let response = client.start_convo("你好,最近怎么样?", None, None).await?;
println!("响应:{}", response.response.unwrap_or_default());
Ok(())
}import requests
BASE_URL = "http://localhost:6969"
# 创建线程
response = requests.post(f"{BASE_URL}/v1/threads", json={
"model": "qwen3-max"
})
thread_id = response.json()["id"]
# 添加消息
requests.post(f"{BASE_URL}/v1/threads/{thread_id}/messages", json={
"role": "user",
"content": "你好,世界!"
})
# 获取响应
response = requests.post(f"{BASE_URL}/v1/responses", json={
"thread_id": thread_id,
"model": "qwen3-max"
})
print(response.json()["response"])const BASE_URL = 'http://localhost:6969';
async function chat(message) {
// 创建线程
const threadRes = await fetch(`${BASE_URL}/v1/threads`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ model: 'qwen3-max' })
});
const { id: threadId } = await threadRes.json();
// 添加消息
await fetch(`${BASE_URL}/v1/threads/${threadId}/messages`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ role: 'user', content: message })
});
// 获取响应
const responseRes = await fetch(`${BASE_URL}/v1/responses`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ thread_id: threadId, model: 'qwen3-max' })
});
const { response } = await responseRes.json();
return response;
}
chat('你好!').then(console.log);| 提供商 | 模型 ID | 功能 | 多模态 |
|---|---|---|---|
| 阿里巴巴 | qwen3-max |
高级多模态 | ✅ |
| 阿里巴巴 | qwen3-plus |
增强模型 | ✅ |
| 阿里巴巴 | qwen3-turbo |
快速模型 | ✅ |
Qwen 模型支持以下文件类型:
- 图片:JPG、PNG、GIF、WebP、BMP
- 文档:PDF、TXT、DOC、DOCX
- 音频:MP3、WAV、AAC、M4A
- 视频:MP4、AVI、MOV、MKV
qwen2api/
├── src/
│ ├── bin/
│ │ ├── api_server.rs # 主服务器程序
│ │ └── api/ # API 模块
│ │ ├── server.rs # 服务器设置
│ │ ├── handlers.rs # 请求处理器
│ │ ├── state.rs # 应用状态
│ │ ├── dashboard.rs # Web 仪表板
│ │ └── docs.rs # API 文档
│ ├── chatgpt/ # ChatGPT 客户端
│ ├── grok/ # Grok 客户端
│ ├── ~~deepseek/~~ ~~# DeepSeek 客户端~~
│ └── qwen/ # Qwen 客户端(多模态)
├── examples/ # 使用示例
├── generated/ # 自动生成的媒体文件
│ ├── images/
│ └── videos/
├── Cargo.toml # Rust 依赖
└── README_CN.md # 本文件
api_server [OPTIONS]
选项:
--host <HOST> 服务器主机(默认:0.0.0.0)
--port <PORT> 服务器端口(默认:6969)
--help 显示帮助信息API_HOST:服务器主机(默认:0.0.0.0)API_PORT:服务器端口(默认:6969)DEEPSEEK_TOKEN:DeepSeek 认证 tokenQWEN_TOKEN:Qwen 认证 token
您也可以将 token 存储在文件中:
- .deepseek_token - DeepSeek token
.qwen_token- Qwen token
服务器运行后,您可以访问:
- API 文档:http://localhost:6969/docs
- 仪表板:http://localhost:6969/dashboard
- 查看统计信息
- 监控活动线程
- 跟踪请求
~~# DeepSeek 示例~~
~~DEEPSEEK_TOKEN="your_token" cargo run --example deepseek_example~~
# Qwen 基础示例
QWEN_TOKEN="your_token" cargo run --example qwen_example
# Qwen 多模态示例
QWEN_TOKEN="your_token" cargo run --example qwen_multimodal_example
# Qwen 图片生成示例
QWEN_TOKEN="your_token" cargo run --example qwen_image_generation_example
# Grok 示例(需要代理)
cargo run --example grok_examplecargo testcargo build --release编译后的二进制文件位于 ./target/release/api_server
如果遇到网络问题:
- 检查防火墙:确保防火墙允许出站连接
- 验证 token:确保您的 token 有效且未过期
1. DeepSeek:从 https://chat.deepseek.com/ 获取新的 token
- 登录 → F12 → Application → LocalStorage →
2. Qwen:从 https://chat.qwen.ai/ 获取新的 tokenuserToken
- 登录 → F12 → Application → Cookies →
token
如果端口 6969 已被占用:
api_server --port 8080视频生成通常需要 1-3 分钟。这是正常的,因为视频渲染比较复杂。
欢迎贡献!请随时提交 Pull Request。
- Fork 仓库
- 创建您的特性分支(
git checkout -b feature/amazing-feature) - 提交您的更改(
git commit -m '添加一些很棒的功能') - 推送到分支(
git push origin feature/amazing-feature) - 打开一个 Pull Request
本项目采用 MIT 许可证 - 详见 LICENSE 文件。
注意:这是一个用于教育目的的逆向工程 API 包装器。使用此工具时,请确保遵守各个 AI 提供商的服务条款。