Skip to main content
A request traveling from application code through an API gateway to a language model
Create a server-side file such as example.mjs. Keep the API key in an environment variable; do not expose it in browser JavaScript.
Every request must include a system prompt, developer message, or instructions field. Browse the model catalog for supported model IDs. The response uses the standard Chat Completions shape. The generated text is in choices[0].message.content, and usage data is in response.usage. If the request fails, check the API key, organization balance, model ID, and system prompt first. For endpoint-specific fields, see the Chat Completions reference.