Skip to main content

Examples

Complete AI_PROVIDER_* configurations. See Overview for what each setting does and Providers for the full provider list.

Provider package or API URL

Every setup needs one of two things so UIGraph knows where to send requests:

  • A provider package (AI_PROVIDER_NPM): such as @ai-sdk/openai or @ai-sdk/anthropic. Each package already knows its provider's endpoint and sets the API URL for you internally, so you don't set AI_PROVIDER_API_URL at all.
  • An API URL (AI_PROVIDER_API_URL): used with the default @ai-sdk/openai-compatible package. That package is generic: it doesn't belong to any single provider, so it can't know the endpoint on its own. You must give it the base URL of an OpenAI-compatible API.

That's why at least one of the two is always required, and why the OpenAI-compatible provider specifically needs the URL while the dedicated packages don't.

Using a provider package

The package sets the endpoint; you only provide the key and model.

OpenAI:

AI_PROVIDER_NPM="@ai-sdk/openai"
AI_PROVIDER_API_KEY="sk-…"
AI_PROVIDER_MODEL="gpt-4o"

Anthropic:

AI_PROVIDER_NPM="@ai-sdk/anthropic"
AI_PROVIDER_API_KEY="sk-ant-…"
AI_PROVIDER_MODEL="claude-sonnet-5"

OpenRouter:

AI_PROVIDER_NPM="@openrouter/ai-sdk-provider"
AI_PROVIDER_API_KEY="sk-or-…"
AI_PROVIDER_MODEL="moonshotai/kimi-k2-thinking"

Using the OpenAI-compatible package with an API URL

Leave AI_PROVIDER_NPM at its default (@ai-sdk/openai-compatible) and point AI_PROVIDER_API_URL at any OpenAI-compatible endpoint. These are the real base URLs each provider publishes:

OpenAI:

AI_PROVIDER_API_URL="https://api.openai.com/v1"
AI_PROVIDER_API_KEY="sk-…"
AI_PROVIDER_MODEL="gpt-4o"

Groq:

AI_PROVIDER_API_URL="https://api.groq.com/openai/v1"
AI_PROVIDER_API_KEY="gsk_…"
AI_PROVIDER_MODEL="llama-3.3-70b-versatile"

Google Gemini (OpenAI-compatible endpoint):

AI_PROVIDER_API_URL="https://generativelanguage.googleapis.com/v1beta/openai/"
AI_PROVIDER_API_KEY="…"
AI_PROVIDER_MODEL="gemini-2.5-pro"

Local model (Ollama):

AI_PROVIDER_API_URL="http://localhost:11434/v1"
AI_PROVIDER_API_KEY="ollama"
AI_PROVIDER_MODEL="llama3.1"

OpenAI has a dedicated package (shown in the section above); pointing the compatible package at its real URL works too, and is included here to make the endpoint concrete. Anthropic is not OpenAI-compatible, use its dedicated @ai-sdk/anthropic package instead. In general, when a provider has its own package, prefer it; reach for AI_PROVIDER_API_URL when it doesn't, or for self-hosted and gateway endpoints.