Skip to main content

Custom Models

Baleybots has no provider-registration API. Since the AI SDK v7 migration, all model construction lives in the AI SDK. The custom-model story is: pass an AI SDK LanguageModel instance as model:.

Any object that satisfies the AI SDK language-model contract (specificationVersion, modelId, doStream) is detected and forwarded straight to the AI SDK — no name parsing, no config merge, no registerProvider. This covers first-party @ai-sdk/* providers, community providers, and OpenAI-compatible endpoints.

For built-in resolution from environment variables, see Provider setup.

Arbitrary endpoint (createOpenAICompatible)

For a self-hosted or third-party server that speaks the OpenAI wire protocol, use @ai-sdk/openai-compatible:

import { Baleybot } from '@baleybots/core';
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';

const myEndpoint = createOpenAICompatible({
name: 'my-endpoint',
baseURL: 'https://llm.internal.example.com/v1',
apiKey: process.env.MY_ENDPOINT_KEY,
});

const bot = Baleybot.create({
name: 'responder',
goal: 'Answer the question',
model: myEndpoint('some-model'),
});

Community AI SDK provider

Install any community provider package and pass the model instance:

import { Baleybot } from '@baleybots/core';
import { createMistral } from '@ai-sdk/mistral';

const mistral = createMistral({ apiKey: process.env.MISTRAL_API_KEY });

const bot = Baleybot.create({
name: 'summarizer',
goal: 'Summarize the input concisely',
model: mistral('mistral-large-latest'),
});

stopWhen, tools, and structured output all work over a passthrough model exactly as they do over a built-in string like 'openai/gpt-4o-mini'.

Many models, one gateway

For access to many models through a single gateway without wiring a provider per model, use the built-in openrouter() factory from core:

import { Baleybot, openrouter } from '@baleybots/core';

const bot = Baleybot.create({
name: 'router-bot',
goal: 'Answer the question',
model: openrouter('anthropic/claude-3.5-sonnet'),
});

Set OPENROUTER_API_KEY in your environment, or pass credentials through the factory options.

What not to do

// Removed in alpha.171 — do not use
import { registerProvider } from '@baleybots/core';
registerProvider('my-llm', { /* ... */ });
const bot = Baleybot.create({ model: 'my-llm/some-model' });

See Alpha 171 migration for the full before/after.