Clatter LabsHelp Center

Does the Model API work with TypeScript?

How-toUpdated

Yes. Use the same client; the SDK's request and response types match the Chat Completions format. Fields the OpenAI types don't know, such as reasoning_content, can be read with a cast.

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 },
});

type WithReasoning = { reasoning_content?: string };

const r = await client.chat.completions.create({
  model: "supercosmos-max",
  messages: [{ role: "user", content: "Is 221 prime?" }],
});
const msg = r.choices[0].message as typeof r.choices[0]["message"] & WithReasoning;
console.log(msg.reasoning_content, msg.content);

For the family id with an effort, add effort to the body; TypeScript may need // @ts-expect-error or a cast because it isn't in OpenAI's types.

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 response has an X-Request-Id; log it so a request can be found later. Why log it
  • New accounts get $5 of free credit; top up from $1 to $800 per purchase in Console › Billing › Credits. Billing
  • 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.