Clatter LabsHelp Center

How do I call the Model API from Windows PowerShell?

How-toUpdated

PowerShell's curl is an alias in older versions, so Invoke-RestMethod is the reliable choice.

$headers = @{
  "Authorization"     = "Bearer $env:CLATTER_API_KEY"
  "X-Clatter-Account" = $env:CLATTER_ACCOUNT_ID
}
$body = @{
  model    = "supercosmos-flash"
  messages = @(@{ role = "user"; content = "Hello from PowerShell" })
} | ConvertTo-Json -Depth 5

$r = Invoke-RestMethod -Method Post `
  -Uri "https://api.gateway.clatterlabs.xyz/v1/chat/completions" `
  -Headers $headers -ContentType "application/json" -Body $body
$r.choices[0].message.content

Set the variables first with $env:CLATTER_API_KEY = "clsk_..." and $env:CLATTER_ACCOUNT_ID = "CL-...". Use -Depth 5 or deeper so nested messages aren't flattened.

Set CLATTER_API_KEY (a clsk_ key with models:invoke) and CLATTER_ACCOUNT_ID (your CL- Account ID from Console › Settings) first. Reference: Model API reference.

Good to know#

  • If calls fail unexpectedly, check status.clatterlabs.com before debugging further.
  • Every response has an X-Request-Id; log it so a request can be found later. Why log it
  • Every call shows in Console › Logs and Usage as Model API, with its price. See what you spent

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.