Skip to main content
This guide will walk you through the complete setup process to send your first meter event, create an agent, set up billing, and generate your first invoice.

2.1 Installing the SDK

Install the Valmi Value Python SDK:
pip install valmi-value
Python 3.8+ is required. Support for Node.js, Go, and other languages coming soon.

2.2 Send Your First Meter Event

from valmi_value import ValueClient
from langgraph.graph import StateGraph

# Initialize the Value client
value = ValueClient(api_key="your-api-key")

# In your agent workflow
def agent_node(state):
    # Your agent logic here
    result = llm.invoke(state["messages"])
    
    # Send meter event
    value.send_action(
        agent_key="my-langgraph-agent",
        action_type="llm_call",
        metadata={
            "model": "gpt-4",
            "input_tokens": result.usage.prompt_tokens,
            "output_tokens": result.usage.completion_tokens,
            "cost_usd": calculate_cost(result.usage)
        }
    )
    
    return {"messages": result}

2.3 Create Your First Agent

  1. Log in to the Valmi Value Control Plane
  2. Navigate to AgentsCreate Agent
  3. Fill in the agent details:
    • Name: My First Agent
    • Type: LangGraph Agent
    • Description: A simple agent for testing
  4. Click Create
You’ll receive an Agent Key that you’ll use in your SDK calls. Keep this secure!

2.4 Attach Metering to the Agent

  1. In the Agent details page, copy the Agent Key
  2. Update your code to use this key:
value = ValueClient(api_key="your-api-key")

value.send_action(
    agent_key="agent_abc123xyz",  # Your agent key
    action_type="llm_call",
    metadata={...}
)
  1. Events will start appearing in the Live Data view within seconds

2.5 Set Up a Billing Plan

  1. Navigate to ProductsCreate Product
  2. Create a new product:
    • Product Name: AI Agent API
    • Description: Pay-per-use AI agent service
  3. Create a Rate Plan:
    • Plan Name: Usage-Based Plan
    • Pricing Model: Usage-Based
    • Charge: $0.01 per 1,000 tokens
  4. Save the plan

2.6 Create an Account + Subscription

  1. Go to AccountsCreate Account
  2. Fill in account details:
  3. Click Create Subscription:
    • Select your product and rate plan
    • Set billing cycle (monthly)
    • Assign the agent instance to this subscription
  4. Save the subscription

2.7 Generate First Invoice

  1. Navigate to BillingInvoices
  2. Click Run Invoice for the current billing period
  3. The system will:
    • Aggregate all usage for the period
    • Apply pricing rules
    • Calculate costs and revenue
    • Generate the invoice
  4. View and download the invoice PDF

2.8 View Revenue & Margin

  1. Go to Profit & Loss dashboard
  2. You’ll see:
    • Revenue: Total billed amount
    • Costs: LLM and infrastructure costs
    • Margin: Revenue - Costs
    • Margin %: Profitability percentage
  3. Filter by agent, customer, or time period