Skip to content

Using AI Providers

VibeDepot supports three AI providers out of the box: Anthropic (Claude), OpenAI (GPT), and Google Gemini. Your app calls AI through the Bridge API, and VibeDepot handles authentication using the user’s API keys.

Your app must declare the ai permission and list supported providers in manifest.json:

{
"permissions": ["ai", "storage.kv"],
"models": {
"required": true,
"providers": ["anthropic", "openai", "gemini"],
"default": "anthropic"
}
}

The simplest way to get an AI response:

const response = await window.vibeDepot.ai.callAI({
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Explain quantum computing in one sentence.' }
]
});
console.log(response.content); // The AI's response text
console.log(response.model); // e.g. "claude-sonnet-4-20250514"
console.log(response.usage); // { inputTokens: 42, outputTokens: 18 }
ParameterTypeRequiredDescription
messagesAIMessage[]YesArray of { role, content } objects
providerstringNoForce a specific provider ('anthropic', 'openai', 'gemini')
modelstringNoForce a specific model (e.g. 'gpt-4o')
maxTokensnumberNoMaximum tokens in the response
temperaturenumberNoSampling temperature (0–2)
  • system — Sets the AI’s behavior. Placed first in the messages array.
  • user — The user’s input.
  • assistant — Previous AI responses (for multi-turn conversations).

For real-time responses, use streaming:

const output = document.getElementById('output');
output.textContent = '';
await window.vibeDepot.ai.streamAI(
{
messages: [
{ role: 'user', content: 'Write a short poem about rain.' }
]
},
(chunk) => {
output.textContent += chunk;
}
);

The onChunk callback fires for each text fragment as it arrives. The promise resolves when the stream is complete.

VibeDepot resolves which provider to use in this priority order:

  1. Explicit requestprovider parameter in the call
  2. Manifest defaultmodels.default in your manifest
  3. Manifest providers — First provider in models.providers that has a configured API key
  4. Any configured — Any provider the user has set up

This means your app works as long as the user has any supported API key configured.

// What provider is currently selected?
const provider = await window.vibeDepot.ai.getProvider();
// => 'anthropic'
// What model is being used?
const model = await window.vibeDepot.ai.getModel();
// => 'claude-sonnet-4-20250514'
// What providers are available for this app?
const providers = await window.vibeDepot.ai.listProviders();
// => ['anthropic', 'openai']

Each provider has a default model:

ProviderDefault Model
Anthropicclaude-sonnet-4-20250514
OpenAIgpt-4o
Geminigemini-2.0-flash

You can override the model per-call:

const response = await window.vibeDepot.ai.callAI({
provider: 'openai',
model: 'gpt-4o-mini',
messages: [{ role: 'user', content: 'Hello!' }]
});

AI calls can fail for several reasons. Always wrap them in try/catch:

try {
const response = await window.vibeDepot.ai.callAI({
messages: [{ role: 'user', content: 'Hello!' }]
});
} catch (err) {
switch (err.code) {
case 'MISSING_API_KEY':
// User hasn't configured any supported API key
showMessage('Please add an API key in VibeDepot Settings.');
break;
case 'AI_PROVIDER_ERROR':
// API returned an error (invalid key, rate limit, etc.)
showMessage('AI error: ' + err.message);
break;
case 'PERMISSION_DENIED':
// App doesn't have 'ai' permission
showMessage('This app needs AI permission.');
break;
default:
showMessage('Something went wrong: ' + err.message);
}
}

See the Error Codes Reference for all error types.

Build conversations by accumulating messages:

const conversation = [
{ role: 'system', content: 'You are a coding tutor.' }
];
async function sendMessage(userInput) {
conversation.push({ role: 'user', content: userInput });
const response = await window.vibeDepot.ai.callAI({
messages: conversation
});
conversation.push({ role: 'assistant', content: response.content });
return response.content;
}