Skip to content

Add cost tracking for LiteLLM models #1831

@habema

Description

@habema

Problem:
When using LiteLLM models, there's no way to track how much each request costs. LiteLLM provides this info via _hidden_params["response_cost"] and their completion_cost() function, but the SDK doesn't expose it.

Proposed Solution:
Add opt-in cost tracking via ModelSettings that populates usage.cost with cost estimates from LiteLLM.

Usage:

agent = Agent(
    model=LitellmModel(model="...", api_key="..."),
    model_settings=ModelSettings(
        include_usage=True,
        track_cost=True,  # opt-in
    ),
)

result = await Runner.run(agent, "Hello")
print(f"Cost: ${result.context_wrapper.usage.cost}")

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions