> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://respan.ai/docs/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://respan.ai/docs/_mcp/server.

# Dify (gateway)

> Route Dify LLM calls through the Respan gateway with Dify's official OpenAI-compatible model provider.

Dify can use Respan as the OpenAI-compatible model endpoint for chat-model calls inside Dify applications and workflows. This is separate from tracing calls made to Dify's Service API with `respan-instrumentation-dify` or `@respan/instrumentation-dify`.

> **Note**
>
> This setup routes Dify's **internal LLM calls** through Respan Gateway. It does not turn Respan into a Dify Service API endpoint, and it does not route Dify Knowledge Base, Workspace, conversation, file, or app-invocation APIs through Respan.

## Setup

#### Enable Dify's OpenAI-compatible model provider

In Dify, install or enable the official [OpenAI-API-compatible model provider](https://marketplace.dify.ai/plugin/langgenius/openai_api_compatible). Open **Settings → Model Provider**, select that provider, and add a customizable LLM model.

#### Configure the Respan endpoint

Use these values for the custom model:

| Dify field                  | Value                                                                   |
| --------------------------- | ----------------------------------------------------------------------- |
| Model Name                  | A model available to the Respan project, for example `gpt-5.5`          |
| API Key                     | Your Respan API key                                                     |
| API Base URL                | `https://api.respan.ai/api`                                             |
| Model name for API endpoint | The same Respan model ID, unless an explicit endpoint alias is required |
| Completion mode             | `Chat`                                                                  |
| API Type                    | `Chat Completions API (/chat/completions)`                              |
| Compatibility mode          | `OpenAI compatible` / strict                                            |

Set context size, maximum output tokens, vision, and tool-calling options to the real capabilities of the selected model. The documented setup path is to add the model manually and cross-check its exact ID and capabilities in the [Respan model catalog](https://platform.respan.ai/platform/models); model discovery was not validated in this documentation pass.

> **Warning**
>
> Dify validates the provider by making a model request. The Respan project therefore needs credits or a configured provider credential, and validation can create a Gateway log.

#### Use the model in Dify

Select the configured model in a Dify chatbot, Agent, Chatflow, or Workflow LLM node, then run the application. Keep the provider in Chat mode because this setup uses Respan's OpenAI-compatible Chat Completions route.

#### Inspect the Gateway log

Open the [Logs page](https://platform.respan.ai/platform/requests) and inspect the model, prompt, completion, usage, latency, cost, and status recorded for the Dify-originated request.

## Add Dify Service API tracing

Gateway logging records the model request handled by Respan. To also trace an external Python or JavaScript application's calls to Dify's Service API, configure the [Dify tracing integration](/docs/integrations/dify). The two paths observe different network legs and provide complementary evidence; this setup does not claim that Dify propagates the external client's trace context into its model-provider request.

## Limitations

* This page documents the LLM Chat Completions path only. Do not infer support for Dify embedding, rerank, speech, or other model-provider types from this setup.
* Use an exact model ID available to the Respan project; this setup does not claim that Dify's model discovery has been validated against Respan.
* Respan Gateway does not expose Dify's Service API. Keep Dify client `baseUrl` / `base_url` values pointed at Dify.
* Dify plugin field labels may vary slightly by plugin version. The required transport values remain the Respan API key, `https://api.respan.ai/api`, API Type `Chat Completions API (/chat/completions)`, and an available model ID in Chat mode.

See the [Respan Gateway API guide](/docs/integrations/gateway/respan-api) for the route contract and current model guidance.