WorkflowAI
WorkflowAI
Inference

Cost Metadata

While most standard LLM APIs return usage metrics (like input and output token counts), they typically don't provide the actual monetary cost of the request. Developers are often left to calculate this themselves, requiring them to maintain and apply up-to-date pricing information for each model.

WorkflowAI simplifies cost tracking by automatically calculating the estimated cost for each LLM request based on the specific model used and WorkflowAI's current pricing data.

Programmatically

TODO:

  • adjust the code for this section, the cost and latency are inside the array choices[]
  • add WorkflowAI SDK and REST API examples
....
class Answer(BaseModel):
    sentiment: str
    score: float

answer, completion = client.chat.completions.create_with_completion(
    model="gpt-4o-mini",
    response_model=Answer,
    messages=[{"role": "user", "content": "I love Workflow AI!"}],
    metadata={"agent_id": "sentiment-analysis-agent"}
)

cost = getattr(completion.choices[0], 'cost_usd', None)
latency = getattr(completion.choices[0], 'duration_seconds', None)
# Ruby implementation here
...
# Instructor implementation here
...

...

You can also track costs in the Playground and the Monitor sections.

TODO: add a section on how to track costs via the API and MCP.

How is this guide?

On this page