openai
The unofficial OpenAI SDK for Dart & Flutter. Full API coverage + OpenAI-compatible providers (Azure, DeepSeek, LM Studio, Ollama): Responses, Chat, Realtime, V
What is openai?
The unofficial OpenAI SDK for Dart & Flutter. Full API coverage + OpenAI-compatible providers (Azure, DeepSeek, LM Studio, Ollama): Responses, Chat, Realtime, Videos, Batch, Fine-tuning.
Overview of openai
What it is
dart_openai is an unofficial Dart/Flutter SDK for the OpenAI API. It provides typed clients for every major API surface, including Responses, Chat Completions, Realtime, Videos, Batch, Fine-tuning, Vector Stores, Evals, Administration, and more. The SDK compiles and runs on Android, iOS, macOS, Linux, Windows, web, and server-side Dart. It is maintained by Anas Fikhi (@anasfik).
Key features
- Full API coverage: Responses, Chat, Audio, Images, Embeddings, Files, Batch, Vector Stores, Fine-tuning, Videos, Realtime, and legacy Completions and Edits.
- Support for OpenAI-compatible providers: Azure, DeepSeek, LM Studio, Ollama, Groq, Together, and others.
- Streaming with a single SSE engine that closes on
[DONE], never duplicates events, and surfaces errors as exceptions. - Resilience: automatic retry on transient failures (connection errors, HTTP 408/429/5xx) with exponential backoff and jitter; configurable retry policy.
- Platform-neutral file uploads using
OpenAIFiletype, nodart:iodependency, works on web. - Typed exceptions for precise error handling:
RequestFailedException,MissingApiKeyException,OpenAIUnexpectedException. - Azure OpenAI support with deployment mapping.
Use cases
- Building Dart/Flutter applications that interact with OpenAI APIs.
- Using OpenAI-compatible providers such as Azure, DeepSeek, LM Studio, or Ollama.
- Streaming responses for chat completions, images, and other endpoints.
- Fine-tuning models, managing vector stores, and batch processing.
- Performing administration tasks like managing projects, users, invites, audit logs, and API keys.
Getting started
Add the dependency to your pubspec.yaml: yaml dependencies: dart_openai: ^8.0.0 Then run: bash dart pub get Quickstart example: dart import 'package:dart_openai/dart_openai.dart'; Future main() async { final client = OpenAIClient(apiKey: Platform.environment['OPENAI_API_KEY']!); 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); }
License and pricing
The SDK is open source under the MIT license. Pricing is not stated; the package is free to use.
Based on the project's public README and repository metadata.