Dify Quick Integration Guide for OpenAI Hub
This tutorial teaches you how to integrate OpenAI Hub’s multi-model API into Dify in the shortest possible time, enabling Dify to directly call models like GPT, Claude, Gemini, DeepSeek, and more. You only need one Key and one API endpoint to get it running.
Step 1: Prepare an OpenAI Hub Account and Key
First, go to openai-hub.com and register an account.
Then go to the console page, find API Key Management, and generate a new Key (for example, name it dify-integration).
Take note of the generated sk-your-api-key — this is your authentication credential. Don’t leak it, or someone else could use your quota for free.
Step 2: Confirm the Base URL
The OpenAI Hub API endpoint is standardized as:
https://api.openai-hub.com/v1
This endpoint is 100% compatible with the official OpenAI API format.
So you can use it the same way as https://api.openai.com/v1, just without needing a VPN. Dify will connect to it directly.
Step 3: Add a Model Provider in Dify
Log in to the Dify admin dashboard and navigate to:
Settings → Model Providers → Install Plugin → Find OpenAI-API-compatible
If the system prompts you to update to the latest version, just click “Install Latest Version.”
After installation, click “Add Model” on the right.
Enter the following configuration information:
| Field | Example | Description |
|---|---|---|
| API Key | sk-your-api-key | The Key copied from the OpenAI Hub console |
| Base URL | https://api.openai-hub.com/v1 | API endpoint |
| Model Name | gpt-4-turbo | The model you want to use, e.g., GPT, Claude, Gemini, etc. |
Don’t forget the Base URL — otherwise, Dify will default to connecting to the official openai.com, which may time out.
After saving, Dify will automatically test the connection. If you get a 401 or network error, it usually means the Key is incorrect or /v1 is missing.
Step 4: Test the Connection
Open an existing app or create a new test workflow.
In Dify’s test input box, enter something like:
“Summarize today’s key tasks for me.”
If you receive a normal response, it means OpenAI Hub has been successfully configured.
You can also view the corresponding model request in Dify’s call logs, for example:
POST https://api.openai-hub.com/v1/chat/completions
Authorization: Bearer sk-your-api-key
Content-Type: application/json
This confirms that Dify is running through the Hub — in other words, you’ve successfully connected to all major model pipelines.
Step 5: Set Up OAuth (Optional)
If you want Dify’s custom tools to call third-party APIs that require authorization (such as GitHub or Google services), you can configure OAuth 2.0 authorization.
Basically, users click an authorization button, the Hub backend exchanges a token, and then uses that token for API calls.
Example:
{
"auth_type": "oauth2",
"client_id": "your_client_id",
"authorization_url": "https://github.com/login/oauth/authorize",
"token_url": "https://github.com/login/oauth/access_token",
"scopes": ["repo", "user"]
}
These fields should be filled in within Dify’s custom tool configuration. Don’t forget to set the correct callback URL to match your tool’s redirect URI.
Once completed, your Dify tool can securely call protected resources without hardcoding usernames or passwords.
Common Issues and Troubleshooting
| Error Message | Cause | Solution |
|---|---|---|
| 401 Unauthorized | Key is incorrect or missing Bearer | Check the authentication header format: Authorization: Bearer sk-your-api-key |
| Network Timeout | Access to openai.com blocked by firewall | Verify the Base URL has been changed to the Hub endpoint |
| JSON Parse Error | Malformed request body | Check if your wrapping is misaligned — especially the messages structure |
Next Steps to Try
You can add an HTTP Request node in your Dify workflow to directly call other OpenAI Hub endpoints — for example, text embeddings or speech-to-text (audio → text) — without changing any configuration.
This approach is especially useful for building enterprise knowledge assistants or automated review tools. Try it and see how smoothly it works.
