Skip to main content
Weaver provides first-class support for OpenAI models through multiple authentication methods, including native Codex integration with OAuth, API keys, and CLI authentication.

Authentication Methods

Weaver supports three authentication methods for OpenAI:

1. API Key Authentication

Standard OpenAI API key authentication.

Get API Key

  1. Visit OpenAI Platform
  2. Create a new API key
  3. Copy the key (starts with sk-)

Configure Weaver

Option A: Configuration File Add to ~/.weaver/config.json:
{
  "providers": {
    "openai": {
      "api_key": "sk-...",
      "api_base": "https://api.openai.com/v1"
    }
  },
  "agents": {
    "defaults": {
      "provider": "openai",
      "model": "gpt-4"
    }
  }
}
Option B: Environment Variable Add to .env:
OPENAI_API_KEY=sk-...

2. OAuth Authentication (Codex)

Use ChatGPT account credentials via OAuth for Codex backend access.
weaver auth login --provider openai
Configure in ~/.weaver/config.json:
{
  "providers": {
    "openai": {
      "auth_method": "oauth"
    }
  },
  "agents": {
    "defaults": {
      "provider": "openai",
      "model": "gpt-5.2"
    }
  }
}
OAuth authentication provides access to the Codex backend, which supports advanced models like gpt-5.2 and experimental features.

3. CLI Token Authentication

Use existing codex-cli credentials.
{
  "providers": {
    "openai": {
      "auth_method": "codex-cli"
    }
  }
}
Weaver will automatically use tokens from codex-cli configuration.

Available Models

OpenAI API Models

ModelDescriptionContext Window
gpt-4Most capable GPT-4 model8K tokens
gpt-4-turboFaster GPT-4 with JSON mode128K tokens
gpt-4oOptimized multimodal model128K tokens
gpt-3.5-turboFast and cost-effective16K tokens

Codex Backend Models (OAuth)

ModelDescriptionContext Window
gpt-5.2Latest Codex model (default)128K tokens
o3Experimental reasoning model128K tokens
o4Advanced experimental model128K tokens

Configuration Options

api_key
string
OpenAI API key (required for API key auth)
api_base
string
default:"https://api.openai.com/v1"
OpenAI API endpoint (for API key auth)
auth_method
string
Authentication method: api_key, oauth, token, or codex-cli
proxy
string
HTTP/HTTPS proxy URL for API requests (optional)

Model Parameters

Configure model behavior:
{
  "agents": {
    "defaults": {
      "model": "gpt-4",
      "max_tokens": 8192,
      "temperature": 0.7
    }
  }
}
max_tokens
integer
default:"8192"
Maximum tokens in response (max_output_tokens for Codex backend)
temperature
float
default:"0.7"
Controls randomness (0.0 = deterministic, 2.0 = very random)

Codex Backend Details

The Codex backend provides access to advanced OpenAI models through the ChatGPT interface.

Model Resolution

Weaver automatically maps models to Codex-compatible versions:
  • Models starting with gpt-, o3, or o4 are used as-is
  • Other model families (Claude, Gemini, etc.) fallback to gpt-5.2
  • OpenAI-specific models are stripped of openai/ prefix
Source: pkg/providers/codex_provider.go:143-183

Account ID

Codex backend requires a ChatGPT account ID:
  • Automatically retrieved during OAuth login
  • Stored in credentials after authentication
  • Sent as Chatgpt-Account-Id header

Response Format

Codex uses streaming response format:
// Event types:
// - response.completed: Full response received
// - response.failed: Request failed
// - response.incomplete: Partial response (hit token limit)
Source: pkg/providers/codex_provider.go:83-136

Usage Examples

Basic Usage

# Use GPT-4
weaver chat --model gpt-4

# Use GPT-4 Turbo
weaver chat --model gpt-4-turbo

# Use Codex backend (requires OAuth)
weaver chat --model gpt-5.2

With Tool Calling

{
  "agents": {
    "defaults": {
      "model": "gpt-4",
      "max_tool_iterations": 20
    }
  }
}

Custom Endpoint

Use Azure OpenAI or other OpenAI-compatible endpoints:
{
  "providers": {
    "openai": {
      "api_key": "...",
      "api_base": "https://your-resource.openai.azure.com/v1"
    }
  }
}

Implementation Details

Weaver’s OpenAI integration uses:
  • HTTPProvider for standard API key authentication
  • CodexProvider for OAuth and Codex backend access
  • Native OpenAI Go SDK (github.com/openai/openai-go/v3)
  • Automatic token refresh for OAuth sessions
Source: pkg/providers/codex_provider.go, pkg/providers/http_provider.go:238-270

Troubleshooting

API Key Issues

# Verify API key
echo $OPENAI_API_KEY

# Test with curl
curl https://api.openai.com/v1/models \
  -H "Authorization: Bearer $OPENAI_API_KEY"

OAuth Issues

# Re-authenticate
weaver auth logout --provider openai
weaver auth login --provider openai

# Check stored credentials
weaver auth list

Codex Backend Issues

  • Verify account ID is present (Chatgpt-Account-Id header)
  • Check model compatibility (use GPT, o3, o4 families only)
  • Re-authenticate to refresh credentials
Requested model is not compatible with Codex backend, using fallback
  • This is normal for non-OpenAI models
  • Codex will use gpt-5.2 as fallback
  • Consider using OpenRouter for other model families
  • OAuth token expired - re-run weaver auth login --provider openai
  • API key invalid or expired
  • Check rate limits and billing status

Next Steps

Provider Overview

Back to all providers

Tool Calling

Use tools with GPT models

Build docs developers (and LLMs) love