Skip to main content

ai_stream_client 0.1.0 copy "ai_stream_client: ^0.1.0" to clipboard
ai_stream_client: ^0.1.0 copied to clipboard

A typed, provider-neutral Dart client for streaming OpenAI-compatible chat APIs with cancellation and structured errors.

ai_stream_client #

A small, typed Dart client for streaming responses from OpenAI-compatible chat APIs. It is provider-neutral, testable, and works in Flutter, Dart servers, and web applications.

Features #

  • Parses Server-Sent Events (SSE) into typed chunks
  • Works with OpenAI-compatible gateways and backend proxies
  • Supports custom headers, cancellation signals, and structured errors
  • Includes a convenience API that combines a stream into one response
  • Has no Flutter dependency

Installation #

dependencies:
  ai_stream_client: ^0.1.0

Usage #

final client = AiStreamClient(
  baseUrl: Uri.parse('https://your-backend.example.com/v1/'),
);

final request = AiChatRequest(
  model: 'your-model',
  messages: const [AiMessage.user('What makes Flutter fast?')],
);

await for (final chunk in client.streamChat(request)) {
  print(chunk.text);
}

client.close();

Use complete when incremental updates are not needed:

final response = await client.complete(request);
print(response.text);

Cancellation and errors #

Pass an AiCancelToken and call cancel() when the user stops generation. HTTP failures use AiHttpException; malformed events use AiProtocolException.

Security #

Never embed a production provider API key in a mobile or web application. Point this client at a backend you control and keep the provider credential on the server.

Compatibility #

The client sends POST chat/completions relative to baseUrl and reads the common data: {...} SSE format. Use request metadata and client defaultHeaders for provider-specific values.

License #

MIT © 2026 Syed Waleed Nawaz

1
likes
160
points
419
downloads

Documentation

API reference

Publisher

verified publishersyedwaleednawaz.com

Weekly Downloads

A typed, provider-neutral Dart client for streaming OpenAI-compatible chat APIs with cancellation and structured errors.

Homepage
Repository (GitHub)
View/report issues

Topics

#ai #streaming #api-client #sse

License

MIT (license)

Dependencies

http

More

Packages that depend on ai_stream_client