Clatter LabsHelp Center

Can I call the Model API with plain fetch instead of the SDK?

FAQUpdated

Yes. Any HTTP client works. This is the whole request with fetch (Node 18+, Deno, Bun).

const res = await fetch("https://api.gateway.clatterlabs.xyz/v1/chat/completions", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.CLATTER_API_KEY}`,
    "X-Clatter-Account": process.env.CLATTER_ACCOUNT_ID,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "supercosmos-flash",
    messages: [{ role: "user", content: "Hello!" }],
  }),
});
const data = await res.json();
if (!res.ok) throw new Error(`${res.status} ${data.error?.code}: ${data.error?.message}`);
console.log(data.choices[0].message.content, res.headers.get("x-request-id"));

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#

  • Retry only 429 and 5xx errors, with backoff; honour Retry-After when it's sent. Which errors to retry
  • 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

Still need help?#

We usually reply within the first hour, and always within 24 hours. A full support team is with you.

Related articles

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.xyz
For deleting your whole account or the data of one service.