ccproxy.claude_sdk¶
ccproxy.claude_sdk
¶
Claude SDK integration module.
ClaudeSDKClient
¶
Minimal Claude SDK client wrapper that handles core SDK interactions.
This class provides a clean interface to the Claude Code SDK while handling error translation and basic query execution.
Source code in ccproxy/claude_sdk/client.py
query_completion
async
¶
Execute a query using the Claude Code SDK.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt
|
str
|
The prompt string to send to Claude |
required |
options
|
ClaudeCodeOptions
|
Claude Code options configuration |
required |
request_id
|
str | None
|
Optional request ID for correlation |
None
|
Yields:
Type | Description |
---|---|
AsyncIterator[UserMessage | AssistantMessage | SystemMessage | ResultMessage]
|
Messages from the Claude Code SDK |
Raises:
Type | Description |
---|---|
ClaudeSDKError
|
If the query fails |
Source code in ccproxy/claude_sdk/client.py
get_last_api_call_time_ms
¶
Get the duration of the last Claude API call in milliseconds.
Returns:
Type | Description |
---|---|
float
|
Duration in milliseconds, or 0.0 if no call has been made yet |
validate_health
async
¶
Validate that the Claude SDK is healthy.
Returns:
Type | Description |
---|---|
bool
|
True if healthy, False otherwise |
Source code in ccproxy/claude_sdk/client.py
ClaudeSDKConnectionError
¶
Bases: ClaudeSDKError
Raised when unable to connect to Claude Code.
ClaudeSDKProcessError
¶
Bases: ClaudeSDKError
Raised when Claude Code process fails.
MessageConverter
¶
Handles conversion between Anthropic API format and Claude SDK format.
format_messages_to_prompt
staticmethod
¶
Convert Anthropic messages format to a single prompt string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
messages
|
list[dict[str, Any]]
|
List of messages in Anthropic format |
required |
Returns:
Type | Description |
---|---|
str
|
Single prompt string formatted for Claude SDK |
Source code in ccproxy/claude_sdk/converter.py
extract_text_from_content
staticmethod
¶
Extract text content from Claude SDK content blocks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content
|
TextBlock | ToolUseBlock | ToolResultBlock
|
List of content blocks from Claude SDK |
required |
Returns:
Type | Description |
---|---|
str
|
Extracted text content |
Source code in ccproxy/claude_sdk/converter.py
extract_contents
staticmethod
¶
Extract content from Claude SDK blocks, preserving custom blocks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content
|
List of content blocks from Claude SDK |
required |
Returns:
Type | Description |
---|---|
str
|
Content with thinking blocks preserved |
Source code in ccproxy/claude_sdk/converter.py
convert_to_anthropic_response
staticmethod
¶
Convert Claude SDK messages to Anthropic API response format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
assistant_message
|
AssistantMessage
|
The assistant message from Claude SDK |
required |
result_message
|
ResultMessage
|
The result message from Claude SDK |
required |
model
|
str
|
The model name used |
required |
Returns:
Type | Description |
---|---|
dict[str, Any]
|
Response in Anthropic API format |
Source code in ccproxy/claude_sdk/converter.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
|
create_streaming_start_chunk
staticmethod
¶
Create the initial streaming chunk for Anthropic API format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message_id
|
str
|
The message ID |
required |
model
|
str
|
The model name |
required |
Returns:
Type | Description |
---|---|
dict[str, Any]
|
Initial streaming chunk |
Source code in ccproxy/claude_sdk/converter.py
create_streaming_delta_chunk
staticmethod
¶
Create a streaming delta chunk for Anthropic API format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
The text content to include |
required |
Returns:
Type | Description |
---|---|
dict[str, Any]
|
Delta chunk |
Source code in ccproxy/claude_sdk/converter.py
create_streaming_end_chunk
staticmethod
¶
Create the final streaming chunk for Anthropic API format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stop_reason
|
str
|
The reason for stopping |
'end_turn'
|
Returns:
Type | Description |
---|---|
dict[str, Any]
|
Final streaming chunk |
Source code in ccproxy/claude_sdk/converter.py
OptionsHandler
¶
Handles creation and management of Claude SDK options.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
settings
|
Settings | None
|
Application settings containing default Claude options |
None
|
Source code in ccproxy/claude_sdk/options.py
create_options
¶
Create Claude SDK options from API parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
str
|
The model name |
required |
temperature
|
float | None
|
Temperature for response generation |
None
|
max_tokens
|
int | None
|
Maximum tokens in response |
None
|
system_message
|
str | None
|
System message to include |
None
|
**kwargs
|
Any
|
Additional options |
{}
|
Returns:
Type | Description |
---|---|
ClaudeCodeOptions
|
Configured ClaudeCodeOptions instance |
Source code in ccproxy/claude_sdk/options.py
extract_system_message
staticmethod
¶
Extract system message from Anthropic messages format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
messages
|
list[dict[str, Any]]
|
List of messages in Anthropic format |
required |
Returns:
Type | Description |
---|---|
str | None
|
System message content if found, None otherwise |
Source code in ccproxy/claude_sdk/options.py
get_supported_models
staticmethod
¶
Get list of supported Claude models.
Returns:
Type | Description |
---|---|
list[str]
|
List of supported model names |