Docs/Aigovernance/Aicost

AI Cost (FinOps)

Control and optimize your AI spending with comprehensive Cost (FinOps) capabilities. Cost is the primary indicator and measurable outcome of FinOps - providing visibility, allocation, optimization, and accountability for your AI investments.

What is AI Cost (FinOps)?

Cost (FinOps) for AI helps organizations achieve cost visibility, allocation, optimization, and accountability:

  • Track every dollar spent on AI operations
  • Attribute costs to customers, teams, or products
  • Optimize spending through data-driven decisions
  • Forecast future costs and budget accordingly
  • Maximize ROI on AI investments

Key Capabilities

1. Real-Time Cost Tracking

Cost tracking is driven by the traces your application sends to Agentic Ants. Instrument your LLM calls once and every generation's token usage and cost is captured automatically.

First, set up tracing at startup (in an instrumentation.ts that is imported before the rest of your app):

typescript
const provider = new NodeTracerProvider({ spanProcessors: [ new AntsPlatformSpanProcessor({ publicKey: process.env.ANTS_PLATFORM_PUBLIC_KEY, secretKey: process.env.ANTS_PLATFORM_SECRET_KEY, baseUrl: "https://api.agenticants.ai", }), ], }); provider.register(); setAntsPlatformTracerProvider(provider);

Then wrap your OpenAI client so every call is traced and costed:

typescript
const openai = observeOpenAI(new OpenAI()); // Every call is now auto-traced; token usage and cost roll up in the dashboard. await openai.chat.completions.create({ model: "gpt-4o-mini", messages: [{ role: "user", content: "What is AI?" }], });

Live spend totals (today, this month, hourly burn rate) are shown on the cost dashboard at https://app.agenticants.ai.

2. Cost Attribution

Know who's driving costs by attaching identifying metadata to your traces. Use the @observe() decorator and tag the current trace with a customer, team, or product:

python
from ants_platform import observe, get_client from ants_platform.openai import openai @observe() def answer_query(customer_id: str, question: str): client = get_client() client.update_current_trace( user_id=customer_id, metadata={"customer_id": customer_id}, ) return openai.chat.completions.create( model="gpt-4o-mini", messages=[{"role": "user", "content": question}], )

Once traces carry this metadata, break costs down by customer, team, or product on the cost dashboard at https://app.agenticants.ai.

3. Budget Management

Budgets and threshold alerts are configured in the dashboard, not through the SDK. Create budgets (for example a quarterly AI budget with warning thresholds and notification channels) and manage them at https://app.agenticants.ai.

4. ROI Analytics

ROI metrics - cost vs. revenue, payback period, and cost per conversion - are calculated from your tracked spend and shown on the analytics views at https://app.agenticants.ai.

Cost Breakdown

What Drives Costs?

Cost Per Operation

To get a per-operation cost breakdown, model each operation as its own span so the dashboard can attribute generation cost to the right step. Use start_as_current_span to nest operations under a trace:

python
from ants_platform import observe, get_client from ants_platform.openai import openai @observe() def customer_support(question: str): client = get_client() with client.start_as_current_span(name="classification"): classify(question) with client.start_as_current_span(name="retrieval"): docs = retrieve(question) with client.start_as_current_span(name="generation"): return openai.chat.completions.create( model="gpt-4o-mini", messages=[{"role": "user", "content": f"{docs}\n\n{question}"}], )

The per-span cost breakdown (classification, retrieval, generation, total) for a given agent and time range is available on the cost dashboard at https://app.agenticants.ai.

Optimization Strategies

1. Model Selection

Use the right model for the job. Because every generation is traced with its model and token usage, you can compare the real cost of different models side by side in the dashboard.

python
from ants_platform.openai import openai # Expensive openai.chat.completions.create( model="gpt-4o", messages=[{"role": "user", "content": prompt}], ) # More economical openai.chat.completions.create( model="gpt-4o-mini", messages=[{"role": "user", "content": prompt}], ) # Compare the actual per-model cost at https://app.agenticants.ai

2. Response Caching

Eliminate redundant calls. Wrap your query function with observe so cache hits and misses are both visible in your traces, then compare their cost in the dashboard.

typescript
const processQuery = observe( async (question: string) => { const cached = cache.get(question); if (cached) { const span = startObservation("span", { name: "cache-hit" }); span.end(); return cached; // no model call, no cost } const answer = await callModel(question); cache.set(question, answer); return answer; }, { name: "process-query" } ); await processQuery("What is AI?"); // model call, costed await processQuery("What is AI?"); // cache hit, no cost

3. Prompt Optimization

Shorter prompts mean lower costs. Token counts are captured on every traced generation, so you can confirm the savings of a trimmed prompt in the dashboard.

python
from ants_platform.openai import openai # Long prompt (inefficient) - large context, more tokens prompt = f""" You are a helpful assistant. Please help the user. Context: {context} User question: {question} Please provide a detailed answer. """ # Optimized prompt - summarized context, far fewer tokens prompt = f"Context: {summarize(context)}\nQ: {question}" openai.chat.completions.create( model="gpt-4o-mini", messages=[{"role": "user", "content": prompt}], ) # Compare token usage and cost for both at https://app.agenticants.ai

4. Smart Sampling

Don't trace everything. Decide per request whether to create an observation, so high-volume free-tier traffic doesn't dominate your trace volume.

typescript
const shouldTrace = (request) => { // Always trace errors if (request.error) return true; // Always trace premium users if (request.userTier === "enterprise") return true; // Sample 10% of free tier return Math.random() < 0.1; }; function handle(request) { if (shouldTrace(request)) { const span = startObservation("span", { name: "request" }); try { return process(request); } finally { span.end(); } } return process(request); }

Cost Dashboards

Real-Time View

The real-time cost view (current spend, burn rate, and live activity) is available on the dashboard at https://app.agenticants.ai.

Cost trends over time (for example the last 90 days at daily granularity) are visualized on the dashboard at https://app.agenticants.ai. There is no SDK query API for trends - use the dashboard.

Alerting

Budget Alerts

Budget threshold alerts and anomaly-detection alerts - including the notification channels they fire to (email, Slack, PagerDuty) - are configured entirely in the dashboard at https://app.agenticants.ai. There is no programmatic alerts API in the SDK.

Cost Spike Detection

Automatic cost-spike and anomaly detection (baseline window, threshold multiplier, minimum spend) is a dashboard feature. Configure it at https://app.agenticants.ai.

Reporting

Monthly Reports

Cost reports - including trends and optimization recommendations, plus PDF export and emailing to your team - are generated from the dashboard at https://app.agenticants.ai.

Custom Reports

Custom and scheduled reports (executive summaries, cost by team, ROI metrics, optimization opportunities) are built and scheduled in the dashboard at https://app.agenticants.ai.

Best Practices

1. Tag Everything

Attach metadata to your traces so costs can be attributed accurately in the dashboard.

python
from ants_platform import observe, get_client @observe(name="query") def run_query(question: str): client = get_client() client.update_current_trace( metadata={ "customer_id": "cust_123", "team": "sales", "product": "chatbot", "environment": "production", }, ) return handle(question)

2. Set Budgets

Per-team budgets (for example a monthly engineering budget) are defined in the dashboard at https://app.agenticants.ai.

3. Review Weekly

Weekly cost summaries and week-over-week change are available on the dashboard at https://app.agenticants.ai. Make reviewing them a recurring habit for your team.

4. Optimize Continuously

Cost-saving recommendations (and their estimated monthly savings) surface automatically on the dashboard at https://app.agenticants.ai as your traces accumulate.

Integration with Billing

Connect to Stripe

Billing integrations - syncing tracked AI cost into Stripe, pass-through customer billing, and markup - are configured in the dashboard at https://app.agenticants.ai.

Usage-Based Pricing

Usage-based pricing (per-token price, minimum charge, billing cycle) is configured in the dashboard at https://app.agenticants.ai, driven by the token usage captured in your traces.

Next Steps

Set Up Cost Tracking →

© 2026 ANTS Platform, Inc.Docs v1.0 · Last updated June 2026