# Interface StreamingListener

All Known Implementing Classes:
  `StreamingListener.Adapter`

public interface StreamingListener

Callback for `LlmClient.chatStream(ChatRequest, StreamingListener)`. Every method is invoked on the EDT; implementations can update UI directly without further marshalling. The terminal `ChatResponse` is delivered via the `AsyncResource` returned by `chatStream`, not via this listener.

Tool-call streaming differs by provider: OpenAI and Anthropic emit argument JSON in fragments (potentially many `onToolCallDelta` calls per tool); Gemini delivers tool calls atomically at the end (a single call with the complete `argumentsFragment` set to the full JSON). Either pattern is valid.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Interface
  Description
  `static class`
  `StreamingListener.Adapter`
  No-op default implementation.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `onContentDelta(String textDelta)`
  A chunk of assistant text.
  `void`
  `onError(Throwable t)`
  Mid-stream error (e.g. connection reset).
  `void`
  `onToolCallDelta(int index, String id, String name, String argumentsFragment)`
  A tool-call fragment.
  `void`
  `onUsage(Usage usage)`
  Token-accounting update.

- ## Method Details

  - ### onContentDelta

    void onContentDelta(String textDelta)
    A chunk of assistant text. Append it to whatever text buffer you're rendering.

  - ### onToolCallDelta

    void onToolCallDelta(int index, String id, String name, String argumentsFragment)
    A tool-call fragment. `index` lets you correlate fragments that belong to the same call when multiple tools are streamed in parallel. `name` is non-null on the first fragment for each call. `argumentsFragment` is the next slice of the arguments JSON; concatenate fragments for the same `index` to reassemble. `id` is the provider's tool-call id, present on the first fragment.

  - ### onUsage

    void onUsage(Usage usage)
    Token-accounting update. Most providers send this once at the end; some send incremental counts.

  - ### onError

    void onError(Throwable t)
    Mid-stream error (e.g. connection reset). The `AsyncResource` returned by `chatStream` will also complete with this same exception, so listeners can typically ignore this and react to the resource. Implemented for parity with other SDKs.