ccproxy.services.proxy_service¶
ccproxy.services.proxy_service
¶
Proxy service for orchestrating Claude API requests with business logic.
RequestData
¶
Bases: TypedDict
Typed structure for transformed request data.
ResponseData
¶
Bases: TypedDict
Typed structure for transformed response data.
ProxyService
¶
ProxyService(
proxy_client,
credentials_manager,
settings,
proxy_mode="full",
target_base_url="https://api.anthropic.com",
metrics=None,
)
Claude-specific proxy orchestration with business logic.
This service orchestrates the complete proxy flow including: - Authentication management - Request/response transformations - Metrics collection (future) - Error handling and logging
Pure HTTP forwarding is delegated to BaseProxyClient.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
proxy_client
|
BaseProxyClient
|
HTTP client for pure forwarding |
required |
credentials_manager
|
CredentialsManager
|
Authentication manager |
required |
settings
|
Settings
|
Application settings |
required |
proxy_mode
|
str
|
Transformation mode - "minimal" or "full" |
'full'
|
target_base_url
|
str
|
Base URL for the target API |
'https://api.anthropic.com'
|
metrics
|
PrometheusMetrics | None
|
Prometheus metrics collector (optional) |
None
|
Source code in ccproxy/services/proxy_service.py
handle_request
async
¶
Handle a proxy request with full business logic orchestration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
method
|
str
|
HTTP method |
required |
path
|
str
|
Request path (without /unclaude prefix) |
required |
headers
|
dict[str, str]
|
Request headers |
required |
body
|
bytes | None
|
Request body |
None
|
query_params
|
dict[str, str | list[str]] | None
|
Query parameters |
None
|
timeout
|
float
|
Request timeout in seconds |
240.0
|
request
|
Request | None
|
Optional FastAPI Request object for accessing request context |
None
|
Returns:
Type | Description |
---|---|
tuple[int, dict[str, str], bytes] | StreamingResponse
|
Tuple of (status_code, headers, body) or StreamingResponse for streaming |
Raises:
Type | Description |
---|---|
HTTPException
|
If request fails |
Source code in ccproxy/services/proxy_service.py
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 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 |
|
handle_models_request
async
¶
Handle a /v1/models request to list available models.
Since Anthropic API doesn't support /v1/models endpoint, returns a hardcoded list of Anthropic models and recent OpenAI models.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
headers
|
dict[str, str]
|
Request headers |
required |
timeout
|
float
|
Request timeout in seconds |
240.0
|
Returns:
Type | Description |
---|---|
tuple[int, dict[str, str], bytes]
|
Tuple of (status_code, headers, body) |
Source code in ccproxy/services/proxy_service.py
1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 |
|
close
async
¶
Close any resources held by the proxy service.