Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:BerriAI Litellm Check Responses Cost

From Leeroopedia
Attribute Value
Sources enterprise/litellm_enterprise/proxy/common_utils/check_responses_cost.py
Domains Cost Tracking, Responses API, Background Jobs, Enterprise
Last Updated 2026-02-15 16:00 GMT

Overview

CheckResponsesCost is a background polling utility that checks the completion status of managed Responses API jobs and relies on litellm.aget_responses() to automatically track their cost.

Description

This class polls the LiteLLM_ManagedObjectTable database table for response jobs that are in queued or in_progress status with file_purpose="response". For each active job, it:

  1. Retrieves the stored response object to extract the model name.
  2. Decrypts the unified response ID using ResponsesIDSecurity._decrypt_response_id.
  3. Calls litellm.aget_responses() with the decrypted response ID and metadata. Cost tracking is handled automatically by this call.
  4. Checks the response status:
    • "completed" -- Marks the job as completed.
    • "failed" or "cancelled" -- Also marks the job as completed (terminal state).
    • Other statuses -- Skips (job remains in progress).
  5. Updates all completed jobs to "completed" status in the database via a batch update.

Unlike CheckBatchCost, this class does not need to manually calculate cost because litellm.aget_responses() handles cost tracking through the standard logging pipeline.

Usage

Instantiate and call check_responses_cost periodically (e.g., via a background scheduler) to ensure background Responses API jobs are tracked after completion.

Code Reference

Source Location

enterprise/litellm_enterprise/proxy/common_utils/check_responses_cost.py

Signature

class CheckResponsesCost:
    def __init__(
        self,
        proxy_logging_obj: ProxyLogging,
        prisma_client: PrismaClient,
        llm_router: Router,
    ): ...

    async def check_responses_cost(self): ...

Import

from litellm_enterprise.proxy.common_utils.check_responses_cost import CheckResponsesCost

I/O Contract

Inputs

Parameter Type Description
proxy_logging_obj ProxyLogging Proxy logging object (currently unused but maintained for consistency).
prisma_client PrismaClient Database client to query managed object table.
llm_router Router LLM router (currently unused; responses use litellm.aget_responses directly).

Outputs

Output Type Description
Cost logging Side effect Cost automatically tracked by litellm.aget_responses().
Status update Side effect Completed/failed/cancelled jobs updated to "completed" in the database.

Usage Examples

from litellm_enterprise.proxy.common_utils.check_responses_cost import CheckResponsesCost

checker = CheckResponsesCost(
    proxy_logging_obj=proxy_logging_obj,
    prisma_client=prisma_client,
    llm_router=llm_router,
)

# Run as a periodic background task
await checker.check_responses_cost()

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment