How do I read response headers like X-Request-Id in JavaScript?
withResponse() gives you the parsed data and the HTTP response with its headers.
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.gateway.clatterlabs.xyz/v1",
apiKey: process.env.CLATTER_API_KEY,
defaultHeaders: { "X-Clatter-Account": process.env.CLATTER_ACCOUNT_ID },
});
const { data, response } = await client.chat.completions
.create({ model: "supercosmos-flash", messages: [{ role: "user", content: "Hi" }] })
.withResponse();
console.log(response.headers.get("x-request-id"));
console.log(response.headers.get("x-ratelimit-remaining"), "/", response.headers.get("x-ratelimit-limit"));
const notice = response.headers.get("x-clatter-notice"); // "abuse_warning" when a warning was issued
if (notice) console.warn(decodeURIComponent(response.headers.get("x-clatter-notice-text") ?? ""));
These headers are exposed for CORS, so browser code can read them too.
Every JavaScript example uses the same client (base URL, key and the X-Clatter-Account header); see Set up the JavaScript SDK. Full parameter list: Create a chat completion.
Good to know#
- Every call shows in Console › Logs and Usage as Model API, with its price. See what you spent
- Keep keys on your server, never in a browser or mobile app. Why
- New accounts get $5 of free credit; top up from $1 to $800 per purchase in Console › Billing › Credits. Billing
Still need help?#
- General support: support@clatterlabs.com or team@clatterlabs.xyz
- Infrastructure questions, or permanent deletion of your data (your whole account or one service): infrastructure@clatterlabs.xyz
We usually reply within the first hour, and always within 24 hours. A full support team is with you.
Related articles
- How do I set up the OpenAI JavaScript SDK for the Model API?
- How do I detect and act on abuse warnings in JavaScript?
- Can I call the Model API with plain fetch instead of the SDK?
- How do I read rate limit headers in Python?
- What do the X-Codebuckets-Tokens and X-Request-Id headers mean?Code Buckets
- Can I see Benchmark 2's raw data?SuperCosmos models
Still need help?
Tried the steps above and still stuck? Email us. We usually reply within the first hour, and always within 24 hours. A full support team is with you.
Infrastructure questions, or permanent deletion of your data
infrastructure@clatterlabs.xyzFor deleting your whole account or the data of one service.