Code Integration
Use the OpenModels chat completions endpoint from server-side code. Keep your API key in an environment variable and send the prompt through the OpenAI-compatible messages array.
Endpoint:
Environment variable:
Do not hardcode API keys in source code or client-side browser bundles.
Request shape
Node.js
This example uses the built-in fetch API available in Node.js 18 and later.
Python
This example uses Python standard library modules only.
Go
This example uses Go’s standard net/http package.
Notes
- Keep
OM_API_KEYon the server. Do not expose it in frontend code. - Use
messagesfor chat prompts. The optional OpenAIuserfield is for end-user tracking, not the prompt body. - The examples include optional
routeandroute_modefields. Remove them to use the default available route. - For production error handling, parse
error.codeand follow the Errors guide.