Guides
JavaScript guide
Make an authenticated, server-side request to the LLMFLUX gateway.
Set up
Create an API key in the dashboard, complete any required Telegram verification, and ensure the account has credit. Keep the key on your server.
npm install openai
# For Messages: npm install @anthropic-ai/sdk
export LLMFLUX_API_KEY="YOUR_GATEWAY_KEY"
export LLMFLUX_MODEL="YOUR_MODEL_ID"Use a current Node.js runtime and an ES module (for example a .mjs file). Do not enable browser SDK usage with a secret API key.
Discover models
Choose a compatible enabled ID from the authenticated model list, then replace YOUR_MODEL_ID or set LLMFLUX_MODEL. Do not assume a model name from another provider is available unchanged.
curl https://api.llmflux.dev/v1/models \
-H "Authorization: Bearer $LLMFLUX_API_KEY"Send a request
import OpenAI from "openai";
const client = new OpenAI({ apiKey: process.env.LLMFLUX_API_KEY, baseURL: "https://api.llmflux.dev/v1" });
const response = await client.chat.completions.create({ model: process.env.LLMFLUX_MODEL, messages: [{ role: "user", content: "Hello from LLMFLUX" }], stream: false });
console.log(response.choices[0].message.content);A successful non-streaming chat request returns choices[].message and provider usage. See Chat completions for the full compatibility boundary.
Use Responses or Messages
The OpenAI SDK also exposes Responses. For Anthropic-format Messages use the Anthropic SDK and its root base URL.
import OpenAI from "openai";
const client = new OpenAI({ apiKey: process.env.LLMFLUX_API_KEY, baseURL: "https://api.llmflux.dev/v1" });
const response = await client.responses.create({ model: process.env.LLMFLUX_MODEL, input: "Hello from LLMFLUX", stream: false });
console.log(response.output_text);import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({ apiKey: process.env.LLMFLUX_API_KEY, baseURL: "https://api.llmflux.dev" });
const message = await client.messages.create({ model: process.env.LLMFLUX_MODEL, max_tokens: 1024, messages: [{ role: "user", content: "Hello from LLMFLUX" }] });
console.log(message.content);Stream output
import OpenAI from "openai";
const client = new OpenAI({ apiKey: process.env.LLMFLUX_API_KEY, baseURL: "https://api.llmflux.dev/v1" });
const response = await client.chat.completions.create({ model: process.env.LLMFLUX_MODEL, messages: [{ role: "user", content: "Hello from LLMFLUX" }], stream: true });
for await (const event of response) {
console.log(event);
}Handle errors during iteration as well as when starting the request. See Streaming for event schemas and usage limitations.
Inspect errors and usage
SDK errors expose HTTP status and the response body. Use gateway error codes to distinguish invalid keys, exhausted credit and retryable failures. SDKs may retry automatically: configure bounded retries and remember inference has no gateway idempotency guarantee.
curl https://api.llmflux.dev/v1/usage \
-H "Authorization: Bearer $LLMFLUX_API_KEY"Usage and remaining credits are account-wide, even when queried with one key.