ai_sdk_client
A Dart library for consuming vercel AI SDK data streams
Note
This only supports vercel v4 AI SDK stream protocol compatible streams.
Installation
dart pub add ai_sdk_client
Setup
This package is pure dart and does not require any native dependencies.
Usage
final dio = Dio();
final req = await dio.post(
'http://localhost:8080',
options: Options(
responseType: ResponseType.stream,
),
);
final stream = req.data.stream as Stream<List<int>>;
final streamConsumer = AiSDKStreamConsumer(stream: stream);
final chunks = await streamConsumer.consume();
// Create a subscription to handle the stream
final subscription = chunks.controller.stream.listen(
(event) {
print('Received chunk: $event');
},
onError: (error) {
print('Error in stream: $error');
},
onDone: () {
print('Stream completed');
},
);
Chunks
This package supports all the chunks that are supported by the vercel AI SDK.
You can find the chunks in the lib/chunks directory.
License
MIT
Libraries
- ai_sdk_client
- chunks/base
- chunks/data
- chunks/error
- chunks/file
- chunks/finish_message
- chunks/finish_step
- chunks/message_annotation
- chunks/reasoning
- chunks/reasoning_signature
- chunks/redacted_reasoning
- chunks/source
- chunks/start_step
- chunks/text
- chunks/tool_call
- chunks/tool_call_delta
- chunks/tool_call_streaming_start
- chunks/tool_result
- chunks/type
- chunks/unknown
- extensions/string
- stream