Integration Guides

Dify OpenAI-API-Compatible Plugin: Setup, Fields and Fixes (2026)

ROIBest AI

What the OpenAI-API-compatible plugin does in Dify

Dify ships first-party providers for the big model vendors. Everything else, such as a self-hosted vLLM or Ollama server, LM Studio, an API gateway, or a vendor whose API copies OpenAI's format, gets connected through one plugin: OpenAI-API-compatible, published by langgenius in the Dify Marketplace.

The plugin turns any endpoint that speaks the OpenAI request format into a Dify model provider. It supports five model types: LLM, text embedding, rerank, speech-to-text and text-to-speech. You add models one at a time, each with its own URL, key and capability switches.

This guide follows the plugin's source and README in the dify-official-plugins repository (version 0.0.87, checked November 24, 2026) and Dify's Docker environment defaults. Field labels can shift between versions; if your screen differs, the logic below still applies. For background on what "compatible" covers, see what an OpenAI-compatible API is.

Install the plugin

  1. In Dify, open Plugins and go to the Marketplace tab.
  2. Search for OpenAI-API-compatible and install the one by langgenius.
  3. Open Settings → Model Provider. The plugin now appears in the provider list.
  4. Click Add Model on it. Each model you add is a separate entry.

Self-hosted Dify needs the plugin daemon running (it is part of the standard Docker Compose setup). On Dify Cloud the plugin installs the same way.

The fields that matter for an LLM

When you add a model with Model Type = LLM, these are the fields that decide whether it works:

Field

What to enter

Notes

Model Name

The model ID the endpoint expects, e.g. deepseek-flash or qwen3-32b

Sent as model unless you fill the next field.

model name for API endpoint

Optional override

Use when you want a friendly name in Dify but a different ID on the wire.

Model display name

Optional label in the Dify UI

Cosmetic.

API Key

The endpoint's key

Optional; local servers often need none.

API Base URL

Base URL including the version path, e.g. https://api.example.com/v1

Required. See the URL rules below.

Completion mode

Chat (default) or Completion

Chat calls /chat/completions; Completion calls the legacy /completions.

Model context size

The model's real context window

Default 4096. Too low truncates prompts; too high causes 400s on long inputs.

Upper bound for max tokens

Highest max_tokens Dify may send

Default 4096.

API Type

Chat Completions API (default) or Responses API

Pick Responses only if the endpoint implements /responses.

Token parameter name

auto, max_tokens or max_completion_tokens

Some newer models reject max_tokens; switch here if you see that error.

Function Call Type

Not Support (default), Function Call, Tool Call

Set Tool Call for Agent apps and tool nodes to use native tool calling.

Stream function calling

Not Support (default) or one of two streaming modes

Leave off unless the server streams tool calls correctly.

Thinking Mode Support

Only Non-Thinking Mode (default), Both Modes, Only Thinking Mode

Tells Dify whether the model returns reasoning and whether it can be switched off.

Vision / Video / Audio / Document Support

Off by default

Enable only what the model really accepts, or uploads will fail at request time.

Structured Output

Not Support (default) / Support

Enables JSON-schema output in Dify when the endpoint honours response_format.

Include Usage in Stream

Enabled (default)

Asks the server for token usage in streaming responses. Disable if the server errors on stream_options.

Enable request metadata

Disabled (default)

When enabled, adds x-dify-app-id and x-dify-user-id headers, useful for per-app cost tracking at a gateway.

When you save, the plugin validates the model by sending a tiny chat request ("ping", max_tokens 5, thinking disabled) to the endpoint. If that request fails, Dify shows the endpoint's error and does not save.

API Base URL rules (the part most setups get wrong)

The plugin builds request paths from the base URL differently per model type:

Model type / setting

What the plugin appends

What to enter

LLM, Chat mode

chat/completions

https://host/v1

LLM, Completion mode

completions

https://host/v1

LLM, API Type = responses

Adds /v1 unless the URL already ends in /v1, /v3 and so on

https://host/v1 (safe either way)

Text embedding

/embeddings

https://host/v1

Rerank

/rerank, unless you fill Rerank Endpoint URL

https://host/v1, or the full rerank URL in the separate field

Speech-to-text, TTS

Some code paths add the version internally

Start with https://host; if errors show /v1/v1, remove /v1

The plugin's README gives the same warning: for some non-LLM types the version is appended internally, so a base URL that already ends in /v1 can produce a duplicated /v1/v1 path.

Concrete values for common backends:

Backend

API Base URL in Dify

DeepSeek

https://api.deepseek.com/v1 (details in our DeepSeek API base URL guide)

vLLM

http://<server>:8000/v1

Ollama

http://<server>:11434/v1

LM Studio

http://<server>:1234/v1

An OpenAI-compatible gateway or relay

The gateway's documented base URL, usually ending in /v1

Docker networking: why localhost fails

Self-hosted Dify runs in Docker, and model requests leave from a container. Inside a container, localhost is the container itself, not your machine. A model server on the host is unreachable at http://localhost:11434/v1 even though it works in your browser.

  • Docker Desktop (macOS, Windows): use http://host.docker.internal:11434/v1.
  • Linux: use the host's LAN IP, or map host.docker.internal to host-gateway with extra_hosts in the Compose file. Make sure the model server listens on 0.0.0.0, not only 127.0.0.1.
  • Another container: put both on the same Docker network and use the service name.

Timeouts and long generations

Long reasoning or long outputs can hit timeouts at several layers:

Layer

Setting

Default

Plugin validation request

connect / read timeout

10 s / 300 s

Plugin daemon

PLUGIN_MAX_EXECUTION_TIMEOUT

600 s

Dify API to plugin daemon

PLUGIN_DAEMON_TIMEOUT

600 s

Dify API workers

GUNICORN_TIMEOUT

360 s

If generations die at a consistent duration, compare it with these numbers. Raise the relevant values in your Docker env files and restart. Streaming the response (on by default in chat apps) also avoids idle-read timeouts at proxies in front of Dify.

Troubleshooting checklist

Symptom

Likely cause

Fix

404 on save

Missing or doubled /v1

Match the URL rules table above

Connection refused / timeout on save

localhost inside Docker, or server bound to 127.0.0.1

Use host.docker.internal or the host IP; bind to 0.0.0.0

401 on save

Wrong key, or the key belongs to another service

Re-copy the key; test the same key with curl

400 "model not found"

Model Name differs from the endpoint's model ID

Call GET /v1/models on the endpoint and copy the exact ID

Agent ignores tools

Function Call Type left at Not Support

Set Tool Call (only if the model supports tools)

Error mentioning max_tokens

Model expects max_completion_tokens

Change Token parameter name

Reasoning text shows up in answers

Thinking mode not configured

Set Thinking Mode Support to match the model

The general version of the URL problem is covered in OpenAI-compatible base URL: what to set, and the wider list of protocol gaps in OpenAI compatibility issues.

Test the endpoint before you blame Dify

Run the same request the plugin will send, from the Dify host or container:

curl https://api.example.com/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "your-model-id", "messages": [{"role": "user", "content": "ping"}], "max_tokens": 5}'

If this fails, the problem is the endpoint, key or network, not Dify. If it works from your laptop but not from the Dify container, it is Docker networking.

FAQ

How do I add an OpenAI-compatible model in Dify?

Install the OpenAI-API-compatible plugin from the Dify Marketplace, then go to Settings → Model Provider, click Add Model on that provider, choose the model type, and fill in Model Name, API Key and API Base URL.

Should the Dify API Base URL include /v1?

For LLM and embedding models, yes: enter https://host/v1, because the plugin appends chat/completions or /embeddings to it. For speech and some other types, the version may be added internally, so remove /v1 if you see /v1/v1 in an error.

Why can Dify not connect to my local Ollama or vLLM server?

Dify runs in Docker, where localhost points to the container. Use host.docker.internal (Docker Desktop) or the host's IP, and make sure the server listens on 0.0.0.0.

How do I enable tool calling for an OpenAI-compatible model in Dify?

Set Function Call Type to Tool Call when you add the model. Leave Stream function calling at Not Support unless you have confirmed the server streams tool calls correctly.

Can I use one gateway key for many models in Dify?

Yes. Add each model as a separate entry with the same API Base URL and key. Enabling request metadata adds Dify app and user IDs as headers, so the gateway can attribute spend per app.

The short version

Install OpenAI-API-compatible, add one entry per model, and get three things right: the exact model ID, a base URL ending in /v1 for chat and embeddings, and a host that the Dify container can actually reach. Then match the capability switches (tool calls, vision, thinking, structured output) to what the model really supports.