cost-katana 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Cost Katana
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,21 @@
1
+ # Include important files in the package distribution
2
+
3
+ include README.md
4
+ include LICENSE
5
+ include requirements.txt
6
+ include requirements-dev.txt
7
+
8
+ # Include examples
9
+ recursive-include examples *.py *.json
10
+
11
+ # Include documentation
12
+ recursive-include docs *.md *.rst *.txt
13
+
14
+ # Exclude development and test files
15
+ exclude Makefile
16
+ exclude .gitignore
17
+ exclude *.pyc
18
+ exclude .pytest_cache
19
+ recursive-exclude * __pycache__
20
+ recursive-exclude * *.py[co]
21
+ recursive-exclude tests *
@@ -0,0 +1,425 @@
1
+ Metadata-Version: 2.4
2
+ Name: cost-katana
3
+ Version: 1.0.0
4
+ Summary: Unified AI interface with cost optimization and failover
5
+ Home-page: https://github.com/your-org/cost-katana-python
6
+ Author: Cost Katana Team
7
+ Author-email: support@costkatana.com
8
+ Project-URL: Bug Reports, https://github.com/your-org/cost-katana-python/issues
9
+ Project-URL: Source, https://github.com/your-org/cost-katana-python
10
+ Project-URL: Documentation, https://docs.costkatana.com
11
+ Keywords: ai,machine learning,cost optimization,openai,anthropic,aws bedrock,gemini
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.8
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
24
+ Requires-Python: >=3.8
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Requires-Dist: requests>=2.28.0
28
+ Requires-Dist: httpx>=0.24.0
29
+ Requires-Dist: typing-extensions>=4.0.0
30
+ Requires-Dist: pydantic>=2.0.0
31
+ Requires-Dist: python-dotenv>=0.19.0
32
+ Requires-Dist: rich>=12.0.0
33
+ Dynamic: author
34
+ Dynamic: author-email
35
+ Dynamic: classifier
36
+ Dynamic: description
37
+ Dynamic: description-content-type
38
+ Dynamic: home-page
39
+ Dynamic: keywords
40
+ Dynamic: license-file
41
+ Dynamic: project-url
42
+ Dynamic: requires-dist
43
+ Dynamic: requires-python
44
+ Dynamic: summary
45
+
46
+ # Cost Katana Python SDK
47
+
48
+ A simple, unified interface for AI models with built-in cost optimization, failover, and analytics. Use any AI provider through one consistent API - no need to manage API keys or worry about provider-specific implementations!
49
+
50
+ ## 🚀 Quick Start
51
+
52
+ ### Installation
53
+
54
+ ```bash
55
+ pip install cost-katana
56
+ ```
57
+
58
+ ### Get Your API Key
59
+
60
+ 1. Visit [Cost Katana Dashboard](https://costkatana.com/dashboard)
61
+ 2. Create an account or sign in
62
+ 3. Go to API Keys section
63
+ 4. Generate a new API key (starts with `dak_`)
64
+
65
+ ### Basic Usage
66
+
67
+ ```python
68
+ import cost_katana as ck
69
+
70
+ # Configure once with your API key
71
+ ck.configure(api_key='dak_your_key_here')
72
+
73
+ # Use any AI model with the same simple interface
74
+ model = ck.GenerativeModel('nova-lite')
75
+ response = model.generate_content("Explain quantum computing in simple terms")
76
+ print(response.text)
77
+ print(f"Cost: ${response.usage_metadata.cost:.4f}")
78
+ ```
79
+
80
+ ### Chat Sessions
81
+
82
+ ```python
83
+ import cost_katana as ck
84
+
85
+ ck.configure(api_key='dak_your_key_here')
86
+
87
+ # Start a conversation
88
+ model = ck.GenerativeModel('claude-3-sonnet')
89
+ chat = model.start_chat()
90
+
91
+ # Send messages back and forth
92
+ response1 = chat.send_message("Hello! What's your name?")
93
+ print("AI:", response1.text)
94
+
95
+ response2 = chat.send_message("Can you help me write a Python function?")
96
+ print("AI:", response2.text)
97
+
98
+ # Get total conversation cost
99
+ total_cost = sum(msg.get('metadata', {}).get('cost', 0) for msg in chat.history)
100
+ print(f"Total conversation cost: ${total_cost:.4f}")
101
+ ```
102
+
103
+ ## 🎯 Why Cost Katana?
104
+
105
+ ### Simple Interface, Powerful Backend
106
+ - **One API for all providers**: Use Google Gemini, Anthropic Claude, OpenAI GPT, AWS Bedrock models through one interface
107
+ - **No API key juggling**: Store your provider keys securely in Cost Katana, use one key in your code
108
+ - **Automatic failover**: If one provider is down, automatically switch to alternatives
109
+ - **Cost optimization**: Intelligent routing to minimize costs while maintaining quality
110
+
111
+ ### Enterprise Features
112
+ - **Cost tracking**: Real-time cost monitoring and budgets
113
+ - **Usage analytics**: Detailed insights into model performance and usage patterns
114
+ - **Team management**: Share projects and manage API usage across teams
115
+ - **Approval workflows**: Set spending limits with approval requirements
116
+
117
+ ## 📚 Configuration Options
118
+
119
+ ### Using Configuration File (Recommended)
120
+
121
+ Create `config.json`:
122
+
123
+ ```json
124
+ {
125
+ "api_key": "dak_your_key_here",
126
+ "default_model": "gemini-2.0-flash",
127
+ "default_temperature": 0.7,
128
+ "cost_limit_per_day": 50.0,
129
+ "enable_optimization": true,
130
+ "enable_failover": true,
131
+ "model_mappings": {
132
+ "gemini": "gemini-2.0-flash-exp",
133
+ "claude": "anthropic.claude-3-sonnet-20240229-v1:0",
134
+ "gpt4": "gpt-4-turbo-preview"
135
+ },
136
+ "providers": {
137
+ "google": {
138
+ "priority": 1,
139
+ "models": ["gemini-2.0-flash", "gemini-pro"]
140
+ },
141
+ "anthropic": {
142
+ "priority": 2,
143
+ "models": ["claude-3-sonnet", "claude-3-haiku"]
144
+ }
145
+ }
146
+ }
147
+ ```
148
+
149
+ ```python
150
+ import cost_katana as ck
151
+
152
+ # Configure from file
153
+ ck.configure(config_file='config.json')
154
+
155
+ # Now use any model
156
+ model = ck.GenerativeModel('gemini') # Uses mapping from config
157
+ ```
158
+
159
+ ### Environment Variables
160
+
161
+ ```bash
162
+ export COST_KATANA_API_KEY=dak_your_key_here
163
+ export COST_KATANA_DEFAULT_MODEL=claude-3-sonnet
164
+ ```
165
+
166
+ ```python
167
+ import cost_katana as ck
168
+
169
+ # Automatically loads from environment
170
+ ck.configure()
171
+
172
+ model = ck.GenerativeModel() # Uses default model from env
173
+ ```
174
+
175
+ ## 🤖 Supported Models
176
+
177
+ ### Amazon Nova Models (Primary Recommendation)
178
+ - `nova-micro` - Ultra-fast and cost-effective for simple tasks
179
+ - `nova-lite` - Balanced performance and cost for general use
180
+ - `nova-pro` - High-performance model for complex tasks
181
+
182
+ ### Anthropic Claude Models
183
+ - `claude-3-haiku` - Fast and cost-effective responses
184
+ - `claude-3-sonnet` - Balanced performance for complex tasks
185
+ - `claude-3-opus` - Most capable Claude model for advanced reasoning
186
+ - `claude-3.5-haiku` - Latest fast model with enhanced capabilities
187
+ - `claude-3.5-sonnet` - Advanced reasoning and analysis
188
+
189
+ ### Meta Llama Models
190
+ - `llama-3.1-8b` - Good balance of performance and efficiency
191
+ - `llama-3.1-70b` - Large model for complex reasoning
192
+ - `llama-3.1-405b` - Most capable Llama model
193
+ - `llama-3.2-1b` - Compact and efficient
194
+ - `llama-3.2-3b` - Efficient for general tasks
195
+
196
+ ### Mistral Models
197
+ - `mistral-7b` - Efficient open-source model
198
+ - `mixtral-8x7b` - High-quality mixture of experts
199
+ - `mistral-large` - Advanced reasoning capabilities
200
+
201
+ ### Cohere Models
202
+ - `command` - General purpose text generation
203
+ - `command-light` - Lighter, faster version
204
+ - `command-r` - Retrieval-augmented generation
205
+ - `command-r-plus` - Enhanced RAG with better reasoning
206
+
207
+ ### Friendly Aliases
208
+ - `fast` → Nova Micro (optimized for speed)
209
+ - `balanced` → Nova Lite (balanced cost/performance)
210
+ - `powerful` → Nova Pro (maximum capabilities)
211
+
212
+ ## ⚙️ Advanced Usage
213
+
214
+ ### Generation Configuration
215
+
216
+ ```python
217
+ from cost_katana import GenerativeModel, GenerationConfig
218
+
219
+ config = GenerationConfig(
220
+ temperature=0.3,
221
+ max_output_tokens=1000,
222
+ top_p=0.9
223
+ )
224
+
225
+ model = GenerativeModel('claude-3-sonnet', generation_config=config)
226
+ response = model.generate_content("Write a haiku about programming")
227
+ ```
228
+
229
+ ### Multi-Agent Processing
230
+
231
+ ```python
232
+ # Enable multi-agent processing for complex queries
233
+ model = GenerativeModel('gemini-2.0-flash')
234
+ response = model.generate_content(
235
+ "Analyze the economic impact of AI on job markets",
236
+ use_multi_agent=True,
237
+ chat_mode='balanced'
238
+ )
239
+
240
+ # See which agents were involved
241
+ print("Agent path:", response.usage_metadata.agent_path)
242
+ print("Optimizations applied:", response.usage_metadata.optimizations_applied)
243
+ ```
244
+
245
+ ### Cost Optimization Modes
246
+
247
+ ```python
248
+ # Different optimization strategies
249
+ fast_response = model.generate_content(
250
+ "Quick summary of today's news",
251
+ chat_mode='fastest' # Prioritize speed
252
+ )
253
+
254
+ cheap_response = model.generate_content(
255
+ "Detailed analysis of market trends",
256
+ chat_mode='cheapest' # Prioritize cost
257
+ )
258
+
259
+ balanced_response = model.generate_content(
260
+ "Help me debug this Python code",
261
+ chat_mode='balanced' # Balance speed and cost
262
+ )
263
+ ```
264
+
265
+ ## 🖥️ Command Line Interface
266
+
267
+ Cost Katana includes a CLI for easy interaction:
268
+
269
+ ```bash
270
+ # Initialize configuration
271
+ cost-katana init
272
+
273
+ # Test your setup
274
+ cost-katana test
275
+
276
+ # List available models
277
+ cost-katana models
278
+
279
+ # Start interactive chat
280
+ cost-katana chat --model gemini-2.0-flash
281
+
282
+ # Use specific config file
283
+ cost-katana chat --config my-config.json
284
+ ```
285
+
286
+ ## 📊 Usage Analytics
287
+
288
+ Track your AI usage and costs:
289
+
290
+ ```python
291
+ import cost_katana as ck
292
+
293
+ ck.configure(config_file='config.json')
294
+
295
+ model = ck.GenerativeModel('claude-3-sonnet')
296
+ response = model.generate_content("Explain machine learning")
297
+
298
+ # Detailed usage information
299
+ metadata = response.usage_metadata
300
+ print(f"Model used: {metadata.model}")
301
+ print(f"Cost: ${metadata.cost:.4f}")
302
+ print(f"Latency: {metadata.latency:.2f}s")
303
+ print(f"Tokens: {metadata.total_tokens}")
304
+ print(f"Cache hit: {metadata.cache_hit}")
305
+ print(f"Risk level: {metadata.risk_level}")
306
+ ```
307
+
308
+ ## 🔧 Error Handling
309
+
310
+ ```python
311
+ from cost_katana import GenerativeModel
312
+ from cost_katana.exceptions import (
313
+ CostLimitExceededError,
314
+ ModelNotAvailableError,
315
+ RateLimitError
316
+ )
317
+
318
+ try:
319
+ model = GenerativeModel('expensive-model')
320
+ response = model.generate_content("Complex analysis task")
321
+
322
+ except CostLimitExceededError:
323
+ print("Cost limit reached! Check your budget settings.")
324
+
325
+ except ModelNotAvailableError:
326
+ print("Model is currently unavailable. Trying fallback...")
327
+ model = GenerativeModel('backup-model')
328
+ response = model.generate_content("Complex analysis task")
329
+
330
+ except RateLimitError:
331
+ print("Rate limit hit. Please wait before retrying.")
332
+ ```
333
+
334
+ ## 🌟 Comparison with Direct Provider SDKs
335
+
336
+ ### Before (Google Gemini)
337
+ ```python
338
+ import google.generativeai as genai
339
+
340
+ # Need to manage API key
341
+ genai.configure(api_key="your-google-api-key")
342
+
343
+ # Provider-specific code
344
+ model = genai.GenerativeModel('gemini-2.0-flash')
345
+ response = model.generate_content("Hello")
346
+
347
+ # No cost tracking, no failover, provider lock-in
348
+ ```
349
+
350
+ ### After (Cost Katana)
351
+ ```python
352
+ import cost_katana as ck
353
+
354
+ # One API key for all providers
355
+ ck.configure(api_key='dak_your_key_here')
356
+
357
+ # Same interface, any provider
358
+ model = ck.GenerativeModel('nova-lite')
359
+ response = model.generate_content("Hello")
360
+
361
+ # Built-in cost tracking, failover, optimization
362
+ print(f"Cost: ${response.usage_metadata.cost:.4f}")
363
+ ```
364
+
365
+ ## 🏢 Enterprise Features
366
+
367
+ - **Team Management**: Share configurations across team members
368
+ - **Cost Centers**: Track usage by project or department
369
+ - **Approval Workflows**: Require approval for high-cost operations
370
+ - **Analytics Dashboard**: Web interface for usage insights
371
+ - **Custom Models**: Support for fine-tuned and custom models
372
+ - **SLA Monitoring**: Track model availability and performance
373
+
374
+ ## 🔒 Security & Privacy
375
+
376
+ - **Secure Key Storage**: API keys encrypted at rest
377
+ - **No Data Retention**: Your prompts and responses are not stored
378
+ - **Audit Logs**: Complete audit trail of API usage
379
+ - **GDPR Compliant**: Full compliance with data protection regulations
380
+
381
+ ## 📖 API Reference
382
+
383
+ ### GenerativeModel
384
+
385
+ ```python
386
+ class GenerativeModel:
387
+ def __init__(self, model_name: str, generation_config: GenerationConfig = None)
388
+ def generate_content(self, prompt: str, **kwargs) -> GenerateContentResponse
389
+ def start_chat(self, history: List = None) -> ChatSession
390
+ def count_tokens(self, prompt: str) -> Dict[str, int]
391
+ ```
392
+
393
+ ### ChatSession
394
+
395
+ ```python
396
+ class ChatSession:
397
+ def send_message(self, message: str, **kwargs) -> GenerateContentResponse
398
+ def get_history(self) -> List[Dict]
399
+ def clear_history(self) -> None
400
+ def delete_conversation(self) -> None
401
+ ```
402
+
403
+ ### GenerateContentResponse
404
+
405
+ ```python
406
+ class GenerateContentResponse:
407
+ text: str # Generated text
408
+ usage_metadata: UsageMetadata # Cost, tokens, latency info
409
+ thinking: Dict # AI reasoning (if available)
410
+ ```
411
+
412
+ ## 🤝 Support
413
+
414
+ - **Documentation**: [docs.costkatana.com](https://docs.costkatana.com)
415
+ - **Discord Community**: [discord.gg/costkatana](https://discord.gg/costkatana)
416
+ - **Email Support**: support@costkatana.com
417
+ - **GitHub Issues**: [github.com/cost-katana/python-sdk](https://github.com/cost-katana/python-sdk)
418
+
419
+ ## 📄 License
420
+
421
+ MIT License - see [LICENSE](LICENSE) for details.
422
+
423
+ ---
424
+
425
+ **Ready to optimize your AI costs?** Get started at [costkatana.com](https://costkatana.com) 🚀