AI Providers

View as Markdown

A provider holds one set of model credentials - OpenAI, Anthropic, and others. Hosted agents and tools reference it by id, so the key is never passed inline or returned in a response.

Create a provider

1const provider = await bctrl.aiProviders.create({
2 provider: "anthropic",
3 name: "anthropic-prod",
4 apiKey: process.env.ANTHROPIC_API_KEY!,
5 defaultModel: "claude-opus-4-8",
6 test: true,
7});

Set test: true to validate the key against the provider before saving.

List, read, update

1const { data } = await bctrl.aiProviders.list();
2const one = await bctrl.aiProviders.get(provider.id);
3
4await bctrl.aiProviders.update(provider.id, { defaultModel: "claude-sonnet-4-6" });

Test and delete

1const result = await bctrl.aiProviders.test(provider.id);
2await bctrl.aiProviders.delete(provider.id);

Use in an agent

Pass the provider id when running a hosted agent:

1await bctrl.runtimes.invocations.stagehand.agent(runtime.id, {
2 instruction: "Summarize the dashboard.",
3 aiProviderId: provider.id,
4 model: "claude-opus-4-8",
5});

Next