opik-mcp

cost-intelligence

Purpose

Cost intelligence lets an agent answer an organization’s Claude Code spend questions from an AI Spend workspace: who spends the most, what the spend is made of, and what happened in the most expensive session. This doc says when the spend types appear, what they answer, and why the guide lives outside the skills folder.

What it does now

When it turns on

The AI Spend feature is on when the transport is stdio and the workspace name starts with __ai_spend_. That predicate is the feature’s own (is_cost_intelligence_enabled in src/opik_mcp/cost_intelligence/__init__.py); the toggle config calls it once at startup and stores the answer as a named boolean, FeatureToggles.cost_intelligence_enabled. The hosted HTTP server never turns it on, whatever the workspace is called (test_the_hosted_transport_never_turns_the_feature_on). Every other workspace keeps the default surface, byte for byte.

What the feature adds

Nothing is hidden or removed. The default tools, types, arguments, skills and project handling work as in any workspace. In an AI Spend workspace the server adds:

What the spend types answer

Every spend type queries the AI Spend endpoints for project claude-code over a window (since/until, 30 days by default) and links the matching AI Spend page. Each answer states its size and labels its dollars as billed or list price, because the backend uses one field name for both.

Call Answers
list('spend_summary') Headline figures for the window against the window before
list('spend_lane') Where the tokens go: one row per lane, by side
read('spend_lane', <lane>) The lane’s top items with tokens, dollars and users, plus how many more exist
list('spend_user') The leaderboard by total tokens; filters on mcp_server, skill or built_in_tool gives who uses one item
list('spend_session') Sessions by total tokens, with analysis status and summary
read('spend_session', <id>) The session narrative when analysis is ready; otherwise the status and the thread outline call to make
list('spend_agent') Subagent usage and how much is attributed

Spend data needs an organization admin’s key; a 403 becomes one sentence saying so on the first spend call. Opik’s own cost fields on traces, threads and read('project') are empty in this workspace, and the instructions and the guide say not to report them.

The guide

read_skill('cost-intelligence') returns src/opik_mcp/cost_intelligence/cost-intelligence.md: what the lanes mean, what is logged, how threads and traces map to sessions and turns, how to outline a session, and recipes for the three questions. It is an unknown skill in every other workspace.

How it works

list/read → run_list/run_read → FeatureToggles.resolve(settings) → visibility (which types)
          → the entity's handler (entities/spend/*) → client/ai_spend.py → AI Spend endpoints
build_server(settings) → register_tools → contributions.tool_sentences (at registration)
          → feature_surface (the advertised enums only)
instructions → contributions.instructions_paragraphs; read_skill → contributions.extra_skills

A feature contributes through accessors on the toggle config. There is no “what a feature adds” contract: a toggle touches the concerns it happens to touch, so a later one that has nothing to do with tools or skills adds a boolean and nothing else.

Where to start:

Decisions

Traps

Proven by

Log