Run Dify apps on an OpenAI-API-compatible endpoint.

Updated 2026-07-16

Dify ships an OpenAI-API-compatible provider exactly for this: install it from the Marketplace, add each model with its id, https://api.apisrouter.com/v1 as the API Base URL, and one key. Your chatflows, agents, and workflows then run on any catalog model, Claude and DeepSeek included.

Quick answer: install the provider, add models by id.

In Dify, open Settings and go to Model Provider. Since Dify 1.0, providers are plugins: find OpenAI-API-compatible (published by langgenius) in the list or install it from the Marketplace, then click Add Model on its card. The dialog is per-model: choose the Model Type (LLM for chat models), enter the exact catalog id in Model Name, paste your key in API Key, and set API Base URL to https://api.apisrouter.com/v1. Leave Completion mode on Chat, then set Model context size and Upper bound for max tokens to the documented limits of the id you are adding. Save, and the model appears in the provider's list, selectable from every app's model dropdown. Repeat the dialog for each id you want; two minutes per model, once.

Model Type:                LLM
Model Name:                claude-sonnet-4-6
API Key:                   sk-YOUR-APISROUTER-KEY
API Base URL:              https://api.apisrouter.com/v1
Completion mode:           Chat
Model context size:        200000
Upper bound for max tokens: 64000

How Dify talks to a compatible provider.

Dify (langgenius on GitHub, roughly 149K stars) is the leading open-source LLM app platform: visual workflows, agent nodes, RAG pipelines over knowledge bases, and published apps with their own API endpoints. Every LLM node in that stack resolves to a model registered under some provider. The OpenAI-API-compatible provider is deliberately generic. Each model you add is a self-contained record, id, endpoint, key, limits, and Dify sends standard chat-completions requests to the configured base URL with your Model Name as the model string. Nothing in the request cares which vendor trained the model, so claude-sonnet-4-6 and deepseek-v4-pro are as valid here as any GPT id, and different models can even point at different endpoints if you ever need that. The per-model registration that feels like friction is also the control surface: the context size and max-tokens values you enter are what Dify's orchestrator uses to budget prompts, trim conversation history, and validate node settings. Enter honest numbers from the model's documentation. Overstating context produces requests the endpoint rejects; understating it silently truncates the context your RAG nodes worked to retrieve.

The fields that do real work.

Model Name is the wire value: it must match the gateway's /v1/models listing character for character, since it travels in every request. The optional model display name only relabels the UI. Completion mode should stay on Chat for every model in the current catalog; the Completion option exists for legacy text-completion endpoints and produces malformed requests against chat models. Model context size and Upper bound for max tokens are the pair people rush. Context size is the model's total window; the upper bound caps how many output tokens a node may request. Dify defaults both to 4096, which is far below what current models support, and leaving the defaults quietly cripples long-document RAG and long-form generation. Set them from the model documentation, not from habit. The capability selectors matter when your apps use them: Vision Support only for ids that accept image input, and the function-call setting to match the model's tool-use support, since agent nodes rely on it. A wrong capability claim fails at runtime inside the workflow, which is a slower place to debug than this dialog. If your workspace also uses embedding or rerank models, the same provider registers them under their own Model Type entries against the same base URL; confirm the specific ids are served by the endpoint before wiring knowledge-base settings to them.

curl -s https://api.apisrouter.com/v1/models \
  -H "Authorization: Bearer $APISROUTER_API_KEY" | head -50
# register these ids verbatim as Model Name entries

Choosing models for workflows and agents.

Dify's own overview pages show tokens per app, but the per-key usage view in the APIsRouter console adds the per-model split across all apps on the same page, which is the number that decides which id keeps the slot.

  • Workflow LLM nodes are volume: classification, extraction, routing, summarization steps that fire on every run. claude-haiku-4-5-20251001, gpt-5.4-mini, and gemini-3.5-flash keep per-run cost flat.
  • Agent nodes and complex reasoning steps earn claude-sonnet-4-6, and its dependable tool use matters more in agents than raw benchmark scores.
  • RAG answer nodes carry retrieved context on every call, so input pricing dominates; deepseek-v4-pro is worth testing where retrieval is heavy and answers are long.
  • Register a fast id and a strong id for the same role and A/B them per node: in Dify, switching a node's model is a dropdown, not a migration.
  • Published apps inherit their nodes' model choices, so the dropdown decision you make in the editor is the unit economics of the app you ship.

Pay-as-you-go · transparent per-model pricing

Selected models are priced below official list prices. Exact input, output, cache, and per-request prices are shown for each model.

ModelOfficial PriceOur Price
Claude Sonnet 4.6$3.00 / $15.00 per M$2.40 / $12.00 per M
Claude Haiku 4.5 20251001$1.00 / $5.00 per M$0.80 / $4.00 per M
GPT-5.4 Mini$0.75 / $4.50 per M$0.60 / $3.60 per M
Gemini 3.5 Flash$1.50 / $9.00 per M$1.20 / $7.20 per M
DeepSeek V4 Pro$0.43 / $0.87 per M$0.39 / $0.78 per M

Failure modes specific to Dify.

Provider missing from the list means the plugin is not installed: since Dify 1.0 the OpenAI-API-compatible provider ships as a Marketplace plugin, and fresh self-hosted instances start without it. Install it once per workspace. A model that saves but errors on first use is usually one of three things: a Model Name that does not match the catalog spelling, a base URL missing its /v1 (Dify appends route paths like /chat/completions to what you enter), or context/max-token values beyond what the model accepts. The error surfaces in the app or workflow log; the fix is back in the Add Model dialog. Agent nodes failing while plain chat nodes work points at the function-calling capability setting, or at a model whose tool use does not meet what the agent strategy expects. Test agents against claude-sonnet-4-6 first to separate configuration problems from model choice. And on self-hosted instances behind strict egress rules, remember it is the Dify api container that must reach the endpoint, not your browser; a curl from inside that container settles connectivity questions quickly.

Who routes Dify through a gateway.

  • Teams building LLM apps who want Claude, GPT, Gemini, and DeepSeek selectable per node without maintaining a vendor account per provider.
  • Self-hosters running Dify for internal tools, where one key in one provider keeps the whole workspace's cloud spend on a single usage log.
  • Builders comparing models on real workflows: each candidate is an Add Model dialog and a dropdown switch, not a new integration.
  • Developers without access to a given vendor's billing. Top-up based access with no card requirement removes the per-provider sign-up dependency.
  • Agencies shipping client apps on Dify who need per-project keys so each client's model spend reports itself.

Verify the endpoint and debug the first run.

Curl the models listing first and register ids from its output; hand-typed Model Names are the leading cause of not-found errors because the field is free text. Then run one chat completion against the id you registered, with the same key. Inside Dify, test in a scratch app before wiring production workflows: add an LLM node, select the new model, run once. Authentication errors point at the API Key field; not-found at the Model Name; connection errors at the base URL or container egress; length errors at the context and max-token values. Once runs flow, the APIsRouter console shows per-request model, token counts, and spend. Workflows multiply LLM calls in ways that are hard to eyeball from the editor, and the usage log is where a five-node pipeline's real token profile becomes visible, per model, per day.

curl -s https://api.apisrouter.com/v1/chat/completions \
  -H "Authorization: Bearer $APISROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"claude-haiku-4-5-20251001",
       "messages":[{"role":"user","content":"ping"}]}'

FAQ

How do I add an OpenAI-API-compatible provider to Dify?

Settings, Model Provider, then install the OpenAI-API-compatible plugin from the Marketplace if it is not listed. Click Add Model on its card and register each id with Model Name, API Key, and API Base URL https://api.apisrouter.com/v1.

What do Model context size and Upper bound for max tokens control?

Context size tells Dify the model's total window, used to budget prompts and history; the upper bound caps requested output tokens. Both default to 4096, which is too low for current models, so set them from the model's documented limits when you register it.

Can Dify run Claude or DeepSeek through this provider?

Yes. The provider sends the Model Name string to your base URL over standard chat completions, so any id the gateway serves works: claude-sonnet-4-6, deepseek-v4-pro, gemini-3.5-flash, and GPT ids side by side, one key for all of them.

Should the API Base URL include /v1?

Yes: https://api.apisrouter.com/v1. Dify appends the route path to what you enter, so a missing /v1 produces connection or 404 errors on first use, and pasting the full /chat/completions path doubles the route.

Does one configuration cover all my Dify apps?

Models are registered per workspace, so every app, workflow, and agent in the workspace can select them once added. Multiple workspaces or environments repeat the setup, which also lets each carry its own key for separate usage reporting.

Why is the OpenAI-API-compatible provider missing from my Dify?

Since Dify 1.0, model providers ship as plugins, and self-hosted instances start with none installed. Open the Marketplace, install OpenAI-API-compatible by langgenius, and the card appears under Model Provider settings with the Add Model action.