Providers
This package talks to nine providers. Each provider is one client class per capability it serves. Gemini has a text client and an image client. Veo has a video client. This page lists who serves what, shows the constructor shape they all share, and links to a page per provider.
What each provider serves
A cell is marked when that provider offers that capability in this package. Empty means it does not.
| Provider | Text | Image | Video | Speech | Sound effect | Music |
|---|---|---|---|---|---|---|
| Gemini | yes | yes | ||||
| Veo | yes | |||||
| OpenAI | yes | |||||
| Flux | yes | |||||
| ElevenLabs | yes | yes | ||||
| Suno | yes | |||||
| Claude | yes | |||||
| Mistral | yes | |||||
| Ollama | yes |
If a provider does not serve a capability, there is no client for it. Ask the registry for one and you get an AiInvalidRequestException instead of a client. See the registry.
The constructor shape
Every provider client takes the same named parameters. Only credentials is required. The rest have defaults, so most code passes only the key.
import 'package:ai_abstracted/ai_abstracted.dart';
final client = OpenAiImageClient(
credentials: ProviderCredentials(apiKey: 'your-key'),
// Everything below is optional.
httpClient: sharedClient, // reuse one http.Client across clients
retryPolicy: const RetryPolicy(), // attempts, backoff, and jitter
endpoint: Uri.parse('https://api.openai.com/v1/images/generations'),
sleep: Future.delayed, // the delay seam, swapped in tests
);
What each optional parameter does:
httpClient: thehttp.Clientto send requests on. Pass one to share connections and to inject a mock in tests. Omit it and the client makes its own.retryPolicy: how many attempts and how long to back off on transient failures. See retries and timeouts.endpoint: overrides the default host. Use it to point at a proxy or a compatible gateway.sleep: the function that waits between retries. The default isFuture.delayed. Override it in tests so retries do not wait real seconds.
Polling clients add two parameters
Flux, Veo, and Suno run long jobs. You submit the job, then the client polls until it is ready, then downloads the result. Those three clients take two more parameters on top of the shape above.
final flux = FluxImageClient(
credentials: ProviderCredentials(apiKey: 'your-bfl-key'),
pollInterval: const Duration(seconds: 2), // wait between status checks
pollTimeout: const Duration(minutes: 3), // give up after this
);
When pollTimeout passes before the job finishes, the client throws AiTimeoutException. Polling clients also report progress through onProgress. See progress.
Choosing a provider at runtime
Construct a client directly when you know the provider at compile time. When the provider is a value you decide at runtime (from config, an env var, or user input), go through ProviderRegistry. You give it a ProviderId and credentials, and it hands back the capability client or throws when that provider does not serve it.
const registry = ProviderRegistry();
final ImageGenerator generator = registry.imageGenerator(
ProviderId.openai,
ProviderCredentials(apiKey: 'your-key'),
);
The registry has one method per capability: textGenerator, imageGenerator, videoGenerator, speechGenerator, soundEffectGenerator, and musicGenerator. Full detail is on the registry.
How to read a provider page
Each provider page follows the same layout, so you can scan straight to what you need:
- Key: which env var holds the API key and where to get one. Keyless providers (Ollama) say so.
- Simple example: the shortest complete request that returns bytes.
- Advanced options: the request fields that matter for that provider, such as size for images or voice for speech.
- Tips: the specifics that trip people up, like exact model names or how a value is formatted.
- Errors: what that provider raises and when, mapped to this package's exception types.
Provider pages
- Gemini: text and image (the "Nano Banana" image model).
- Veo: video, with audio on Veo 3. Uses your Gemini key.
- OpenAI: image via
gpt-image-1. - Flux: image via Black Forest Labs, polled.
- ElevenLabs: speech and sound effects.
- Suno: music, through the sunoapi.org gateway.
- Claude: text, with vision when you attach an image.
- Mistral: text over an OpenAI-style chat endpoint.
- Ollama: local text, keyless, or a remote instance you point at.