Skip to content

Dify Configuration

What is Dify

Dify is an open-source AI application development platform that supports building AI workflows, chatbots, and Agent applications through a visual interface.

Configure ai.TokenHub

Dify supports OpenAI-compatible protocol and can directly configure ai.TokenHub as a model provider.

Configuration Steps

1. Go to Model Provider Settings

  1. Log in to Dify dashboard
  2. Click avatar → Settings
  3. Select Model Providers from left menu

2. Add OpenAI-API-compatible

  1. Find OpenAI-API-compatible in the provider list
  2. Click Add Model

3. Fill in Configuration

ParameterValue
Model Namegpt-4o (or your desired model ID)
API KeyYour ai.TokenHub API Key
API Base URLhttps://ai-tokenhub.com/v1

4. Set Model Parameters

ParameterRecommended Value
Context Window128000
Max Tokens16384
Streaming✅ Enabled
Function Calling✅ Supported (if needed)
Vision✅ Supported (if using multimodal models)

5. Save and Test

After saving, click the Test button next to the model name to send a test message.

Multi-Model Configuration

Add Claude Models

Repeat the above steps, fill in Model Name:

ModelModel Name
Claude 3.5 Sonnetclaude-3-5-sonnet-20241022
Claude 3 Opusclaude-3-opus-20240229

Complete Configuration Example

ModelModel NameAPI Base URL
GPT-4ogpt-4ohttps://ai-tokenhub.com/v1
GPT-4o-minigpt-4o-minihttps://ai-tokenhub.com/v1
Claude 3.5 Sonnetclaude-3-5-sonnet-20241022https://ai-tokenhub.com/v1
Gemini 3 Progemini-3-prohttps://ai-tokenhub.com/v1

Python Verification Script

Before configuring in Dify, you can verify API connectivity with Python:

python
from openai import OpenAI

client = OpenAI(
    api_key="your_api_key",
    base_url="https://ai-tokenhub.com/v1"
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "user", "content": "Hello, test connectivity"}
    ],
    stream=True
)

for chunk in response:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

FAQ

Extra slash at the end of Base URL

❌ Wrong: https://ai-tokenhub.com/v1/ ✅ Correct: https://ai-tokenhub.com/v1

Model Name is Case Sensitive

Ensure the model name matches exactly with the model ID on the ai.TokenHub platform.

Request Failed 404

Check if the Base URL is correct, no extra / at the end.

Docker Deployment Dify

bash
git clone https://github.com/langgenius/dify.git
cd dify