ccproxy.streaming.interfaces¶
ccproxy.streaming.interfaces
¶
Streaming interfaces for provider implementations.
This module defines interfaces that providers can implement to extend streaming functionality without coupling core code to specific providers.
StreamingMetrics
¶
Bases: TypedDict
Standard streaming metrics structure.
IStreamingMetricsCollector
¶
Bases: Protocol
Interface for provider-specific streaming metrics collection.
Providers implement this interface to extract token usage and other metrics from their specific streaming response formats.
process_chunk
¶
Process a streaming chunk to extract metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk_str
|
str
|
Raw chunk string from streaming response |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if this was the final chunk with complete metrics, False otherwise |
Source code in ccproxy/streaming/interfaces.py
process_raw_chunk
¶
Process a raw provider chunk before any format conversion.
This method is called with chunks in the provider's native format, before any OpenAI/Anthropic format conversion happens.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk_str
|
str
|
Raw chunk string in provider's native format |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if this was the final chunk with complete metrics, False otherwise |
Source code in ccproxy/streaming/interfaces.py
process_converted_chunk
¶
Process a chunk after format conversion.
This method is called with chunks after they've been converted to a different format (e.g., OpenAI format).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk_str
|
str
|
Chunk string after format conversion |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if this was the final chunk with complete metrics, False otherwise |
Source code in ccproxy/streaming/interfaces.py
get_metrics
¶
Get the collected metrics.
Returns:
| Type | Description |
|---|---|
StreamingMetrics
|
Dictionary with provider-specific metrics (tokens, costs, etc.) |