agentleFS
wangfeiwest2025wangfeiwest2025/openclaw-integration-skills/iflow2api/SKILL.md

iflow2api

Skill0 starsChanged 9 months agoMITView on GitHub

iflow2api 将 iFlow CLI 的 AI 服务暴露为 OpenAI 兼容 API。使用当需要:(1) 将 iFlow CLI 模型集成到 OpenClaw 或其他 OpenAI 兼容客户端,(2) 访问 iFlow CLI 专属高级模型(GLM-5, DeepSeek, Qwen, Kimi),(3) 使用支持思考链 (reasoning_content) 的推理模型,(4) 通过统一 API 管理多个 iFlow 模型。

  • Sends data out

The file

Files
SKILL.md

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-5128K强大的推理能力,推荐用于复杂任务
minimax-m2.5200K强大的推理和长文本理解
kimi-k2.5256K超长上下文,适合长文档分析
kimi-k2-thinking-专门用于深度推理

代码模型

模型特点
qwen3-coder-plus强大的代码生成和理解能力
glm-5-code代码专用,性能优秀

通用对话模型

模型特点
glm-4.7平衡性能和成本
glm-4.6轻量级通用模型
deepseek-v3.2-chatDeepSeek 最新对话模型

多模态模型

模型特点
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 管理界面:

在管理界面中可以:

  • 查看服务状态和统计
  • 重新登录 iFlow 账户
  • 查看调用日志
  • 测试 API 调用

故障排查

问题:服务无法启动

检查:

  1. Python 版本(需要 Python 3.7+)
  2. 依赖安装:pip3 install --upgrade iflow2api
  3. 端口占用:lsof -i :28000

问题:模型调用失败

检查:

  1. 服务是否运行:curl http://127.0.0.1:28000/v1/models
  2. 日志查看:tail -n 50 ~/.iflow2api/iflow2api.log
  3. OAuth 登录状态:访问 http://127.0.0.1:28000/admin

问题:OpenClaw 无法识别模型

检查:

  1. models.json 配置是否正确
  2. 服务是否可访问:curl http://127.0.0.1:28000/v1/models
  3. 重启 OpenClaw gateway:openclaw gateway restart

参考资料

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.