Skip to main content

Install

For Flutter apps using Firebase AI Logic (Gemini through Firebase), also add dartantic_firebase_ai and register firebase-google / firebase-vertex on Agent.providerFactories (see Providers).

API Keys

Set environment variables for the providers you’ll use:
Prefer to handle API keys server-side. Take special care to not expose them in your client code. See Providers for the complete list.

Your First Chat

The following shows simple agent usage using the Agent() constructor, which takes a model string.
Alternatively, you can use the Agent.forProvider() constructor which takes a provider directly:

Model Strings

The model string used by Agent can be specified in several ways:
  • Just the providerName, e.g. openai → specifies whatever the default chat and embeddings models are for that provider
  • providerName:chatModelName, e.g. google:gemini-2.0-flash → specifies a provider and model, separated by a colon
  • providerName/chatModelName, e.g. google/gemini-2.0-flash → specifies a provider and model, separated by a slash
  • providerName?chat=chatModelName&embeddings=embeddingsModelNameopenai?chat=gpt-4&embeddings=text-embedding-ada-002 → uses query format

Providers

A provider is a Dart type like GoogleProvider that knows how to expose model objects. When you pass in a model string, you’re really looking up a provider object and one or more types of model objects for the agent to do its work. All the providers support a chat model (e.g. GoogleChatModel) and several of them also support an embeddings model (e.g. GoogleEmbeddingsModel). You can see the list of Supported Providers that Dartantic exposes. And you can build your own Custom Providers if you like.

Provider Aliases

Some providers support multiple provider prefixes. The alias can be used where the provider name is specified, e.g. gemini:gemini-2.0-flashgoogle:gemini-2.0-flash. Here’s where you can see the list of aliases for each of the Supported Providers.

What’s Next?

Now that you’ve tasted power, dive deeper: