Set up an OpenAI-compatible model
How-to guide
Many services and servers implement the OpenAI chat completions API, so one provider covers them all: you only choose the service and the model. Compass asks the model for probabilities as JSON and validates them.
Prerequisites
Section titled “Prerequisites”- Compass installed in your Starlight site.
- An API key for a service that implements the API, or a local server like Ollama running a model with support for structured outputs.
Configure the provider
Section titled “Configure the provider”-
Add the plugin with the
openaiCompatible()provider to your Starlight configuration. Choose the service:astro.config.mjs import starlightCompass, { openaiCompatible } from "starlight-compass";starlightCompass({provider: openaiCompatible({ model: "gpt-4o-mini" }),});astro.config.mjs import starlightCompass, { openaiCompatible } from "starlight-compass";starlightCompass({provider: openaiCompatible({baseUrl: "https://openrouter.ai/api/v1",model: "deepseek/deepseek-chat",}),});astro.config.mjs import starlightCompass, { openaiCompatible } from "starlight-compass";starlightCompass({provider: openaiCompatible({baseUrl: "http://localhost:11434/v1",model: "llama3.1",}),}); -
Create a
.envfile in your project root with your API key, and make sure.envis listed in your.gitignorefile. Local servers like Ollama need no key, so skip this step for them..env OPENAI_API_KEY=sk-...The provider reads the
OPENAI_API_KEYvariable whatever the service is. Pass theapiKeyoption to read another variable.
Next, review your first page.