How to Connect HeFu to n8n with an OpenAI-Compatible API
Configure HeFu in n8n with an OpenAI credential or HTTP Request node, map a current model ID and verify chat output, errors and actual usage.
HeFu · Published 2026-11-26 · Updated 2026-11-263 min read
n8n can call HeFu in two ways: an OpenAI credential with a custom base URL for AI Agent workflows, or an HTTP Request node for explicit HTTP control. Both use the same HeFu API key and current model catalog.
The concise companion reference is the n8n setup guide on GitHub.
Node names and credential layouts vary between n8n versions. Executing either path makes a real, billable API request. Disable automatic retries while diagnosing the first call.
Option A: Use an OpenAI Credential
Choose this path when an AI Agent or chain expects an OpenAI Chat Model.
- Open Credentials → Add credential and select OpenAI.
- Enter the HeFu API key.
- Set Base URL to
https://api.hefu.hk/v1. If the field is collapsed, check the credential's advanced options. - Save the credential.
- Add an OpenAI Chat Model sub-node to the compatible agent or chain and select that credential.
- Enter an exact current chat model ID from the HeFu live catalog. If the dropdown does not load HeFu's catalog, use the version's manual or expression entry rather than choosing an unrelated OpenAI ID.
- Run one short test with tools and automatic retries disabled.
The credential expects a base URL. Do not append /chat/completions when the node constructs that path.
Option B: Use an HTTP Request Node
Choose this path when you need to control the complete payload, headers or a non-chat endpoint.
- Add an HTTP Request node.
- Set Method to
POST. - Set URL to
https://api.hefu.hk/v1/chat/completions. - Configure Header Auth with header name
Authorizationand valueBearer <your-key>, using an n8n credential rather than embedding the real key in the workflow. - Select a JSON body and map the current model ID and prompt:
{
"model": "deepseek-v4-flash",
"messages": [
{"role": "user", "content": "={{ $json.prompt }}"}
]
}
The model ID above is an example checked against the catalog on 2026-11-21. Replace it when the live catalog changes. On self-hosted n8n, a protected HEFU_API_KEY environment variable can be referenced through the expression support available in your deployment.
Inspect the returned content at choices[0].message.content. Save a sanitized request fixture and the expected response structure for later regression tests, but do not save credentials or confidential prompts.
Verify the Result and Actual Usage
A successful workflow run should establish all of the following:
- The intended model ID appears in the request.
- The response contains the expected chat content.
- The node handles empty, error and timeout results without an unlimited loop.
- The HeFu console shows the corresponding request and usage.
- Wallet details reconcile with actual charges and any applicable discount.
Basic chat success does not verify tool calls, streaming or every AI Agent feature. Test each capability used by the workflow separately.
Troubleshooting
| Symptom | What to check |
|---|---|
401 Unauthorized | Active key, Bearer prefix and correct credential selection |
404 Not Found | Base URL versus full chat URL; avoid duplicated /v1 segments |
| Model not found | Exact current model ID, including separators and capitalization |
| Empty agent response | Chat Model credential, manual model entry and input mapping |
| Repeated charges after a failure | Automatic node retries, workflow loops and error branches |
Disable retry-on-fail temporarily when diagnosing a request. Once the request is correct, restore only bounded retry behavior for transient failures.
For a multi-model recovery path, branch only on retryable errors and preserve an overall workflow deadline. Read Model Fallback Without Infinite Retries before chaining models. For another client, the same three-value setup is summarized in the OpenAI-compatible client checklist.
FAQ
Which n8n node should call HeFu?
Use an OpenAI Chat Model sub-node with a custom OpenAI credential when an AI Agent or chain expects a chat model. Use the HTTP Request node when you need direct control over the JSON payload, headers or non-chat endpoint.
What Base URL should the OpenAI credential use?
Use https://api.hefu.hk/v1. For an HTTP Request node calling Chat Completions directly, the full URL is https://api.hefu.hk/v1/chat/completions.
Where should the API key be stored?
Use n8n credentials or a protected environment variable. Never inline a real key in shared workflow JSON, screenshots or version control.