Skip to content

davidmigloz/ai_clients_dart

Repository files navigation

AI Clients Dart

tests Discord MIT

Type-safe Dart clients for OpenAI, Anthropic, Google Gemini, Mistral, Ollama, and more — all sharing a consistent API shape. Built for Flutter apps, backends, CLIs, and server-side Dart across every platform.

Table of Contents

Quickstart

The AI provider clients share a consistent shape — pick one and start with a few lines:

OpenAI
dependencies:
  openai_dart: ^3.0.0
import 'package:openai_dart/openai_dart.dart';

Future<void> main() async {
  final client = OpenAIClient.fromEnvironment();

  try {
    final response = await client.responses.create(
      CreateResponseRequest(
        model: 'gpt-5.4',
        input: ResponseInput.text('What is the capital of France?'),
      ),
    );

    print(response.outputText);
  } finally {
    client.close();
  }
}
Anthropic
dependencies:
  anthropic_sdk_dart: ^1.4.0
import 'package:anthropic_sdk_dart/anthropic_sdk_dart.dart';

Future<void> main() async {
  final client = AnthropicClient.fromEnvironment();

  try {
    final response = await client.messages.create(
      MessageCreateRequest(
        model: 'claude-sonnet-4-6',
        maxTokens: 1024,
        messages: [InputMessage.user('What is the capital of France?')],
      ),
    );

    print(response.text);
  } finally {
    client.close();
  }
}
Google Gemini
dependencies:
  googleai_dart: ^4.0.0
import 'package:googleai_dart/googleai_dart.dart';

Future<void> main() async {
  final client = GoogleAIClient.fromEnvironment();

  try {
    final response = await client.models.generateContent(
      model: 'gemini-2.5-flash',
      request: GenerateContentRequest(
        contents: [Content.text('Explain why Dart works well for APIs.')],
      ),
    );

    print(response.text);
  } finally {
    client.close();
  }
}
Ollama
dependencies:
  ollama_dart: ^2.0.0
import 'package:ollama_dart/ollama_dart.dart';

Future<void> main() async {
  final client = OllamaClient();

  try {
    final response = await client.chat.create(
      request: ChatRequest(
        model: 'gpt-oss',
        messages: [ChatMessage.user('Explain what Dart isolates do.')],
      ),
    );

    print(response.message?.content);
  } finally {
    client.close();
  }
}

Packages

Package Description Version Downloads
openai_dart OpenAI — Responses, Chat Completions, images, audio, realtime openai_dart openai_dart monthly downloads
anthropic_sdk_dart Anthropic — Claude messages, streaming, tools, extended thinking anthropic_sdk_dart anthropic_sdk_dart monthly downloads
googleai_dart Google AI / Vertex AI — Gemini generation, embeddings, Live API googleai_dart googleai_dart monthly downloads
mistralai_dart Mistral AI — chat, embeddings, OCR, TTS, reasoning, agents mistralai_dart mistralai_dart monthly downloads
ollama_dart Ollama — local chat, streaming, embeddings, tool calling ollama_dart ollama_dart monthly downloads
open_responses OpenResponses — one typed interface, multiple providers open_responses open_responses monthly downloads
chromadb ChromaDB — vector search, collections, multi-tenant RAG chromadb chromadb monthly downloads
openai_realtime_dart OpenAI Realtime — lower-level WebSocket sessions openai_realtime_dart openai_realtime_dart monthly downloads
tavily_dart Tavily — web search and research for agents and RAG tavily_dart tavily_dart monthly downloads

Why choose these clients?

  • Pure Dart — works everywhere: Flutter apps, backends, CLIs, and server-side Dart across iOS, Android, macOS, Windows, Linux, and Web.
  • Type-safe — sealed classes, typed request/response models, and ergonomic helpers.
  • Consistent shape — AI provider clients share fromEnvironment() for config, similar resource methods, and close() for cleanup.
  • Minimal dependencies — just http, logging, meta, and where needed web_socket.
  • Strict semver — follows semver.org so downstream packages can depend on stable, predictable version ranges.

Used By

These open-source packages and apps use one or more clients from this repo. For more, see the GitHub dependents graph.

Packages

Package Downloads
langchain_dart langchain monthly downloads
dartantic dartantic monthly downloads
genkit-dart genkit monthly downloads

Apps

App Stars
Anx Reader Anx Reader stars
ApiDash ApiDash stars
Lotti Lotti stars

For Coding Agents

Use llms.txt for package hubs, llms-ctx.txt for the non-optional concatenated context bundle, and llms-ctx-full.txt for the full bundle including optional sources.

Sponsor

If these packages are useful to you or your company, please consider sponsoring the project. Development and maintenance are provided to the community for free, but integration tests against real APIs and the tooling required to build and verify releases still have real costs. Your support, at any level, helps keep these packages maintained and free for the Dart & Flutter community.

License

AI Clients Dart is licensed under the MIT License.

About

A collection of Dart client libraries for popular AI APIs. Provides type-safe, well-documented, and idiomatic interfaces to OpenAI, Anthropic (Claude), Google AI (Gemini), Mistral, Ollama, and other providers. Ready for Dart and Flutter.

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

 

Contributors