Skip to content

CacheCreationTokens metric

Bases: LMOperationalMetric

Tokens written to the prompt cache during this run (Anthropic cache_creation_input_tokens; you pay a higher rate for these).

Example:

program.compile(
    metrics=[
        synalinks.metrics.CacheCreationTokens(),
    ],
)
Source code in synalinks/src/metrics/lm_metrics.py
@synalinks_export("synalinks.metrics.CacheCreationTokens")
class CacheCreationTokens(LMOperationalMetric):
    """Tokens written to the prompt cache during this run (Anthropic
    `cache_creation_input_tokens`; you pay a higher rate for these).

    Example:

    ```python
    program.compile(
        metrics=[
            synalinks.metrics.CacheCreationTokens(),
        ],
    )
    ```
    """

    def __init__(self, name="cache_creation_tokens"):
        super().__init__(name=name)

    def result(self):
        return int(self._delta("cache_creation_tokens"))