Skip to content

Hypothesize-Tech/costkatana-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cost Katana Examples

Production-ready examples for every Cost Katana feature

Documentation Discord GitHub

Overview

This repository contains 350+ production-ready code examples demonstrating how to use Cost Katana across 49 different features. Whether you're building with TypeScript, Python, or directly via HTTP APIs, you'll find working examples with full error handling and best practices.

What you'll find here:

  • 🟦 TypeScript/Node.js - Complete SDK examples with type safety
  • 🟨 Python - Pythonic examples with the Cost Katana SDK
  • 🟩 HTTP REST APIs - Direct API calls you can test immediately
  • 🔧 Framework Integrations - Express, Next.js, Fastify, NestJS, FastAPI

Quick Start

1. Get Your API Key

Sign up at costkatana.com/dashboard to get your API key.

2. Choose Your Language

TypeScript/Node.js:

npm install cost-katana
export COST_KATANA_API_KEY=your_key_here
npx ts-node 1-cost-tracking/npm-package/openai.ts

Python:

pip install costkatana
export COST_KATANA_API_KEY=your_key_here
python 1-cost-tracking/python-sdk/openai.py

HTTP (REST Client):

  1. Install REST Client for VS Code
  2. Open any .http file
  3. Update the API key
  4. Click "Send Request"

Examples by Category

🏗️ Advanced Architecture & Intelligence

Leverage Cost Katana's AI-native architecture with autonomous optimization and self-improving systems.

Feature Description Examples
Provider-Independent Core Capability-based routing, zero vendor lock-in Guide, Patterns
AI Governance & Security Zero-trust agent governance with RBAC HTTP, TypeScript, Python
Data Network Effects Self-improving AI with learning loops HTTP, TypeScript, Python

Key Benefits:

  • AI-Native Architecture - Platform designed from ground up with AI models as first-class infrastructure
  • Autonomous Optimization - Hands-free cost reduction with intelligent interventions
  • Self-Improving - System gets smarter with every user interaction
  • Enterprise Security - Zero-trust governance with comprehensive auditing

💰 Cost Management

Track and optimize your AI spending with comprehensive cost management tools.

Feature Description Examples
Cost Tracking Monitor costs across all AI providers HTTP, TypeScript, Python
Analytics Analyze spending patterns and trends HTTP, TypeScript, Python
Budgets Set spending limits and alerts HTTP, TypeScript, Python
Cost Optimization AI-powered cost reduction recommendations HTTP, TypeScript, Python

Expected Savings: 30-80% cost reduction through optimization


🚀 Performance & Optimization

Boost performance and reduce costs with intelligent caching and optimization.

Feature Description Examples
Semantic Caching Cache similar requests (30-40% savings) HTTP, TypeScript, Python, Frameworks
Cortex Optimization AI-powered prompt compression HTTP, TypeScript, Python
Model Routing Route to optimal models automatically HTTP, TypeScript, Python
Failover Auto-failover between providers HTTP, TypeScript, Python

Performance Gains: 3-10x faster responses with caching


🔔 Monitoring & Alerts

Stay informed with real-time notifications and comprehensive monitoring.

Feature Description Examples
Webhooks Real-time event notifications (65+ events) HTTP, TypeScript, Python, Frameworks
OpenTelemetry Distributed tracing & metrics HTTP, TypeScript, Python, Frameworks
Monitoring System health & performance HTTP, TypeScript, Python
Alerts Custom alert rules HTTP, TypeScript, Python
Email Tracking Automated email notifications HTTP, TypeScript, Python

Coverage: 65+ webhook event types available


🤖 AI Orchestration

Build complex AI workflows and multi-agent systems.

Feature Description Examples
Agent Trace Monitor and optimize agent traces HTTP, TypeScript, Python, FastAPI
Agents AI agent management HTTP, TypeScript, Python
Memory Persistent agent context HTTP, TypeScript, Python
Templates Reusable prompt templates HTTP, TypeScript, Python

Capabilities: Parallel execution, conditional branching, error handling


🔒 Security & Compliance

Protect your AI applications with built-in security features.

Feature Description Examples
Key Vault Secure API key management HTTP, TypeScript, Python
Guardrails Content moderation & PII detection HTTP, TypeScript, Python
Security Threat detection & scanning HTTP, TypeScript, Python
MFA Multi-factor authentication HTTP, TypeScript, Python
Audit Logs Complete audit trail HTTP, TypeScript, Python

Protection: PII detection, toxicity filtering, prompt injection defense


🔧 Developer Tools

Essential tools for development and testing.

Feature Description Examples
Gateway Unified API for all providers HTTP, TypeScript, Python
CLI Command-line interface Shell scripts, Guides
Python SDK Complete Python package Python examples
CKQL SQL-like query language HTTP, TypeScript, Python
Notebooks Interactive analysis HTTP, TypeScript, Python

📊 Analytics & Reporting

Comprehensive analytics and automated reporting.

Feature Description Examples
Reports Automated report generation HTTP, TypeScript, Python
Feedback Request quality ratings HTTP, TypeScript, Python
Tagging Custom request tagging HTTP, TypeScript, Python
Experiments A/B testing & comparison HTTP, TypeScript, Python
AI Cost Monitoring Real-time cost tracking HTTP, TypeScript, Python

👥 Team & Organization

Collaborate effectively with team management features.

Feature Description Examples
Projects Project organization HTTP, TypeScript, Python
Team Management Team collaboration HTTP, TypeScript, Python
User Telemetry Usage analytics HTTP, TypeScript, Python
Rate Limiting API rate controls HTTP, TypeScript, Python

🔌 Integrations

Connect with your favorite tools and platforms.

Feature Description Examples
Integrations Third-party connections HTTP, TypeScript, Python
Ingestion Data import pipelines HTTP, TypeScript, Python
Express.js Express integration TypeScript
Next.js Next.js integration TypeScript
FastAPI FastAPI integration Python

Complete Feature List

All 44 features with direct links to examples:

📋 Click to expand full feature index

Core Features (1-9)

  1. Cost Tracking - Track AI costs across providers
  2. Gateway - Unified API gateway
  3. Optimization - General optimizations
  4. Cortex - Prompt optimization
  5. Analytics - Cost analytics
  6. Advanced - Advanced features
  7. Frameworks - Framework integrations
  8. Python SDK - Python examples
  9. CLI - Command-line interface

Infrastructure (10-17)

  1. Webhooks - Real-time notifications
  2. Observability - OpenTelemetry & tracing
  3. Guardrails - Content moderation
  4. Workflows - Multi-step orchestration
  5. Cache - Semantic caching
  6. Key Vault - Secure key management
  7. Security - Threat detection
  8. Monitoring - System health

Management (18-24)

  1. Projects - Project management
  2. Budgets - Budget tracking
  3. Memory - Agent memory
  4. Templates - Prompt templates
  5. Feedback - Request feedback
  6. Tagging - Custom tagging
  7. Experiments - A/B testing

Specialized Features (25-43)

  1. Notebooks - Interactive notebooks
  2. CKQL - Query language
  3. Agents - AI agents
  4. MFA - Multi-factor auth
  5. Moderation - Content moderation
  6. Cortex Training - Custom training
  7. Email Tracking - Email notifications
  8. AI Cost Monitoring - Real-time monitoring
  9. Ingestion - Data ingestion
  10. User Telemetry - Telemetry config
  11. Team Management - Team collaboration
  12. Audit Logs - Audit trail
  13. Rate Limiting - Rate controls
  14. Failover - Provider failover
  15. Model Routing - Intelligent routing
  16. Cost Optimization - Recommendations
  17. Alerts - Alert management
  18. Reports - Report generation
  19. Integrations - Third-party integrations

Framework Integration Examples

Express.js

import express from 'express';
import { CostKatana } from 'cost-katana';

const app = express();
const katana = new CostKatana({ apiKey: process.env.COST_KATANA_API_KEY });

app.post('/chat', async (req, res) => {
  const response = await katana.chat.completions.create({
    model: 'gpt-4',
    messages: req.body.messages
  });
  res.json({ 
    response: response.choices[0].message, 
    cost: response.cost 
  });
});

See: 7-frameworks/express/

Next.js API Route

// app/api/chat/route.ts
import { CostKatana } from 'cost-katana';

export async function POST(req: Request) {
  const katana = new CostKatana({ apiKey: process.env.COST_KATANA_API_KEY });
  const { messages } = await req.json();
  
  const response = await katana.chat.completions.create({
    model: 'gpt-4',
    messages
  });
  
  return Response.json({ response: response.choices[0].message });
}

See: 7-frameworks/nextjs/

FastAPI (Python)

from fastapi import FastAPI
from cost_katana import CostKatana

app = FastAPI()
katana = CostKatana(api_key=os.getenv("COST_KATANA_API_KEY"))

@app.post("/chat")
async def chat(messages: list):
    response = katana.chat.completions.create(
        model="gpt-4",
        messages=messages
    )
    return {"response": response.choices[0].message, "cost": response.cost}

See: 7-frameworks/ for all framework examples


Real-World Use Cases

Use Case 1: Multi-Agent Customer Support

Goal: Build a customer support system with multiple AI agents handling different tasks.

Features Used:

  • Agents - Create specialized agents
  • Workflows - Orchestrate agent interactions
  • Memory - Maintain conversation context
  • Webhooks - Get notified of escalations

Expected Results:

  • 24/7 automated support
  • 70% reduction in support costs
  • Context-aware responses

Use Case 2: Cost-Optimized Content Generation

Goal: Generate marketing content at scale while minimizing costs.

Features Used:

Expected Results:

  • 60-80% cost reduction
  • 10x content generation speed
  • $10K+ monthly savings

Use Case 3: Enterprise AI Platform

Goal: Build a secure, compliant AI platform for enterprise use.

Features Used:

Expected Results:

  • SOC 2 compliance ready
  • Zero security incidents
  • Full audit trail

ROI Calculator

Scenario: 1000 AI Requests/Day

Without Cost Katana:

1000 requests/day × $0.045/request = $45/day
Monthly: $1,350
Yearly: $16,425

With Cost Katana (Caching + Optimization):

1000 requests/day × 20% actual calls × $0.03/request = $6/day
Monthly: $180
Yearly: $2,190

SAVINGS: $14,235/year (87% reduction)

ROI Breakdown:

  • Semantic Caching: 70-80% hit rate = 70-80% cost savings
  • Cortex Optimization: 30-40% token reduction
  • Model Routing: 15-25% savings using optimal models
  • Failover: Prevent downtime costs

Best Practices

1. Security

// ✅ DO: Use environment variables
const apiKey = process.env.COST_KATANA_API_KEY;

// ❌ DON'T: Hardcode API keys
const apiKey = 'ck_live_abc123'; // NEVER DO THIS

2. Error Handling

try {
  const response = await katana.chat.completions.create({...});
} catch (error) {
  if (error.status === 429) {
    // Rate limiting - implement exponential backoff
    await exponentialBackoff();
  } else if (error.status === 500) {
    // Server error - try failover
    await failoverToBackupProvider();
  }
  // Log error for monitoring
  logger.error('AI request failed', { error, context });
}

3. Caching Strategy

// High-precision responses: Higher threshold
const critical = await katana.chat.completions.create({
  model: 'gpt-4',
  messages: [...],
  cache: { enabled: true, threshold: 0.95 } // 95% match required
});

// General queries: Lower threshold
const general = await katana.chat.completions.create({
  model: 'gpt-3.5-turbo',
  messages: [...],
  cache: { enabled: true, threshold: 0.80 } // 80% match OK
});

4. Monitoring

// Always track costs and performance
const response = await katana.chat.completions.create({...});

// Log metrics
logger.info('AI request completed', {
  cost: response.cost,
  tokens: response.usage.total_tokens,
  latency: response.latency,
  cached: response.cached,
  model: response.model
});

Repository Structure

costkatana-examples/
├── 1-cost-tracking/          # Track costs across providers
│   ├── http-headers/         # HTTP REST API examples
│   ├── npm-package/          # TypeScript/Node.js examples
│   ├── python-sdk/           # Python SDK examples
│   └── README.md             # Feature documentation
│
├── 10-webhooks/              # Real-time notifications
│   ├── http-headers/         # Webhook API examples
│   ├── npm-package/          # TypeScript webhook handlers
│   ├── python-sdk/           # Python webhook receivers
│   ├── frameworks/           # Express, Next.js, etc.
│   └── README.md             # Webhook guide
│
├── 14-cache/                 # Semantic caching
├── 13-workflows/             # AI orchestration
├── 27-agents/                # AI agents
└── ... (44 feature directories total)

Each feature directory contains:

  • README.md - Complete feature documentation
  • http-headers/ - Direct HTTP API examples
  • npm-package/ - TypeScript/Node.js SDK examples
  • python-sdk/ - Python SDK examples
  • frameworks/ - Framework-specific integrations (when applicable)

Supported Providers

Cost Katana works with all major AI providers:

  • OpenAI (GPT-4, GPT-3.5, DALL-E)
  • Anthropic (Claude 3 Opus/Sonnet/Haiku)
  • AWS Bedrock (All models)
  • Google AI (Gemini, PaLM)
  • Cohere (Command, Embed)
  • Azure OpenAI (All models)
  • DeepSeek (DeepSeek models)
  • Grok (Llama, Mixtral)
  • HuggingFace (Open models)
  • Ollama (Local models)
  • Replicate (All models)

300+ AI models supported across all providers.


Getting Help

Documentation

📚 Docs: docs.costkatana.com
🎓 Tutorials: docs.costkatana.com/tutorials
📖 API Reference: docs.costkatana.com/api

Community

💬 Discord: discord.gg/Wcwzw8wM
🐦 Twitter: @costkatana
🐙 GitHub: github.com/costkatana

Support

📧 Email: support@costkatana.com
🌐 Dashboard: costkatana.com/dashboard
📊 Status: status.costkatana.com


Contributing

We welcome contributions! Here's how to add your own examples:

  1. Fork this repository
  2. Create a feature branch (git checkout -b feature/my-example)
  3. Add your example following our structure:
    • Include HTTP, TypeScript, and Python versions
    • Add comprehensive README with use cases
    • Include error handling and best practices
    • Test with real API endpoints
  4. Commit your changes (git commit -m 'Add: My awesome example')
  5. Push to your branch (git push origin feature/my-example)
  6. Open a Pull Request

Code Quality Guidelines:

  • ✅ Production-ready code with error handling
  • ✅ Clear comments explaining the logic
  • ✅ Type safety (TypeScript) and type hints (Python)
  • ✅ Security best practices (no hardcoded keys)
  • ✅ Real-world use cases in README

License

This repository is licensed under the MIT License. See LICENSE for details.


Statistics

📊 Repository Metrics

Total Examples:     300+
Features Covered:   44
Languages:          TypeScript, Python, HTTP
Frameworks:         5 (Express, Next.js, Fastify, NestJS, FastAPI)
Lines of Code:      ~15,000+
Documentation:      50 comprehensive READMEs

Updated:            Weekly
Maintained by:      Cost Katana Team

🚀 Ready to Get Started?

Browse ExamplesGet API KeyRead DocsJoin Discord


Built with ❤️ by the Cost Katana Team

Making AI development simpler, faster, and more cost-effective

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published