How to Connect HeFu to Dify with an OpenAI-Compatible API

Add a current HeFu chat model in Dify's OpenAI-API-compatible provider, configure the base URL and capabilities, then run one controlled test.

HeFu · Published 2026-11-26 · Updated 2026-11-26

3 min read

Dify can use HeFu through its OpenAI-API-compatible model provider. A reliable setup depends on four values: the base URL, a protected API key, an exact current model ID and accurate capability settings.

The companion Dify setup guide on GitHub remains the concise configuration reference. This tutorial adds verification and troubleshooting.

Dify labels and plugin placement vary by release. Treat the menu names below as a guide and follow the labels in your installed version. A debug conversation is a real, billable model request.

1. Prepare the HeFu Configuration

Create an API key in the HeFu console and choose a currently available chat model from the live catalog. Record:

SettingValue or source
API endpoint URLhttps://api.hefu.hk/v1
API KeyA key created and protected in the HeFu console
Model NameThe exact current ID copied from the catalog
Capabilities and limitsThe current model detail and API documentation

Do not use a model's display name as an assumed API ID. Check the current billing unit and rate before sending the test message.

2. Add the Provider and Model

  1. Open the Dify workspace with permission to manage model providers.
  2. Open Settings → Model Provider. In plugin-based versions, install or enable OpenAI-API-compatible first.
  3. Choose Add model for that provider.
  4. Enter the exact model ID as Model Name.
  5. Enter the HeFu API key and https://api.hefu.hk/v1 as the endpoint URL.
  6. Select Chat as the completion mode when configuring a chat model.
  7. Set context and maximum-token limits from current model information rather than copying an old tutorial's numbers.
  8. Enable function calling or vision only when the selected model currently supports that capability and your Dify app uses it.
  9. Save the model entry.

Dify stores provider configuration separately for model entries in some versions. When rotating a key, review every affected entry rather than assuming one global field updates them all.

3. Run One Controlled Test

Open a Dify app's prompt or orchestration panel, select the new model and send a short message with no tools or plugins. A useful first test is:

Reply with one sentence explaining what an API gateway does.

Then verify four things:

  • The response arrives and is readable.
  • The selected model entry is the one you intended.
  • The HeFu console shows the corresponding call and usage.
  • The wallet record is consistent with actual platform billing and any applicable discount.

This test proves basic chat only. Test tool calling, vision, streaming and structured output as separate acceptance checks if the app needs them.

4. Troubleshoot Without Randomly Changing Settings

SymptomLikely check
Credential validation failsConfirm the endpoint ends in /v1 and the key has no extra whitespace
401 UnauthorizedVerify the active key and Dify credential field
404 Not FoundRemove a duplicated /v1 or an appended chat path
Model not foundCopy the exact current ID again, including capitalization and separators
Tool calls fail or disappearVerify current model support and the model entry's function-calling setting
A test succeeds but an app node failsInspect that node's selected model, input mapping, protocol features and timeout

Do not solve a configuration error by enabling every capability or repeatedly running the app. Isolate the failing layer and inspect actual call records.

5. Add Resilience Deliberately

Dify workflows can branch to another configured model after specific transient failures. Keep the same controls as application code: bounded attempts, an overall deadline and fail-fast behavior for invalid requests.

Fallback models are not interchangeable. Evaluate each one with the same sanitized input and record which model generated the result. See Model Fallback Without Infinite Retries for the policy, or use the general OpenAI-compatible client checklist when reviewing another client.

FAQ

Which Dify provider should I select?

Use Dify's OpenAI-API-compatible provider. Depending on the Dify version, install or enable that provider plugin first, then add a model.

What is the correct HeFu endpoint in Dify?

Use https://api.hefu.hk/v1 as the API endpoint URL. Do not append /chat/completions when Dify adds that path itself.

Why does chat work while tool calls fail?

The model entry may have function calling enabled without current model support, or the client and model may implement different protocol details. Verify the model capability and test the feature independently.

Next step

Prepare the model before opening Dify settings

Use the live catalog to verify the exact model ID, capabilities, context and current rate before saving the provider configuration.

Copy a Current Model IDRead API docs