Skip to content

ccproxy.plugins.claude_api.routes

ccproxy.plugins.claude_api.routes

API routes for Claude API plugin.

create_anthropic_message async

create_anthropic_message(request, _, auth, adapter)

Create a message using Claude AI with native Anthropic format.

Source code in ccproxy/plugins/claude_api/routes.py
@router.post(
    "/v1/messages",
    response_model=anthropic_models.MessageResponse | anthropic_models.APIError,
)
@with_format_chain(
    [FORMAT_ANTHROPIC_MESSAGES], endpoint=UPSTREAM_ENDPOINT_ANTHROPIC_MESSAGES
)
async def create_anthropic_message(
    request: Request,
    _: anthropic_models.CreateMessageRequest,
    auth: ConditionalAuthDep,
    adapter: ClaudeAPIAdapterDep,
) -> APIResponse:
    """Create a message using Claude AI with native Anthropic format."""
    return await _handle_adapter_request(request, adapter)

create_openai_chat_completion async

create_openai_chat_completion(request, _, auth, adapter)

Create a chat completion using Claude AI with OpenAI-compatible format.

Source code in ccproxy/plugins/claude_api/routes.py
@router.post(
    "/v1/chat/completions",
    response_model=openai_models.ChatCompletionResponse | openai_models.ErrorResponse,
)
@with_format_chain(
    [FORMAT_OPENAI_CHAT, FORMAT_ANTHROPIC_MESSAGES],
    endpoint=UPSTREAM_ENDPOINT_ANTHROPIC_MESSAGES,
)
async def create_openai_chat_completion(
    request: Request,
    _: openai_models.ChatCompletionRequest,
    auth: ConditionalAuthDep,
    adapter: ClaudeAPIAdapterDep,
) -> APIResponse:
    """Create a chat completion using Claude AI with OpenAI-compatible format."""
    return await _handle_adapter_request(request, adapter)

claude_v1_responses async

claude_v1_responses(request, auth, adapter)

Response API compatible endpoint using Claude backend.

Source code in ccproxy/plugins/claude_api/routes.py
@router.post("/v1/responses", response_model=None)
@with_format_chain(
    [FORMAT_OPENAI_RESPONSES, FORMAT_ANTHROPIC_MESSAGES],
    endpoint=UPSTREAM_ENDPOINT_ANTHROPIC_MESSAGES,
)
async def claude_v1_responses(
    request: Request,
    auth: ConditionalAuthDep,
    adapter: ClaudeAPIAdapterDep,
) -> APIResponse:
    """Response API compatible endpoint using Claude backend."""
    # Ensure format chain is present for request/response conversion
    # format chain and endpoint set by decorator
    session_id = request.headers.get("session_id") or str(uuid.uuid4())
    return await _handle_adapter_request(request, adapter)

list_models async

list_models(request, auth, config)

List available Claude models from configuration.

Source code in ccproxy/plugins/claude_api/routes.py
@router.get("/v1/models", response_model=openai_models.ModelList)
async def list_models(
    request: Request,
    auth: ConditionalAuthDep,
    config: ClaudeAPIConfigDep,
) -> dict[str, Any]:
    """List available Claude models from configuration."""
    models = [card.model_dump(mode="json") for card in config.models_endpoint]
    return {"object": "list", "data": models}