Skip to content

ccproxy.plugins.command_replay.config

ccproxy.plugins.command_replay.config

Configuration for the Command Replay plugin.

CommandReplayConfig

Bases: BaseModel

Configuration for command replay generation.

Generates curl and xh commands for provider requests to enable easy replay and debugging of API calls.

should_generate_for_url

should_generate_for_url(url, is_provider_request=None)

Check if commands should be generated for the given URL.

Parameters:

Name Type Description Default
url str

The request URL to check

required
is_provider_request bool | None

Whether this is a provider request (None = auto-detect)

None

Returns:

Type Description
bool

True if commands should be generated for this URL

Source code in ccproxy/plugins/command_replay/config.py
def should_generate_for_url(
    self, url: str, is_provider_request: bool | None = None
) -> bool:
    """Check if commands should be generated for the given URL.

    Args:
        url: The request URL to check
        is_provider_request: Whether this is a provider request (None = auto-detect)

    Returns:
        True if commands should be generated for this URL
    """
    # Check exclude patterns first
    if self.exclude_url_patterns:
        if any(pattern in url for pattern in self.exclude_url_patterns):
            return False

    # Auto-detect if this is a provider request if not specified
    if is_provider_request is None:
        provider_domains = [
            "api.anthropic.com",
            "claude.ai",
            "api.openai.com",
            "chatgpt.com",
        ]
        is_provider_request = any(
            domain in url.lower() for domain in provider_domains
        )

    # Apply request type filtering
    if self.only_provider_requests and not is_provider_request:
        return False

    if not self.include_client_requests and not is_provider_request:
        return False

    # For provider requests, check include patterns
    if is_provider_request:
        if self.include_url_patterns:
            return any(pattern in url for pattern in self.include_url_patterns)
    else:
        # For client requests, be more permissive
        # Only filter if there are specific include patterns that don't match
        if self.include_url_patterns:
            # If include patterns are all provider domains, allow client requests
            provider_only = all(
                any(
                    provider in pattern.lower()
                    for provider in ["anthropic", "openai", "claude", "chatgpt"]
                )
                for pattern in self.include_url_patterns
            )
            if provider_only:
                return True
            # Otherwise apply normal include pattern matching
            return any(pattern in url for pattern in self.include_url_patterns)

    # Default: generate for all URLs if no patterns specified
    return True