How to Connect Any LLM to Dify (OpenAI-Compatible)
Dify is not limited to OpenAI's own models. Through the first-party OpenAI-API-compatible plugin it can connect to any service that speaks the OpenAI standard — a local runtime like LM Studio or llama.cpp, or a gateway that fronts hundreds of models behind one key. The whole integration comes down to four fields: the model Type, Name, API Key, and URL (the base endpoint). This guide walks the exact path in the workspace model-provider settings, shows what to put in each field, explains how Dify actually consumes the model's output once it's wired up, and gives you a troubleshooting table for the errors that trip people up.
The short answer
Install the OpenAI-API-compatible plugin, open the model-provider settings, click Add Model, and enter four things: Type, Name, API Key, and URL (the base endpoint). That is the entire integration for any service that speaks the OpenAI standard — whether it's a local runtime like LM Studio or llama.cpp, a self-hosted model, or a gateway fronting hundreds of models. Dify's first-party plugin (langgenius/openai_api_compatible) exists precisely so you are not locked to OpenAI's own models.
Once the credentials validate, the model becomes selectable everywhere in Dify — apps, chatflows, agents, and workflow LLM nodes — and that selection is how its output gets consumed. The rest of this guide is the detail: where each field comes from, the exact base-URL format, and the errors to watch for.
Install the OpenAI-API-compatible plugin
Model providers live in the workspace under Integrations > Model Provider — and OpenAI-compatible support ships as a plugin you install there. In the Dify workspace, model providers are managed at Integrations > Model Provider (they can also be browsed via the Marketplace). Find and install the official OpenAI-API-compatible plugin — langgenius/openai_api_compatible — which lets Dify integrate with services such as LM Studio, llama.cpp, and any other OpenAI-standard endpoint.
One access note before you start: only the workspace owner and admins can manage model providers, and any connected API key applies workspace-wide — the model is shared across everyone in the workspace, not scoped to your user. If you don't see the provider settings, you likely need an admin to add the model or grant access.
The four fields you fill in
Adding a model through the plugin comes down to Type, Name, API Key, and URL — everything else is optional tuning. When you click Add Model on the provider card, Dify asks for the core parameters below; the optional fields cover completion/context/token limits and streaming and vision behaviour.
| Field | What it is | What to enter |
|---|---|---|
| Type | Model category | LLM, text embedding, rerank, speech-to-text (STT), or text-to-speech (TTS) |
| Name | Model identifier | The exact model id the endpoint expects (e.g. the string you'd pass as model) |
| API Key | Auth credential | Your provider or gateway key |
| URL | API endpoint (base URL) | The provider's base URL, typically ending in /v1 |
| context_size | Model context size | Required for some types (embedding / rerank); otherwise optional |
| streaming / vision | Feature toggles | Optional — enable if the model and your app need them |
The plugin supports five categories in total — LLM, reranking, text embedding, STT, and TTS — so the same OpenAI-compatible provider can serve more than just chat completions if your endpoint exposes those routes.
Setup, step by step
Six steps take you from a blank workspace to a working model. This is the synthesized end-to-end flow; the exact button labels can shift between Dify versions, so treat the labels as guidance and match them to what your UI shows.
| # | Step | Where / what |
|---|---|---|
| 1 | Open model-provider settings | Workspace → Integrations > Model Provider |
| 2 | Install the plugin | Add the OpenAI-API-compatible provider (langgenius/openai_api_compatible) from the Marketplace |
| 3 | Add a model | Click Add Model on the provider card |
| 4 | Enter the four fields | Type, Name, API Key, and URL (base endpoint, e.g. https://host/v1) |
| 5 | Set required extras | For embedding/rerank types, provide context_size; toggle streaming/vision if needed |
| 6 | Save & validate | Dify validates the credentials before activating the model |
For the URL, one detail saves the most support tickets: enter the base URL, not the full completion path. That means the host with a /v1 suffix (for example https://host/v1) rather than https://host/v1/chat/completions — Dify appends the route itself. Pointing the field at the full path is the single most common misconfiguration. (Base-URL format verified against an independent guide, July 2026; the official docs describe the field generically as the endpoint URL.)
# Example values on the Add Model form (OpenAI-API-compatible)
Type : LLM
Name : claude-opus-4.8 # the model id your endpoint expects
API Key : sk-... # your provider / gateway key
URL : https://www.datallmlab.com/v1 # base URL, NOT /chat/completions
How Dify handles the API output
You don't wire the output up separately — once a model is configured, it becomes selectable across the platform, and selecting it is how its output is consumed. A configured model shows up in apps, chatflows, agents, and workflow LLM nodes. In a workflow, you drop an LLM node, choose your OpenAI-compatible model, and the node returns the completion as its output — which you then reference in downstream nodes (a Code node, an Answer node, a conditional branch, and so on).
So the practical answer to "how do I handle the request output from the API" in Dify is: pick the model in the component, and read the LLM node's output variable downstream. Dify normalizes the OpenAI-compatible response for you — you work with the node's text output, not raw JSON. If you enabled streaming on the model, the node streams tokens; if not, it returns the full completion. For structured downstream logic you parse the output text in a Code node like any other variable.
Default Models and fallbacks
Dify has a system-level fallback layer so components that don't name a model still work. Via the Default Models control (top-right of the workspace model settings), you can assign system defaults that kick in when an app or node doesn't specify its own model:
| Default slot | Used when a component needs… |
|---|---|
| System Reasoning Model | a general LLM and none is specified |
| Embedding Model | vectorization (e.g. knowledge retrieval) |
| Rerank Model | reranking retrieved results |
| Speech-to-Text Model | transcription |
| Text-to-Speech Model | audio output |
If you're standing up a fresh workspace, set at least the System Reasoning and Embedding defaults after adding your provider — otherwise RAG and agent features that rely on them will error out for lack of a model.
Troubleshooting model-config errors
Almost every failed Dify model connection is one of five things. This table maps the symptom to the likely cause and the fix. Because Dify validates credentials before activating a model, most of these surface at the moment you click save.
| Symptom | Likely cause | Fix |
|---|---|---|
| Credential validation fails immediately | URL is the full /chat/completions path, not the base URL | Use the base URL ending in /v1 (e.g. https://host/v1) |
| 401 / auth error on validate | Invalid, expired, or wrong-scope API key | Regenerate the key; confirm it's pasted with no trailing space |
| Model not found / unknown model | Name doesn't match an id the endpoint serves | Enter the exact model id the provider expects |
| Embedding or rerank model won't save | Missing context_size (Model context size) | Provide the context size for that model type |
| Works, but output is truncated | Completion/token limits set too low, or wrong mode | Raise max-tokens; match the completion mode to the model |
| Model missing for your teammates | Added under your user, but you expected per-user scope | Keys are workspace-wide — an owner/admin manages them once |
For the deeper HTTP-level view — what a 401 vs a 429 vs a 5xx actually means when your endpoint returns one — see our LLM API error-code reference. The context_size requirement for embedding/rerank types is corroborated by the Dify GitHub repo; underlying credential config there includes fields such as api_key, endpoint_url, context_size, max_tokens_to_sample, mode, and vision_support.
One key across many models
Because the custom-provider path is just base URL + API key, a gateway that exposes an OpenAI-compatible API drops straight into Dify — no special integration required. If you find yourself adding a provider card per vendor — one for Anthropic, one for a local model, one for an open-weights host — a gateway collapses that into a single provider. You point the URL field at the gateway's base endpoint and use one key; the gateway handles which upstream model actually serves each request, plus routing and failover.
DataLLM Lab is an OpenAI-compatible endpoint at https://www.datallmlab.com/v1, so you configure it exactly like any other custom provider in Dify — this is standard OpenAI-compatible setup, not a Dify-specific plugin. Add it once and the same trick works in any tool that accepts a custom base_url, from LangChain to Cursor. Browse the full model catalogue or check pricing to see what one key reaches.
Point Dify at one OpenAI-compatible endpoint
DataLLM Lab exposes 300+ models on one key at https://www.datallmlab.com/v1. Add it once via Dify's OpenAI-API-compatible plugin — base URL plus API key — and reach every model, with routing and failover handled for you.
FAQ
Can Dify connect to any LLM, not just OpenAI?
Yes. The first-party OpenAI-API-compatible plugin (langgenius/openai_api_compatible) connects Dify to any service exposing an OpenAI-standard API — LM Studio, llama.cpp, self-hosted models, or a gateway. You supply the Type, Name, API Key, and URL. Categories include LLM, embedding, rerank, STT, and TTS.
Where do I add a model provider in Dify?
In the workspace under Integrations > Model Provider (also browsable via the Marketplace). Install the OpenAI-API-compatible plugin, then click Add Model on the provider card. Only the workspace owner and admins can manage providers, and a connected key applies workspace-wide.
What URL do I enter for an OpenAI-compatible endpoint?
The provider's base URL — typically the host with a /v1 suffix, e.g. https://host/v1 — not the full /chat/completions path. Dify appends the route. For DataLLM Lab it's https://www.datallmlab.com/v1. (Field labels vary slightly across Dify versions, verified July 2026.)
How does Dify handle the request output from the API?
Once configured, the model is selectable in apps, chatflows, agents, and workflow LLM nodes. You consume its output by selecting the model there; the LLM node returns the completion as an output variable for downstream nodes. Dify normalizes the OpenAI-compatible response so you work with text, not raw JSON.
Why does my Dify model fail credential validation?
Usually a wrong URL (the full /chat/completions path instead of the base URL), an invalid or expired API key, or a Name the endpoint doesn't recognize. Embedding/rerank models may need a context_size value. Dify validates before activating, so these fail at save time.
Can I use a gateway for one key across many models?
Yes — a gateway with an OpenAI-compatible API is configured like any custom provider: base URL plus API key. DataLLM Lab (https://www.datallmlab.com/v1) is added once via the plugin and reaches many models through one key. This is standard OpenAI-compatible configuration, not special Dify support.
DataLLM Lab