Get started in 3 simple steps!
pip install costkatanaPackage Name:
costkatana(Python/PyPI) vscost-katana(JavaScript/NPM)
Visit costkatana.com/settings and copy your API key (starts with dak_)
import cost_katana as ck
# Just works if you have API key in environment
response = ck.ai('gpt-4', 'Hello, world!')
print(response.text)
print(f"Cost: ${response.cost}")import cost_katana as ck
# Configure once at the start
ck.configure(api_key='dak_your_key_here')
# Then use anywhere
response = ck.ai('gpt-4', 'Explain quantum computing')
print(response.text)import cost_katana as ck
chat = ck.chat('gpt-4')
chat.send('Hello!')
chat.send('What can you help with?')
chat.send('Tell me a joke')
print(f"Total cost: ${chat.total_cost}")import cost_katana as ck
models = ['gpt-4', 'gpt-3.5-turbo', 'claude-3-haiku']
prompt = 'Explain machine learning'
for model in models:
response = ck.ai(model, prompt)
print(f"{model}: ${response.cost:.4f}")import cost_katana as ck
# Cortex: 40-75% cost reduction
response = ck.ai('gpt-4', 'Write a comprehensive guide',
cortex=True)
print(f"Optimized: {response.optimized}")import cost_katana as ck
# First call - costs money
r1 = ck.ai('gpt-4', 'What is 2+2?', cache=True)
# Second call - free from cache
r2 = ck.ai('gpt-4', 'What is 2+2?', cache=True)
print(r2.cached) # Trueexport COST_KATANA_API_KEY="dak_your_key_here"Then in Python:
import cost_katana as ck
# Auto-detects from environment
response = ck.ai('gpt-4', 'Hello')Create config.json:
{
"api_key": "dak_your_key_here",
"default_model": "gpt-3.5-turbo",
"enable_cache": true,
"enable_cortex": true
}Then:
import cost_katana as ck
ck.configure(config_file='config.json')import cost_katana as ck
ck.configure(
api_key='dak_your_key_here',
cortex=True,
cache=True
)from fastapi import FastAPI
import cost_katana as ck
app = FastAPI()
@app.post("/api/chat")
async def chat(request: dict):
response = ck.ai('gpt-4', request['prompt'])
return {
'text': response.text,
'cost': response.cost
}from flask import Flask, request, jsonify
import cost_katana as ck
app = Flask(__name__)
@app.route('/api/chat', methods=['POST'])
def chat():
prompt = request.json['prompt']
response = ck.ai('gpt-4', prompt, cache=True)
return jsonify({
'text': response.text,
'cost': response.cost
})from django.http import JsonResponse
import cost_katana as ck
def chat_view(request):
prompt = request.POST.get('prompt')
response = ck.ai('gpt-4', prompt)
return JsonResponse({
'text': response.text,
'cost': response.cost
})# Use cheaper models for simple tasks
ck.ai('gpt-3.5-turbo', 'Simple question') # 10x cheaper
# Enable optimization for long content
ck.ai('gpt-4', 'Long article', cortex=True) # 40-75% savings
# Cache repeated queries
ck.ai('gpt-4', 'FAQ answer', cache=True) # Free on repeats# Control creativity
ck.ai('gpt-4', 'Story', temperature=1.5) # More creative
# Limit response length
ck.ai('gpt-4', 'Explain AI', max_tokens=100) # Short answer
# Use system prompts
ck.ai('gpt-4', 'Question',
system_message='You are an expert')The Python package includes a CLI command:
# After installing costkatana
pip install costkatana
# Python CLI command
costkatana chat
costkatana ask "What is Python?"Or use the NPM global CLI (more features):
# Install NPM CLI globally
npm install -g cost-katana-cli
# JavaScript CLI command
cost-katana chat
cost-katana ask "What is Python?"
cost-katana compare "Test" --models gpt-4,claude-3-sonnet| Provider | Models | Best For |
|---|---|---|
| OpenAI | gpt-4, gpt-3.5-turbo, gpt-4o | General purpose, function calling |
| Anthropic | claude-3-sonnet, claude-3-haiku | Analysis, coding, safety |
| gemini-pro, gemini-flash | Creative tasks, multimodal | |
| AWS | nova-pro, nova-lite | Enterprise, cost optimization |
- Documentation: https://docs.costkatana.com/python
- Examples: Check the
examples/folder - Discord: https://discord.gg/D8nDArmKbY
- Email: support@costkatana.com
- Dashboard: https://costkatana.com/dashboard
You're ready to use AI in Python! 🚀
import cost_katana as ck
response = ck.ai('gpt-4', 'Hello!')