Thanks to visit codestin.com
Credit goes to forgecode.dev

Skip to main content

Configuring API Providers

Configure Forge to work with your preferred AI provider. This guide covers provider setup, credential management, and provider-specific features.

Supported AI Providers

Forge supports multiple AI providers, each with unique capabilities and pricing models:

Provider Overview

  • OpenRouter: Access to 300+ models from multiple providers
  • OpenAI: Official OpenAI models (GPT-4, o3-mini, etc.)
  • Anthropic: Claude models (Claude 3.7 Sonnet, etc.)
  • Google Vertex AI: Google's enterprise AI platform with Claude and Gemini models
  • Groq: Ultra-fast inference with optimized models like DeepSeek R1
  • Amazon Bedrock: AWS managed AI service with multiple model providers
  • OpenAI-Compatible Providers: Any provider following OpenAI API format

Quick Start: Configure Providers

The recommended way to configure providers is using the interactive login command:

1

Login to a Provider

Use the forge provider login command to configure your AI provider credentials:

forge provider login

This interactive command will:

  1. Show you a list of available providers
  2. Guide you through entering the required credentials
  3. Securely store your credentials in Forge's configuration
2

Verify Configuration

Test your provider configuration by running Forge:

forge

Forge will automatically use your configured provider.

Managing Provider Credentials

Forge provides commands to manage your provider credentials:

# Login to a provider (add or update credentials)
forge provider login

# Remove provider credentials
forge provider logout

# List supported providers
forge provider list

Where to get API keys:

Switching Between Providers

Once you have multiple providers configured, you can easily switch between them using the /provider command.

Using the /provider Command

# In Forge CLI, type:
/provider

This will display an interactive menu showing all your configured providers:

? Select a provider:
> openrouter [openrouter.ai]
openai [api.openai.com]
anthropic [api.anthropic.com]
[Type a name or use arrow keys to navigate and Enter to select]

Navigation:

  • Use arrow keys to navigate up/down
  • Type to filter providers by name
  • Press Enter to select
  • Press Escape to cancel

Model Selection

After switching providers, you'll be prompted to select a compatible model from the new provider's available models.

Multiple Providers

Configure multiple providers to easily switch based on your needs:

  • OpenRouter: For model variety and cost comparison
  • OpenAI: For latest GPT models and features
  • Anthropic: For Claude's reasoning capabilities
  • Groq: For ultra-fast inference

Deprecated: Environment Variable Configuration

DEPRECATED

Using .env files for provider configuration is deprecated and will be removed in a future version. Please use forge provider login instead.

Automatic Migration

For backward compatibility, Forge still supports environment variables. On first run, if credentials are found in environment variables (.env files), Forge will:

  1. Automatically migrate your API keys to credentials
  2. Display a notification about the migration
  3. Continue working with your credentials

After migration, you should manage your providers using:

# Add or update provider credentials
forge provider login

# Remove provider credentials
forge provider logout

Legacy Environment Configuration

Legacy .env Setup (Not Recommended)

If you still need to use environment variables temporarily, Forge searches for .env files in this order:

  1. Current working directory (.env)
  2. Parent directories (recursively up to root)
  3. Home directory (~/.env)

Example legacy configuration:

# ~/.env or project/.env

# OpenRouter (recommended for model variety)
OPENROUTER_API_KEY=your_openrouter_key_here

# Official OpenAI
OPENAI_API_KEY=your_openai_key_here

# Official Anthropic
ANTHROPIC_API_KEY=your_anthropic_key_here

# Google Vertex AI
PROJECT_ID=your_project_id
LOCATION=your_location
VERTEX_AI_AUTH_TOKEN=your_auth_token

# Groq
OPENAI_API_KEY=your_groq_api_key
OPENAI_URL=https://api.groq.com/openai/v1

# Amazon Bedrock (requires Bedrock Access Gateway)
OPENAI_API_KEY=your_bedrock_gateway_api_key
OPENAI_URL=your_bedrock_gateway_base_url

Migration process:

When you run Forge for the first time after upgrading, it will:

  • Detect credentials in your .env files
  • Automatically migrate them to secure file-based storage
  • Show a notification about the migration
  • Continue working without interruption

After migration:

  • Your credentials are now managed by Forge
  • Use forge provider login to add new providers
  • Use forge provider logout to remove providers
  • Your original .env files remain unchanged (for other tools)

Provider Priority

When multiple providers are configured, Forge uses this priority order:

  1. OpenRouter - Second priority (multiple models)
  2. OpenAI - Third priority (official OpenAI)
  3. Anthropic - Lowest priority (official Anthropic)

You can override the default provider using the /provider command at any time.

Next Steps


Provider configuration complete! Use forge provider login to manage your AI provider credentials securely.