Skip to content
pubscout

dart_openai

8.0.0, released 3 months ago by gwhyyy.com

Unofficial Dart and Flutter SDK for the OpenAI API and compatible providers.

WASM-ready
$ flutter pub add dart_openai
Source repository

What it does

Provides typed clients for OpenAI and compatible APIs like DeepSeek, Ollama, and LM Studio. It supports chat completions, streaming, vector stores, fine-tuning, images, audio, and more across all platforms including web.

AI-written summary of version 8.0.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to integrate OpenAI or compatible LLM APIs into your Dart or Flutter app.
  • You require multi-platform support including Flutter Web.
  • You need robust streaming, automatic retries, and rate-limit tracking.

Skip it when

  • You are building exclusively with official first-party SDKs that have guaranteed OpenAI synchronization.
  • You require only on-device models without any remote API connectivity.

Strengths

  • Comprehensive API coverage including Responses, Chat, Realtime, Batch, and Vector Stores.
  • Per-client configuration allows multiple accounts or local models to run side-by-side.
  • Platform-neutral file handling supports web and native disk access.

Weaknesses

  • It is an unofficial SDK, meaning it might lag behind official OpenAI API updates.
  • Relies on community maintenance.

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
5

Add dependency to pubspec.yaml and configure your OpenAI API key or compatible endpoint URL.

import 'package:dart_openai/dart_openai.dart';

Future<void> main() async {
  final client = OpenAIClient(apiKey: 'sk-...');
  final completion = await client.chat.create(
    model: 'gpt-4o',
    messages: [
      const OpenAIChatCompletionChoiceMessageModel(
        role: OpenAIChatMessageRole.user,
        content: 'Say hello in five words.',
      ),
    ],
  );
  print(completion.choices.first.message.content);
}

Alternatives

Packages that do the same job and could replace dart_openai.

  • ollama_dart

    Pick it if you are specifically targeting Ollama local models and want an Ollama-focused client.

  • openai_dart

    Alternative Dart client for the OpenAI API.

  • llamadart

    Pick it if you want to run Llama models directly on-device rather than calling a remote API.

Works with

Packages commonly used together with dart_openai: ones it builds on, ones built on it, and its own family.