Provider Capabilities
Dartantic includes a capabilities system that allows you to check what features each provider supports. Different providers have different capabilities - for example, OpenRouter doesn't support embedding generation while OpenAI and Gemini do.
Checking Provider Capabilities
You can check what capabilities a provider supports using the caps
property:
import 'package:dartantic_ai/dartantic_ai.dart';
void main() async {
final openaiAgent = Agent('openai');
final openrouterAgent = Agent('openrouter');
// Check capabilities
print('OpenAI capabilities: ${openaiAgent.caps}');
// Output: (textGeneration, embeddings, chat, fileUploads, tools)
print('OpenRouter capabilities: ${openrouterAgent.caps}');
// Output: (textGeneration, chat, fileUploads, tools)
// Check specific capabilities
final openaiSupportsEmbeddings = openaiAgent.caps.contains(ProviderCaps.embeddings);
final openrouterSupportsEmbeddings = openrouterAgent.caps.contains(ProviderCaps.embeddings);
print('OpenAI supports embeddings: $openaiSupportsEmbeddings'); // Output: true
print('OpenRouter supports embeddings: $openrouterSupportsEmbeddings'); // Output: false
}
Capability Types
The ProviderCaps
enum defines the following capability types:
textGeneration
- Provider supports text generation and completionembeddings
- Provider supports vector embedding generationchat
- Provider supports conversational/chat interactionsfileUploads
- Provider supports file and media uploadstools
- Provider supports tool/function calling
Graceful Capability Handling
Check capabilities before attempting operations to handle unsupported features gracefully:
import 'package:dartantic_ai/dartantic_ai.dart';
void main() async {
final agent = Agent('openrouter'); // OpenRouter doesn't support embeddings
if (agent.caps.contains(ProviderCaps.embeddings)) {
// Safe to use embeddings
final embedding = await agent.createEmbedding('test text');
print('Embedding generated: ${embedding.length} dimensions');
} else {
print('Provider ${agent.model} does not support embeddings');
// Use alternative approach or different provider
}
}