Skip to main content
Install the OpenAI SDK:
Create a server-side file such as example.mjs. Read the API key from an environment variable. Do not expose it in browser JavaScript.
SERV-enabled Chat Completions requests require a system or developer message. The Responses API also accepts an instructions field. Check the model catalog for supported model IDs and reasoning support. The SDK returns the standard Chat Completions shape. Read the generated text from choices[0].message.content and usage data from 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.