Iflow2api - iFlow CLI OpenAI API 桥接
概述
iflow2api 是一个桥接工具,将 iFlow CLI 的 AI 服务转换为 OpenAI 兼容的 API 端点。这使得任何支持 OpenAI API 的应用(包括 OpenClaw)都可以无缝使用 iFlow CLI 的高级模型,无需手动调用 CLI。
核心优势:
- 通过
User-Agent: iFlow-Cli解锁 CLI 专属高级模型 - 内置 OAuth 登录,无需单独配置 iFlow CLI
- 标准 OpenAI API 兼容 (
/v1/models,/v1/chat/completions) - 支持思考链 (reasoning_content) 输出
- 统一管理多个 AI 模型
工作流决策树
开始
│
├── 首次安装? → 是 → 参见 [安装和配置](https://github.com/cacaview/iflow2api)
│ │
│ └── 完成 → 服务启动
│
└── 已安装? → 是 → 检查服务状态
│
├── 服务未运行 → 启动服务
│
└── 服务运行中 → 直接使用
快速开始
1. 安装 iflow2api
pip3 install iflow2api
推荐版本:v1.6.10 或更高
2. 启动服务
python3 -m iflow2api --host 127.0.0.1 --port 28000
关键参数:
--host: 监听地址(默认 0.0.0.0)--port: 监听端口(默认 8000,推荐 28000)--log-level: 日志级别(INFO, DEBUG, ERROR)
后台运行:
nohup python3 -m iflow2api --host 127.0.0.1 --port 28000 > ~/.iflow2api/iflow2api.log 2>&1 &
3. 验证服务
# 列出可用模型
curl http://127.0.0.1:28000/v1/models
# 测试模型调用
curl -X POST http://127.0.0.1:28000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "glm-5",
"messages": [{"role": "user", "content": "你好"}]
}'
4. 集成到 OpenClaw
参见 OpenClaw 集成指南 了解详细配置步骤。
支持的模型
iflow2api 默认提供 12 个高级模型:
推理模型(支持思考链)
| 模型 | 上下文 | 特点 |
|---|---|---|
| glm-5 | 128K | 强大的推理能力,推荐用于复杂任务 |
| minimax-m2.5 | 200K | 强大的推理和长文本理解 |
| kimi-k2.5 | 256K | 超长上下文,适合长文档分析 |
| kimi-k2-thinking | - | 专门用于深度推理 |
代码模型
| 模型 | 特点 |
|---|---|
| qwen3-coder-plus | 强大的代码生成和理解能力 |
| glm-5-code | 代码专用,性能优秀 |
通用对话模型
| 模型 | 特点 |
|---|---|
| glm-4.7 | 平衡性能和成本 |
| glm-4.6 | 轻量级通用模型 |
| deepseek-v3.2-chat | DeepSeek 最新对话模型 |
多模态模型
| 模型 | 特点 |
|---|---|
| qwen-vl-max | 强大的视觉理解能力 |
在 OpenClaw 中使用
配置方式
编辑 ~/.openclaw/agents/main/agent/models.json,添加 iflow2api provider:
{
"providers": [
{
"id": "iflow2api",
"apiType": "openai-completions",
"baseURL": "http://127.0.0.1:28000/v1",
"models": [
{"id": "glm-5"},
{"id": "glm-4.7"},
{"id": "glm-4.6"},
{"id": "deepseek-v3.2-chat"},
{"id": "qwen3-coder-plus"},
{"id": "kimi-k2.5"},
{"id": "kimi-k2-thinking"},
{"id": "minimax-m2.5"},
{"id": "qwen-vl-max"},
{"id": "glm-5-code"}
]
}
]
}
使用模型
# 设置默认模型
openclaw models set iflow2api/glm-5
# 或者在对话中指定
"请使用 iflow2api/glm-5 模型分析这个代码"
思考链 (Reasoning Chain) 支持
部分模型(如 glm-5, kimi-k2-thinking)支持思考链输出。在 OpenClaw 中,可以通过 /reasoning 命令启用:
/reasoning on # 启用推理输出
模型会在 reasoning_content 字段中返回详细的思考过程。
脚本工具
技能包含以下便捷脚本:
scripts/start_service.sh
启动/停止/重启 iflow2api 服务
# 启动服务
bash scripts/start_service.sh start
# 停止服务
bash scripts/start_service.sh stop
# 重启服务
bash scripts/start_service.sh restart
# 查看状态
bash scripts/start_service.sh status
scripts/check_status.py
检查服务运行状态和可用模型
python3 scripts/check_status.py
scripts/list_models.py
列出所有可用的模型及其详细信息
# 简单列表
python3 scripts/list_models.py
# 详细信息
python3 scripts/list_models.py --verbose
scripts/test_model.py
测试指定模型的调用
# 测试 glm-5
python3 scripts/test_model.py glm-5
# 自定义测试消息
python3 scripts/test_model.py glm-5 --message "写一个 Python 快速排序"
# 启用推理输出
python3 scripts/test_model.py glm-5 --reasoning
配置文件
iflow2api 配置
默认配置文件:~/.iflow2api/config.json
{
"host": "127.0.0.1",
"port": 28000,
"log_level": "INFO",
"oauth": {
"auto_login": true
}
}
iFlow 配置(可选)
如果已经配置 iFlow CLI,iflow2api 会自动读取 ~/.iflow/settings.json 中的凭据:
{
"api_key": "sk-xxxxxxxxxxxxxxxxxxxx",
"base_url": "https://apis.iflow.cn/v1"
}
最佳实践
1. 服务管理
- 使用后台服务管理(如 systemd 或 launchd)确保服务稳定运行
- 定期检查服务日志:
tail -f ~/.iflow2api/iflow2api.log - 监控端口占用:
lsof -i :28000
2. 模型选择
- 复杂推理任务:使用
glm-5或kimi-k2-thinking - 长文档分析:使用
kimi-k2.5(256K 上下文) - 代码编写:使用
qwen3-coder-plus或glm-5-code - 日常对话:使用
glm-4.7或deepseek-v3.2-chat - 视觉理解:使用
qwen-vl-max
3. 成本优化
- 对于简单任务,使用轻量级模型(glm-4.6)降低成本
- 对非推理任务禁用 thinking 输出
- 合理设置 temperature 参数(0-1)
4. 错误处理
启用重试机制处理网络抖动:
import time
import requests
def call_with_retry(model, messages, max_retries=3):
for i in range(max_retries):
try:
response = requests.post(
"http://127.0.0.1:28000/v1/chat/completions",
json={"model": model, "messages": messages},
timeout=120
)
return response.json()
except Exception as e:
if i == max_retries - 1:
raise
time.sleep(2 ** i) # 指数退避
管理界面
iflow2api 提供 Web 管理界面:
- 管理界面: http://127.0.0.1:28000/admin
- API 文档: http://127.0.0.1:28000/docs
- Swagger UI: http://127.0.0.1:28000/docs
在管理界面中可以:
- 查看服务状态和统计
- 重新登录 iFlow 账户
- 查看调用日志
- 测试 API 调用
故障排查
问题:服务无法启动
检查:
- Python 版本(需要 Python 3.7+)
- 依赖安装:
pip3 install --upgrade iflow2api - 端口占用:
lsof -i :28000
问题:模型调用失败
检查:
- 服务是否运行:
curl http://127.0.0.1:28000/v1/models - 日志查看:
tail -n 50 ~/.iflow2api/iflow2api.log - OAuth 登录状态:访问 http://127.0.0.1:28000/admin
问题:OpenClaw 无法识别模型
检查:
- models.json 配置是否正确
- 服务是否可访问:
curl http://127.0.0.1:28000/v1/models - 重启 OpenClaw gateway:
openclaw gateway restart
参考资料
- 安装和配置: setup.md
- OpenClaw 集成: openclaw_integration.md
- 模型详情: models.md
- iflow2api GitHub: https://github.com/cacaview/iflow2api
- iFlow CLI 文档: https://iflow.cn/docs