在 Dify 中使用 oairoute
- 开源的 LLM 应用编排平台
- 通过 OpenAI 兼容模型接入 OAIRoute
- 可以在工作流里混用多家模型
第一步:获取 API Key
在 OAIRoute 控制台 创建。
Create one in the OAIRoute console.
第二步:添加模型供应商
进入 Dify,点右上角头像 → 设置 → 模型供应商,找到 OpenAI-API-compatible,点 添加模型:
选 LLM(要接 embedding 时另建一条,类型选 Text Embedding)。
填模型 ID,例如 gpt-4o-mini。这个名字会显示在 Dify 的模型下拉里,可以和真实 ID 不同,但建议保持一致。
你的 OAIRoute Key。
https://api.oairoute.com/v1
填该模型的真实上限,例如 128000。
单次请求允许的最大输出 token 数,例如 4096。
仅多模态模型需要开启。
工作流里要用「工具」节点时必须开启。
点 保存,Dify 会做一次连通性测试,通过后该模型即可用。
Open Dify, click your avatar in the top right → Settings → Model providers, find OpenAI-API-compatible, and click Add model:
Choose LLM (create a separate entry with type Text Embedding if you need embeddings).
Enter the model ID, e.g. gpt-4o-mini. This name appears in Dify's model dropdown and can differ from the real ID, though keeping them the same is recommended.
Your OAIRoute key.
https://api.oairoute.com/v1
Enter the model's real limit, e.g. 128000.
The maximum output tokens allowed per request, e.g. 4096.
Enable only for multimodal models.
Required if you use "Tool" nodes in a workflow.
Click Save; Dify runs a connectivity test, and the model is usable once it passes.
第三步:在工作流中使用
新建应用 → 选「工作流」或「聊天助手」,在模型下拉里选中刚添加的模型。也可以在一个应用里配置「模型回退」,主模型失败时自动切到备用。
Create an app → choose "Workflow" or "Chat assistant", then select the model you just added in the dropdown. You can also configure model fallback in an app so it switches to a backup automatically when the primary fails.
常见问题
保存时提示 Authorization failed
API Key 有误,或 endpoint 少了 /v1。
模型下拉里看不到
保存后需要刷新页面。如果仍然没有,检查「模型类型」是否选错。
工作流执行报 context length exceeded
「模型上下文长度」填大了。改成模型真实值,或者在工作流里加一个文本截断节点。
Dify 会对同一段提示词做自己的 token 估算,与上游实际计数可能有偏差。接近上限时建议留出 10% 余量。
"Authorization failed" on save
The API key is wrong, or the endpoint is missing /v1.
The model doesn't appear in the dropdown
Refresh the page after saving. If it's still missing, check whether "Model type" was chosen correctly.
Workflow fails with context length exceeded
"Model context length" is set too high. Change it to the model's real value, or add a text truncation node to the workflow.
Dify estimates tokens for a prompt on its own, which may differ from the upstream's actual count. Leave about 10% headroom when you're near the limit.