Production-ready examples for every Cost Katana feature
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
Sign up at costkatana.com/dashboard to get your API key.
TypeScript/Node.js:
npm install cost-katana
export COST_KATANA_API_KEY=your_key_here
npx ts-node 1-cost-tracking/npm-package/openai.tsPython:
pip install costkatana
export COST_KATANA_API_KEY=your_key_here
python 1-cost-tracking/python-sdk/openai.pyHTTP (REST Client):
- Install REST Client for VS Code
- Open any
.httpfile - Update the API key
- Click "Send Request"
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
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
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
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
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
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
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 |
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 |
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 |
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 |
All 44 features with direct links to examples:
📋 Click to expand full feature index
- Cost Tracking - Track AI costs across providers
- Gateway - Unified API gateway
- Optimization - General optimizations
- Cortex - Prompt optimization
- Analytics - Cost analytics
- Advanced - Advanced features
- Frameworks - Framework integrations
- Python SDK - Python examples
- CLI - Command-line interface
- Webhooks - Real-time notifications
- Observability - OpenTelemetry & tracing
- Guardrails - Content moderation
- Workflows - Multi-step orchestration
- Cache - Semantic caching
- Key Vault - Secure key management
- Security - Threat detection
- Monitoring - System health
- Projects - Project management
- Budgets - Budget tracking
- Memory - Agent memory
- Templates - Prompt templates
- Feedback - Request feedback
- Tagging - Custom tagging
- Experiments - A/B testing
- Notebooks - Interactive notebooks
- CKQL - Query language
- Agents - AI agents
- MFA - Multi-factor auth
- Moderation - Content moderation
- Cortex Training - Custom training
- Email Tracking - Email notifications
- AI Cost Monitoring - Real-time monitoring
- Ingestion - Data ingestion
- User Telemetry - Telemetry config
- Team Management - Team collaboration
- Audit Logs - Audit trail
- Rate Limiting - Rate controls
- Failover - Provider failover
- Model Routing - Intelligent routing
- Cost Optimization - Recommendations
- Alerts - Alert management
- Reports - Report generation
- Integrations - Third-party integrations
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
});
});// 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/
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
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
Goal: Generate marketing content at scale while minimizing costs.
Features Used:
- Cortex Optimization - Compress prompts
- Semantic Caching - Cache similar requests
- Model Routing - Use optimal models
- Cost Tracking - Monitor spending
Expected Results:
- 60-80% cost reduction
- 10x content generation speed
- $10K+ monthly savings
Goal: Build a secure, compliant AI platform for enterprise use.
Features Used:
- Key Vault - Secure key management
- Guardrails - Content moderation
- Audit Logs - Compliance tracking
- MFA - Enhanced security
- Team Management - Role-based access
Expected Results:
- SOC 2 compliance ready
- Zero security incidents
- Full audit trail
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
// ✅ DO: Use environment variables
const apiKey = process.env.COST_KATANA_API_KEY;
// ❌ DON'T: Hardcode API keys
const apiKey = 'ck_live_abc123'; // NEVER DO THIStry {
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 });
}// 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
});// 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
});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 documentationhttp-headers/- Direct HTTP API examplesnpm-package/- TypeScript/Node.js SDK examplespython-sdk/- Python SDK examplesframeworks/- Framework-specific integrations (when applicable)
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.
📚 Docs: docs.costkatana.com
🎓 Tutorials: docs.costkatana.com/tutorials
📖 API Reference: docs.costkatana.com/api
💬 Discord: discord.gg/Wcwzw8wM
🐦 Twitter: @costkatana
🐙 GitHub: github.com/costkatana
📧 Email: support@costkatana.com
🌐 Dashboard: costkatana.com/dashboard
📊 Status: status.costkatana.com
We welcome contributions! Here's how to add your own examples:
- Fork this repository
- Create a feature branch (
git checkout -b feature/my-example) - 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
- Commit your changes (
git commit -m 'Add: My awesome example') - Push to your branch (
git push origin feature/my-example) - 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
This repository is licensed under the MIT License. See LICENSE for details.
📊 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
Browse Examples • Get API Key • Read Docs • Join Discord
Built with ❤️ by the Cost Katana Team
Making AI development simpler, faster, and more cost-effective