Dify OpenAI-API-compatible model setup
Dify's OpenAI-API-compatible provider takes a model name, a key and an endpoint URL per model. Add each RelaySwitch id you use once, and every LLM node, agent and chatflow in the workspace can pick it.
Dify connects to any OpenAI-format API through its OpenAI-API-compatible model provider, a plugin from the Dify Marketplace. Unlike a gateway connection that fetches a list, this provider holds one entry per model: you type the id, the key and the URL, and Dify treats it as a model of that provider. Point the entries at https://api.relayswitch.io/v1 and the models on the Models page run inside Dify, billed per token to a prepaid balance.
This guide adds the first model field by field, lists five worth adding with their live prices, prices a day of runs, and gives the curl that proves the key before you blame the workflow.
01What you need
- A Dify workspace, cloud or self-hosted, with the OpenAI-API-compatible provider installed from Integrations > Model Provider.
- A RelaySwitch key. Sign in with an email code at the console and create one. Keys start with
sk-relay-. - A balance. Top-ups start at $10, by card or crypto, with no subscription. Before the first top-up the console chat runs 12 free turns a day for comparing models.
02Add the first model
- Open Integrations > Model Provider. If the OpenAI-API-compatible card is not there, install it under Install model providers.
- Click Add Model on the card. Dify's docs describe this as giving the model “a name and its credentials”.
- Fill the form:
Model Type: LLMModel Name: claude-sonnet-5-5API Key: sk-relay-...API endpoint URL: https://api.relayswitch.io/v1Completion mode: ChatModel context size: 1000000Upper bound for max tokens: 128000Streaming: Supported- Model Name: the id exactly as the Models page prints it. Dify sends it as the
modelfield. - API endpoint URL:
https://api.relayswitch.io/v1, with the/v1. The plugin README's rule: use the/v1URL for LLM and chat models, and the bare origin for embedding, rerank, speech and transcription models, because for those types the plugin appends the API version itself. The RelaySwitch gateway also answers a doubled/v1/v1path (checked 2026-10-31), so a wrong choice still works; the README's rule avoids it. - Completion mode: Chat.
- Model context size and Upper bound for max tokens: the figures from the model's page. Dify uses them to cut history and cap output; set them lower than the model's if you want a tighter cap.
- Streaming: supported. The API streams server-sent events when a request sets
streamto true, which Dify does for chat.
Save, then repeat Add Model for each id below. One key covers all of them; Dify stores it per model entry. Under Default Models at the top right, pick one of them as the system reasoning model so new apps start on it.
03Which models to add
Prices per million tokens, context windows and the output cap, read from the live catalog when this page was built. The last column is one run of 2,000 tokens in and 500 out.
| Model | Input | Output | Context | Max output | One run |
|---|---|---|---|---|---|
| Claude Sonnet 5.5 | $1.20 | $3.00 | 1M tokens | 128,000 | $0.0039 |
| GPT-5.5 | $1.80 | $9.00 | 1.1M tokens | 128,000 | $0.0081 |
| Gemini 3.5 Flash | $1.50 | $9.00 | 1M tokens | 65,536 | $0.0075 |
| DeepSeek V4 Pro 0423 | $0.792 | $2.376 | 1M tokens | 393,216 | $0.0028 |
| GLM 5.3 | $0.3276 | $1.0296 | 1M tokens | 131,072 | $0.0012 |
USD, read from the RelaySwitch catalog at build time. Context and max output are the developer's stated figures; type them into the Dify form.
The Claude ids answer the OpenAI format here, so they go in through the same provider as the rest; no second provider is needed.
04What a day of runs costs
A chatflow with one LLM node on Claude Sonnet 5.5, run 500 times a day at 2,000 tokens in and 500 out each: $0.0039 a run, $1.95 a day. The same day on GLM 5.3 is $0.585.
A workflow with several LLM nodes bills each node as its own request, and a knowledge-retrieval step puts the retrieved chunks into the input of the node that reads them. Each request shows on the console's Usage page with its tokens and charge, so the split per node is readable there. See how pricing works for cached input and the rest of the billing rules.
05Check it
From the machine that runs Dify, list the models the key can call:
curl https://api.relayswitch.io/v1/models -H "Authorization: Bearer sk-relay-..."Then send one streamed request the way an LLM node does. -i prints the headers, including the request id.
curl -i https://api.relayswitch.io/v1/chat/completions \ -H "Authorization: Bearer sk-relay-..." \ -H "Content-Type: application/json" \ -d '{"model": "claude-sonnet-5-5", "messages": [{"role": "user", "content": "Say ok."}], "stream": true}'If both work and the Dify node does not, the problem is in the model entry. The API docs list every endpoint and error.
06Errors and fixes
- Saving the model fails: Dify validates the entry with a request. A
401means the key; a404means the Model Name is not a catalog id (a display name, or a typo). 402in a run: the balance is too low. Top up in the console and the next run goes through.429: the key hit its rate limit. Every app in the workspace shares the key you entered; give a busy app its own key with its own limits from the console.- Output is cut short: Upper bound for max tokens is set below what the answer needs. Raise it up to the model's cap in the table.
- A
/v1/v1in an error message: the endpoint URL was entered with/v1on a model type that appends it. The gateway still answers; for a clean path use the origin for those types, as the README says.
07Sources
The menu path and the Add Model step are from Dify's Model Providers doc; the fields, the /v1 rule and the version (0.0.73 on the marketplace page) are from the OpenAI-API-compatible plugin README. Both read 2026-10-31. Prices are from the live catalog at build time.
Questions
- How do I add a custom OpenAI-compatible model to Dify?
- Integrations > Model Provider, install OpenAI-API-compatible, click Add Model on its card, and fill Model Name (the catalog id), API Key, API endpoint URL (https://api.relayswitch.io/v1), Completion mode Chat, the context size and the max-tokens bound. Save and repeat per model.
- Does the Dify endpoint URL include /v1?
- For LLM and chat models, yes: https://api.relayswitch.io/v1. For embedding, rerank, speech and transcription entries the plugin README says to use the origin without /v1 because the plugin appends the API version itself. The RelaySwitch gateway answers both shapes.
- Can Dify fetch the model list from the key?
- Not through this provider: each model is one entry you type. Keep the list to the ids you use; the Models page has every id and price.
- Does streaming work in Dify on this key?
- Yes. Leave streaming on in the model entry; the API streams server-sent events when the request sets stream to true, and Dify chat apps do.
- What does a Dify run cost on this key?
- The tokens of each LLM node at the live prices in the table ($0.0039 for a chat-sized run on Claude Sonnet 5.5 today), from a prepaid balance that starts at $10. Dify itself adds nothing on a self-hosted install.