Tool / HTTP settings
- URL: https://api.ai24x.com/v1/chat/run
- Auth header: X-API-Key: YOUR_KEY
- Body JSON: prompt, model (flash/pro), max_tokens
{
"prompt": "{{user_input}}",
"model": "flash",
"max_tokens": 500
}
UI labels differ by Dify version—map the response text into your prompt/answer node. Do not paste secrets into public apps.
Prerequisites
- A Dify workspace, cloud or self-hosted, on a version that supports custom tools or an OpenAI-compatible model provider.
- An AI24X API key. Because Dify workflow nodes run server-side, the key is never exposed to the browser, which makes it safe for internal apps.
- For self-hosted Dify, outbound HTTPS access to
api.ai24x.comfrom the Dify containers.
Two ways to wire it up
- Custom tool — point an HTTP / API tool at
https://api.ai24x.com/v1/chat/runwith theX-API-Keyheader, exactly as shown above. This gives you full control over the request body and is the approach to use when you want to choose the tier per node. - OpenAI-compatible provider — Dify can also treat AI24X as a generic OpenAI-compatible model provider by supplying the base URL
https://api.ai24x.com/v1and your key. That path lets you select the model in the app settings instead of per node. Field names differ between Dify versions, so check against your own build.
Handling the response
Run the tool once from Dify's own test panel and inspect the returned JSON before you build anything downstream. Node references use the tool node's output, and the exact field name depends on what your account returns, so always read it from a real run rather than assuming a structure.
For a chat-style app, feed the assistant text into the answer node and leave the raw payload out of the reply. Users should see the answer, not the envelope around it.
Common errors and fixes
- 401 Unauthorized — wrong or missing key, or the header name was entered as something other than
X-API-Key. - 402 / insufficient credits — top up the AI24X credit balance and re-run the node.
- 400 Bad Request on a body that looks correct — a variable was interpolated into hand-built JSON and broke the quoting. Put the placeholder where the value belongs and let Dify handle escaping; avoid writing quote characters around the placeholder yourself.
- 429 Too Many Requests — the app is being hit harder than your plan allows. Reduce concurrency or add a delay between calls.
- Timeouts on long answers — cap
max_tokensso the reply stays within the node's timeout window.
Troubleshooting order
- Replay the same request with curl from the Dify host to isolate network and key problems.
- Verify the header name and key inside the tool definition.
- Test the tool in isolation before attaching it to a workflow.
- Inspect the raw JSON output, then fix any body interpolation issues.
- Only then adjust timeouts and rates.
n8n · HTTP / Python · Help
Gateway guides: What is an AI gateway · OpenAI-compatible API · Pricing · Start free