Request and inspect

POST /v1/chat/completions uses ai:write. Provide model and a messages array containing role and content. Get model from /v1/models. A regular response contains choices and usage. Let the caller inspect finish_reason before treating text as a completed answer.

Budget and recover

Use a finite output limit appropriate for the workload. Check Model pricing and workspace limits. If the model is unavailable, re-list authorized models and choose a suitable route rather than retrying indefinitely.