c.AI.Chat(ctx, request) calls the AI Gateway, an OpenAI-compatible chat completions endpoint. It needs the ai:chat scope and a Standard plan or above.
The shorter snippets below run inside the program from Running the examples: paste one at a time into main and run goimports.
Request
squarecloud.ChatRequest fields, with their JSON names:
The response is a
ChatCompletion with the OpenAI shape: ID, Object, Created, Model, Choices (Index, Message, FinishReason) and Usage (PromptTokens, CompletionTokens, TotalTokens).
No streaming
AI.Chat does not stream: it returns the whole completion. ChatRequest has no stream field; the API answers 400 stream_not_supported to stream: true.
Timeout
The gateway gives each request 90 seconds in total, then answers 503server_overloaded. Without a ctx deadline, the SDK waits at least 2 minutes before timing out, so you get the gateway’s answer.
Errors
AI errors use the OpenAI format, so their codes are lowercase. They are still returned as an*APIError, with Code set to the OpenAI code (or its type when there is no code):
The SDK never retries AI errors: the request is a non-idempotent
POST. See the AI Gateway reference for plan limits.
Next steps
Errors
Error class, retries and rate limits.
AI Gateway reference
Models, plan limits and the OpenAI-compatible endpoint.

