Provider Setup
Baleybots is provider-agnostic. It works with OpenAI, Anthropic, Ollama, and any provider supported by the AI SDK.
Provider resolution
Baleybots auto-detects your provider from:
- Explicit model string:
model: 'openai|gpt-4o'ormodel: 'anthropic|claude-sonnet-4-20250514' - Environment variables: If
OPENAI_API_KEYis set, defaults to OpenAI. IfANTHROPIC_API_KEYis set, defaults to Anthropic.
OpenAI
npm install @ai-sdk/openai
export OPENAI_API_KEY="sk-..."
import { Baleybot } from '@baleybots/core';
// Auto-detected from env
const bot = Baleybot.create({
name: 'bot',
goal: 'Help users',
});
// Explicit model
const bot2 = Baleybot.create({
name: 'bot',
goal: 'Help users',
model: 'openai|gpt-4o-mini',
});
Anthropic
npm install @ai-sdk/anthropic
export ANTHROPIC_API_KEY="sk-ant-..."
const bot = Baleybot.create({
name: 'bot',
goal: 'Help users',
model: 'anthropic|claude-sonnet-4-20250514',
});
Ollama (local)
npm install ollama-ai-provider-v2
# Make sure Ollama is running locally
const bot = Baleybot.create({
name: 'bot',
goal: 'Help users',
model: 'ollama|llama3.2',
});
Advanced configuration
For full control over the provider, use the object form:
const bot = new Baleybot({
name: 'bot',
goal: 'Help users',
model: {
id: 'gpt-4o',
provider: {
apiKey: 'sk-...',
baseUrl: 'https://custom-endpoint.example.com/v1',
fetch: customFetchWrapper, // e.g., for Tauri, React Native
},
},
});
Custom fetch
Override the fetch function for special environments:
// Tauri
import { fetch as tauriFetch } from '@tauri-apps/plugin-http';
const bot = new Baleybot({
name: 'bot',
goal: 'Help users',
model: { id: 'gpt-4o', provider: { fetch: tauriFetch } },
});
// Testing
const mockFetch = vi.fn().mockResolvedValue(
new Response(JSON.stringify({ choices: [{ message: { content: '...' } }] }))
);
const bot = new Baleybot({
name: 'bot',
goal: 'Help users',
model: { id: 'gpt-4o', provider: { fetch: mockFetch } },
});
Environment variable priority
When no explicit model is provided:
OPENAI_API_KEY— uses OpenAIANTHROPIC_API_KEY— uses Anthropic- Ollama — checked if running locally
Set both keys and use the model string to pick which one to use per-agent.