Integrations

Node.js → AI24X

Use native fetch (Node 18+) in scripts, bots, and backends.

Minimal example

const key = process.env.AI24X_API_KEY; const r = await fetch("https://api.ai24x.com/v1/chat/run", { method: "POST", headers: { "X-API-Key": key, "Content-Type": "application/json", }, body: JSON.stringify({ prompt: "Hello", model: "flash", max_tokens: 200, }), }); const data = await r.json(); console.log(r.status, data);

Keep the key in env vars. Prefer flash for cost; pro for harder tasks; VIP ids only after VIP is active.

Prerequisites

  • Node.js 18 or newer, which ships a global fetch. On older runtimes add node-fetch or axios instead.
  • An AI24X API key stored in process.env.AI24X_API_KEY. Never hard-code it into a repository file.
  • Top-level await, as used below, requires an ES module (.mjs, or "type": "module" in package.json). Inside CommonJS, wrap the same code in an async function.

Full example with error handling

fetch resolves even when the request fails, so check res.ok before you parse anything:

const res = await fetch("https://api.ai24x.com/v1/chat/run", { method: "POST", headers: { "X-API-Key": process.env.AI24X_API_KEY, "Content-Type": "application/json", }, body: JSON.stringify({ prompt: "Hello", model: "flash", max_tokens: 200 }), }); if (!res.ok) { const detail = await res.text(); throw new Error(`AI24X ${res.status}: ${detail}`); } const data = await res.json(); console.log(data);

Choosing a tier

Each request names a model. Use flash for high-volume, forgiving workloads such as tagging, extraction and summarising user input. Step up to pro when a call really needs deeper reasoning or a longer context window. Named VIP models are addressed with a vip- prefix, for example vip-kimi, and only resolve once VIP access is active on the account.

Because the request shape is identical across tiers, you can make the tier an environment variable and change your cost profile without touching the calling code.

Common errors and fixes

  • 401 Unauthorized — the key is absent or wrong. Confirm process.env.AI24X_API_KEY is actually populated in this process; a missing .env load is the usual cause.
  • 402 / insufficient credits — top up the AI24X credit balance and resend the same request.
  • 400 Bad Request — the body was not valid JSON. Always pass the payload through JSON.stringify rather than building a string by hand.
  • 429 Too Many Requests — you are sending faster than your plan allows. Queue the calls or add a small delay between them.
  • fetch is not defined — you are on a runtime older than Node 18. Upgrade, or install a fetch polyfill.

Calling the API from a Node process means there is no browser in the path, so CORS settings are irrelevant here. If you see CORS errors, the request is coming from client-side code and the key would be exposed anyway — move the call behind your own server.

Troubleshooting order

  1. Reproduce the call with curl to separate a key problem from a code problem.
  2. Log res.status and res.text() before you attempt res.json().
  3. Confirm the key is loaded into the process that makes the call.
  4. Confirm the payload survives JSON.stringify unchanged.
  5. Only then look at timeouts, DNS and any egress proxy in your network.

curl · HTTP / Python · Sign up