ccproxy.plugins.claude_sdk.hooks¶
ccproxy.plugins.claude_sdk.hooks
¶
Hook integration for Claude SDK plugin to emit streaming metrics.
ClaudeSDKStreamingHook
¶
Bases: Hook
Hook for emitting Claude SDK streaming metrics.
This hook handles streaming completion events from claude_sdk and emits PROVIDER_STREAM_END events with usage metrics for access logging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hook_manager
|
HookManager | None
|
Hook manager for emitting events |
None
|
Source code in ccproxy/plugins/claude_sdk/hooks.py
emit_stream_end
async
¶
emit_stream_end(
request_id,
usage_metrics,
provider="claude_sdk",
url="claude-sdk://direct",
method="POST",
total_chunks=0,
total_bytes=0,
)
Emit PROVIDER_STREAM_END event with usage metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request_id
|
str
|
Request ID for correlation |
required |
usage_metrics
|
dict[str, Any]
|
Dictionary containing token counts and costs |
required |
provider
|
str
|
Provider name (default: claude_sdk) |
'claude_sdk'
|
url
|
str
|
URL or endpoint identifier |
'claude-sdk://direct'
|
method
|
str
|
HTTP method |
'POST'
|
total_chunks
|
int
|
Number of chunks streamed |
0
|
total_bytes
|
int
|
Total bytes streamed |
0
|