flutter_ai_provider_openai

OpenAI streaming provider for flutter_ai — Chat Completions mapped to AiStreamEvents. Works with the public API or any compatible endpoint (Azure, proxies, local servers).

A streamed answer rendered by flutter_ai

flutter_ai_provider_openai on pub.dev pub points License: BSD-3-Clause

Family: flutter_ai · core · client · elements · anthropic · gemini
Recipes · Migrating from the Vercel AI SDK

Streamed responses render through flutter_ai_elements (AiResponse).


An OpenAI-compatible LlmProvider for the flutter_ai family.

Streams the OpenAI Chat Completions API and maps each chunk to flutter_ai_core AiStreamEvents — text deltas, streamed tool calls, and finish reasons. Works with the public OpenAI endpoint or any compatible server (Azure OpenAI, proxies, local servers) via a custom base URL.

Usage

import 'package:flutter_ai_provider_openai/flutter_ai_provider_openai.dart';

final provider = OpenAiProvider(
  apiKey: const String.fromEnvironment('OPENAI_API_KEY'),
  defaultModel: 'gpt-4o-mini',
);

// Drive it with flutter_ai_client's UseChatController:
final controller = UseChatController(provider: provider);
controller.sendText('Hello!');

Point it elsewhere with baseUrl:

OpenAiProvider(
  apiKey: key,
  baseUrl: Uri.parse('https://my-proxy.example.com/v1'),
);

The HTTP client is injectable (client:) for testing or custom transport.

Status

Published on pub.dev (see the CHANGELOG); depends on flutter_ai_core. The request/response mapping is unit-tested against recorded SSE chunks.

☕ Support this project

Buy me a coffee on Ko-fi

If flutter_ai saves you time, buy me a coffee ☕ — it keeps the whole family maintained.

Libraries

flutter_ai_provider_openai
OpenAI-compatible provider for the flutter_ai family.