Cost Attribution

Cost attribution is the core feature of InfraPrism. By tagging your LLM calls with entity information, you can answer critical business questions about your AI spend.

Entity Types

InfraPrism supports four built-in entity types:

Entity TypeUse CaseExample
customerTrack costs per customer for margin analysisentity_id="acme-corp"
teamAllocate costs to internal teams for budgetingentity_id="engineering"
projectTrack costs by product or featureentity_id="chatbot-v2"
employeeMonitor individual usage (dev, support, etc.)entity_id="emp-12345"

Basic Usage

Add entity_type and entity_id to any LLM call:

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": user_message}],
    entity_type="customer",
    entity_id="acme-corp",
)

Choosing an Entity Type

Customer Attribution

Use customer when you need to:

  • Calculate per-customer AI costs for margin analysis
  • Identify margin-negative customers
  • Bill customers for AI usage
  • Set per-customer usage limits
# E-commerce chatbot
response = client.chat.completions.create(
    model="gpt-4o",
    messages=conversation,
    entity_type="customer",
    entity_id=current_user.company_id,  # "acme-corp"
)

Team Attribution

Use team when you need to:

  • Allocate AI costs to department budgets
  • Track R&D vs. production spend
  • Compare team efficiency
# Internal tool
response = client.chat.completions.create(
    model="gpt-4o",
    messages=messages,
    entity_type="team",
    entity_id="customer-support",  # or "engineering", "sales", etc.
)

Project Attribution

Use project when you need to:

  • Track costs by product or feature
  • Compare AI spend across initiatives
  • Make build vs. buy decisions
# Feature-specific tracking
response = client.chat.completions.create(
    model="gpt-4o",
    messages=messages,
    entity_type="project",
    entity_id="smart-search",  # or "doc-summarizer", "code-review", etc.
)

Employee Attribution

Use employee when you need to:

  • Monitor developer AI tool usage
  • Track support agent AI assistance
  • Manage individual quotas
# Developer tool
response = client.chat.completions.create(
    model="gpt-4o",
    messages=messages,
    entity_type="employee",
    entity_id=current_user.employee_id,  # "emp-12345"
)

Multiple Dimensions

You can combine entity attribution with custom tags for multi-dimensional analysis:

response = client.chat.completions.create(
    model="gpt-4o",
    messages=messages,
    entity_type="customer",
    entity_id="acme-corp",
    tags={
        "feature": "chatbot",        # Which feature
        "team": "support",           # Which team operates it
        "tier": "enterprise",        # Customer tier
        "env": "production",         # Environment
    },
)

This lets you answer questions like:

  • “What’s the chatbot cost for enterprise customers?”
  • “How much does the support team’s AI usage cost per customer?”

Best Practices

Use Stable IDs

Use stable, internal identifiers rather than names:

# Good - stable ID
entity_id="cust-12345"

# Avoid - names can change
entity_id="Acme Corporation"

Be Consistent

Use the same entity ID across your codebase:

# Define constants
ENTITY_TYPES = {
    "CUSTOMER": "customer",
    "TEAM": "team",
}

# Use consistently
response = client.chat.completions.create(
    model="gpt-4o",
    messages=messages,
    entity_type=ENTITY_TYPES["CUSTOMER"],
    entity_id=customer.id,
)

Handle Missing Context

Always provide entity information, even with a default:

def get_entity_id(user) -> str:
    if user and user.company_id:
        return user.company_id
    return "anonymous"

response = client.chat.completions.create(
    model="gpt-4o",
    messages=messages,
    entity_type="customer",
    entity_id=get_entity_id(current_user),
)

Don’t Include PII

Entity IDs should be internal identifiers, not personal information:

# Good
entity_id="cust-12345"

# Avoid - PII
entity_id="[email protected]"

Dashboard Features

With proper attribution, you can:

  1. View costs by entity - See which customers/teams/projects drive spend
  2. Compare periods - Track cost changes over time per entity
  3. Set alerts - Get notified when an entity exceeds thresholds
  4. Export data - Download per-entity cost reports for billing

API Access

Query costs programmatically via the Analytics API:

import requests

response = requests.get(
    "https://api.infraprism.com/v1/analytics/costs",
    headers={"Authorization": "Bearer ip-..."},
    params={
        "entity_type": "customer",
        "start_date": "2025-01-01",
        "end_date": "2025-01-31",
    },
)

for entity in response.json()["data"]:
    print(f"{entity['entity_id']}: ${entity['total_cost']:.2f}")

See Analytics API for full documentation.

Next Steps