Skip to content

JavaScript ChatClient Streaming Uses Callbacks, Not Async Iterators #507

@leestott

Description

@leestott

JavaScript ChatClient Streaming Uses Callbacks, Not Async Iterators

Severity: Documentation gap
Component: foundry-local-sdk JavaScript v0.9.x — ChatClient.completeStreamingChat()

The ChatClient returned by model.createChatClient() provides a completeStreamingChat() method, but it uses a callback pattern rather than returning an async iterable:

// ❌ This does NOT work — throws "stream is not async iterable"
for await (const chunk of chatClient.completeStreamingChat(messages)) { ... }

// ✅ Correct pattern — pass a callback
await chatClient.completeStreamingChat(messages, (chunk) => {
  process.stdout.write(chunk.choices?.[0]?.delta?.content ?? "");
});

Impact: Developers familiar with the OpenAI SDK's async iteration pattern (for await) will encounter confusing errors. The callback must be a valid function or the SDK throws "Callback must be a valid function."

Expected: Document the callback pattern in the SDK reference. Alternatively, support the async iterable pattern for consistency with the OpenAI SDK.


Metadata

Metadata

Labels

js sdkIssue related to JavaScript SDKpapercutThis issue relates to user experience papercut

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions