Nov 2026 · 9 min read

AI Kit – Flutter multi-provider AI framework

Having shipped numerous Flutter apps I saw a need for a Flutter framework that could abstract common AI functionality like provider configuration, chat streaming, re-trying and analytics. It also includes chat UI and intelligent components. AI Kit enables your app to switch between different AI providers (for example, OpenAI, Gemini and Claude) and is able to truthfully attribute responses to the correct model.

ai_kit

Following numerous Flutter apps which duplicated AI integration code (such as API setup, chat streaming, re-trying and analytics) I’ve created AI Kit. This is a cross-API solution which also includes intuitive chat components. It allows your application to switch between different AI models (for example, OpenAI, Gemini and Claude) whilst truthfully attributing responses to the relevant model.

In early 2026 I then moved this duplicated code out of my client projects and into a new package which I have called AI Kit – the AI integration solution which I have often longed for Flutter to provide.

Why build a toolkit and not just a UI

Despite different verticals, most of my apps have similar AI functionality:

  • Use a particular AI service SDK or HTTP client.
  • Stream responses from the service.
  • Maintain context.
  • Provide failover should the service be unavailable, or if it is rate limited.
  • Display information about how much something has cost (tokens, currency and/or quota).

I used this system in apps providing document, health, art tuition and TTS reading functionality – and also for website creation. Whilst the domains differed, the integration was consistent.

For every new app I built I continually asked:

  • Which service SDK should I use?
  • How will my app respond if the service is unavailable?
  • How can I house context, streaming and cost data so it does not become scattered through my app widgets?

AI Kit is my solution. It comprises a compact central system which comprehends AI services, streaming, context and costs. Widgets are then used to present such functionality in a natural way within Flutter apps.

Infrastructure

I wanted to present AI as infrastructure, not an app.

Constraints

  1. Multi-provider

Whilst OpenAI, Gemini and Claude are currently top tier providers, we designed our architecture to be able to support additional ones as well.

  1. Live token output

As modern models provide live outputs, the UI should also. There shouldn’t be added effort to convert this data for display.

  1. Transparent failure

Where a provider isn’t functioning, this should be made clear within the UI. No misleading ‘offline’ or stealthy switching to an alternative model.

  1. Flutter only

No cross-platform or native view controllers. Only Dart, http, shared_preferences and standard Flutter components are allowed.

Provided these constraints were met, I could plug in AI Kit, as you would plug in a router or themes subsystem – in the most unexciting but appropriate manner.

Providers, not deities

AI Kit works on the principle that providers can be swapped.

Each can:

  • Convert AIMessages to an HTTP request
  • Receive and emit AIResponses
  • Provide information about itself such as which model it uses and how many tokens have been consumed.

Included by default are provider classes for:

  • OpenAI (GPT‑4o, GPT‑4o‑mini, GPT‑4‑turbo, o1, plus custom endpoints)
  • Google Gemini (version 2.0 Flash, 1.5 Pro and 1.5 Flash)
  • Anthropic Claude (Sonnet 4, Opus 4 and 3.5 Haiku)

The configuration is located near to where the application begins.

Dart
AIKit.init(
  providers: [
    OpenAIProvider(apiKey: openAiKey),
    GeminiProvider(apiKey: geminiKey),
    ClaudeProvider(apiKey: claudeKey),
  ],
  defaultProvider: 'OpenAI',
);

Everything uses one shared AIKit. The name of the provider is a simple string. Despite its simplicity, this provides some useful benefits:

  • allowing different providers to be swapped out without UI changes
  • facilitates model A/B testing
  • and enables OpenAI to point to Azure (or other matching) endpoints by manually specifying a baseUrl along with headers.

The UI doesn’t need to care which SDK was used to make a call. It simply receives an output stream together with usage information.

Streamed chat view

The second component is a chat view (called AIChatView). Like ListView.builder and Scaffold I wanted it to be a ‘plug-in’ for pages.

Dart
Scaffold(
  appBar: AppBar(title: const Text('AI Chat')),
  body: const AIChatView(
    systemPrompt: 'You are a friendly coding assistant.',
  ),
);

By default AIChatView includes:

  • streaming of chat replies (characters or tokens)
  • chatting – typing and thinking modes
  • error and retry functionality
  • displaying of messages with their position and time stamps
  • light and dark themes together with an AIChatTheme which allows for complete theme control.

Extra functionality can also be added including:

  • chatting suggestions
  • information about how many and what type of tokens have been used together with associated costs
  • which AI provider generated a response (for example, OpenAI, Gemini and Claude)

I aimed to produce a basic but functional chat page at minimal cost. However, there should still be ample scope to completely change the chat interface if you are developing a custom solution.

Internally AIChatView simply consumes the streams provided by AI Kit. Separately, the domain (messages, providers and memory) is modelled and is not part of the widget hierarchy.

Product-led memory

Whilst each AI product will have a slightly different approach to how far back in ‘history’ it wishes to look, AI Kit includes 3 different memory options so that you can choose what is right for your product:

  1. BufferMemory
  • Retain N most recent messages
  • Ideal for non-complex use cases where message history is key.
  1. SlidingWindowMemory
  • Continue to store messages up to your set token limit (such as 4,000)
  • Excellent for models with limited context lengths, and situations where a consistent system prompt is required at the top of the interface.
  1. SlidingWindowMemory
  • Data is stored and so information remains available even if the app is closed.
  • Good for both core chat functionality and for seamless assistants.

Externally, all widgets behave identically. Users input messages and the widget assesses which messages to send to the service. This means that the ‘selection’ process remains within the boundary of the domain – and not in individual widgets or in API requests.

Plus, it is simple to evolve functionality. For example, an initially naïve widget can easily be upgraded to a token sensitive sliding window, again without needing to modify the interface.

Transparent fail-over and retry

Providers can fail in a number of ways, such as:

  • Quota
  • Network issues
  • Model retirement
  • Regional downtime

Generally this is considered to be at ‘user’ level – and is described as ‘An error has occurred.’ I wanted AI Kit to see providers as a group. This means an individual provider’s failure does not need to cause the interaction to terminate.

How it works

  • Several providers are set up in advance.
  • You then invoke a helper (such as chatWithFailover).
  • AI Kit initially attempts to use the default provider.
  • Should this fail, it will then try the next provider on your list.

There were two key principles:

  1. Infrastructure issues

Issues such as auth, bad keys and clear misconfiguration should not be silently sent to Provider B. It is the configuration that is at fault, not the model.

  1. Do not disguise a switch as a primary service

Where Provider B has been selected then the UI should inform users. Hence why Provider names and their respective usage are given top billing in the response.

As I have done with my apps, I allow for a degraded experience during a genuine disruption. However, I do not want ‘offline’ or AI to be used as a disguise for real issues that a user needs to become aware of.

AI text fields

Whilst some situations require a fully fledged chat interface – there are also cases where simply adding intelligence to a text field will suffice (for example; email heading, customer service response and even a short piece of content, where AI can be used to provide additional information, but is not the centrepiece of the application).

AI Kit provides an AITextField widget which works much like a standard TextField but has added features including:

  • Live AI suggested information (in field or in a pop-up)
  • Ability to insert/attach suggested information to text
  • Control over the number of suggestions and the level of enthusiasm with which they are retrieved.

Despite being in a single text field, the AITextField continues to utilise the same ‘brain’ at its heart as other AI Kit components. Consequently, the provision, caching and fail-over functionality is identical whether within a multi-line chat interface or a single line text field.

This is key to providing an AI Kit which acts more like an underlying infrastructure and less like a collection of disparate components.

Usage tracking as a first‑class concern

Monitoring

When developing AI driven solutions for people, common questions that come up are:

  • “How many requests are we actually making?”
  • “Which provider is burning the most tokens?”
  • “Is this feature going to blow through the free tier?”

AI Kit provides monitoring of call volume; token consumption; estimated expenditure and a high level view of which providers are being used.

Whilst not mandatory, it can be utilised for a rapid overview of usage and also to display information to users. There is no additional administration required.

As previously mentioned, again this centres around using a tool to automate away the mundane.

What I’d still like to sharpen

AI Kit is intentionally minimal and includes ‘essential’ features that should be available in all AI enhanced Flutter apps.

Potential developments include:

  • Improved mechanisms for sandbox environments

Whilst AI Kit currently assumes a network connection, I would like to develop additional sandbox functionality. This should make it clear that these are merely examples and never mimic real AI.

  • More sophisticated function invocation

Although the package allows models to invoke Dart functions, there are opportunities to enhance usability and introduce controls for the functions available for invocation.

  • Higher level patterns

Commonly seen in apps are higher level patterns such as ‘learn me about x in a week’, or ‘abstract and test me on y’. Although there is a fine balance to be drawn between toolkits and frameworks, I wish to remain within the toolkit space and yet further simplify the use of such patterns.

As previously mentioned, the following remains central to our approach:

I designed AI kit so that AI is a ‘standard library’ part of your Flutter application. Strong, but in an unexciting way.

I created AI Kit for those using Flutter to add AI functionality who are sick of continually having to re-implement Provider.

Discussion

Questions or notes. Comments live on GitHub Discussions.