Prime Agent Model Providers and API Key Configuration Guide
Prime Agent supports seven LLM providers—OpenAI, Anthropic, OpenRouter, Azure OpenAI, Amazon Bedrock, Google VertexAI, and Cohere—with API keys configured via environment variables mapped in packages/ai/src/env-api-keys.ts.
Prime Agent is an open-source AI coding agent developed by PrimeIntellect. Its modular AI layer, powered by the @earendil-works/pi-ai package, routes requests to multiple backend providers through a unified interface defined in the PrimeIntellect-ai/prime-agent source code.
Supported Model Providers
The authoritative list of supported backends is defined by the KnownProvider union type in packages/ai/src/types.ts. As implemented in the repository, the current providers include:
- OpenAI (
openai) – GPT-4, GPT-4o, and other OpenAI models. - Anthropic (
anthropic) – Claude 3.5 Sonnet and Claude 3 Opus series. - OpenRouter (
openrouter) – Aggregated access to multiple open-weight and commercial models. - Azure OpenAI (
azure-openai) – Enterprise OpenAI deployments via Microsoft Azure. - Amazon Bedrock (
bedrock) – AWS managed foundation models. - Google VertexAI (
google) – Gemini and PaLM models via Google Cloud. - Cohere (
cohere) – Command and Embed models.
Default model selections for each provider are stored in the defaultModelPerProvider object located in packages/coding-agent/src/core/model-resolver.ts.
How API Key Resolution Works
Prime Agent discovers credentials through the getEnvApiKey(provider) function exported from packages/ai/src/env-api-keys.ts. When the agent initializes or switches providers via a command like /model openai:gpt-4o, the resolver calls getEnvApiKey with the provider identifier and returns the corresponding secret from the process environment.
The function maps each provider string to specific environment variables:
- OpenAI:
OPENAI_API_KEY - Anthropic:
ANTHROPIC_API_KEY - OpenRouter:
OPENROUTER_API_KEY - Azure OpenAI:
AZURE_OPENAI_API_KEY(requiresAZURE_OPENAI_ENDPOINTas well) - Amazon Bedrock:
BEDROCK_ACCESS_KEY_IDandBEDROCK_SECRET_ACCESS_KEY - Google VertexAI:
GOOGLE_VERTEXAI_API_KEY - Cohere:
COHERE_API_KEY
If the variable is unset, getEnvApiKey returns undefined and the agent raises a configuration error before attempting the LLM call.
Configuration Methods
Environment Variables
Export the required variable before launching the agent. For OpenAI:
export OPENAI_API_KEY="sk-..."
prime-agent
For Anthropic:
export ANTHROPIC_API_KEY="sk-ant-..."
prime-agent
Azure OpenAI requires both the key and the endpoint URL:
export AZURE_OPENAI_API_KEY="..."
export AZURE_OPENAI_ENDPOINT="https://my-resource.openai.azure.com/"
prime-agent
Dotenv Files
Prime Agent automatically loads a .env file from the repository root. Create a file named .env with key-value pairs:
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
OPENROUTER_API_KEY=...
Only variables for providers you intend to use need to be present. The getEnvApiKey function reads these values at runtime via process.env.
Provider-Specific Options
Additional configuration for regional endpoints or project IDs can be supplied via supplementary environment variables as documented in packages/ai/src/env-api-keys.ts. For example, Bedrock deployments may require AWS_REGION alongside the Bedrock-specific access keys.
Programmatic Usage
When using the @earendil-works/pi-ai package directly in TypeScript, the library automatically resolves the API key from the environment using the same getEnvApiKey logic:
import { stream } from "@earendil-works/pi-ai";
await stream({
provider: "openai",
model: "gpt-4o",
// OPENAI_API_KEY is read automatically
});
For Azure OpenAI programmatic access:
await stream({
provider: "azure-openai",
model: "gpt-4",
// Requires AZURE_OPENAI_API_KEY and AZURE_OPENAI_ENDPOINT env vars
});
Summary
- Prime Agent supports seven providers: OpenAI, Anthropic, OpenRouter, Azure OpenAI, Amazon Bedrock, Google VertexAI, and Cohere, enumerated in the
KnownProvidertype inpackages/ai/src/types.ts. - API keys are resolved via the
getEnvApiKeyfunction inpackages/ai/src/env-api-keys.ts, which maps provider identifiers to specific environment variable names. - Configure credentials by exporting environment variables before startup or placing them in a
.envfile at the repository root. - Azure OpenAI uniquely requires both an API key (
AZURE_OPENAI_API_KEY) and an endpoint URL (AZURE_OPENAI_ENDPOINT). - Default model selections are maintained in
packages/coding-agent/src/core/model-resolver.ts.
Frequently Asked Questions
How do I switch between providers while Prime Agent is running?
Prime Agent supports runtime provider switching through slash commands. Use /model <provider>:<model> (for example, /model anthropic:claude-3-5-sonnet-20241022) to change backends. The system calls getEnvApiKey for the new provider immediately, so ensure the corresponding environment variable is set before issuing the command.
Can I use multiple providers simultaneously in one session?
The current implementation requires selecting a single active provider per conversation context. However, you can define multiple API keys in your .env file and switch between them using the /model command without restarting the agent. Each switch triggers a fresh resolution via env-api-keys.ts.
What happens if an API key is missing or invalid?
If getEnvApiKey returns undefined because the environment variable is unset, or if the key fails authentication, Prime Agent throws a configuration error before attempting the LLM call. Check the provider identifier spelling in your command against the KnownProvider type and verify the variable names listed in packages/ai/src/env-api-keys.ts.
Does Prime Agent support custom OpenAI-compatible endpoints?
While the KnownProvider type in packages/ai/src/types.ts enumerates specific backends, the OpenRouter and Azure OpenAI implementations demonstrate support for alternative endpoints. For fully custom base URLs, inspect packages/ai/src/env-api-keys.ts to see if the provider configuration accepts an override URL environment variable, or use the OpenRouter provider as a proxy for custom endpoints.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →