TNSA API Python Client
A powerful, OpenAI-compatible Python SDK for TNSA NGen3 Pro and Lite Models.
Features
- 🚀 OpenAI-Compatible API - Familiar interface for easy migration
- ⚡ Async & Sync Support - Both synchronous and asynchronous clients
- 🌊 Streaming Responses - Real-time token streaming for interactive applications
- 🔧 Comprehensive Error Handling - Robust error handling with retry logic
- 📊 Usage Tracking - Built-in token counting and cost estimation
- 💬 Conversation Management - Automatic chat history and context management
- 🔒 Secure Authentication - API key management with environment variable support
- 📝 Type Safety - Full type hints for better IDE support
- 🎯 Framework Integration - Works seamlessly with FastAPI, Django, and more
Installation
pip install tnsa-api
Quick Start
from tnsa_api_v2 import TNSA
# Initialize the client
client = TNSA(api_key="your-api-key")
# List available models
models = client.models.list()
print("Available models:", [model.id for model in models])
# Create a chat completion
response = client.chat.completions.create(
model="NGen3.9-Pro",
messages=[
{"role": "user", "content": "Hello, how are you?"}
]
)
print(response.choices[0].message.content)
Streaming Example
# Streaming responses
stream = client.chat.completions.create(
model="NGen3.9-Lite",
messages=[{"role": "user", "content": "Tell me a story"}],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")
Async Usage
import asyncio
from tnsa_api_v2 import AsyncTNSA
async def main():
client = AsyncTNSA(api_key="your-api-key")
response = await client.chat.completions.acreate(
model="NGen3.9-Pro",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)
asyncio.run(main())
Configuration
The client can be configured using environment variables, configuration files, or direct parameters:
Environment Variables
export TNSA_API_KEY="your-api-key"
export TNSA_BASE_URL="https://api.tnsaai.com"
export TNSA_TIMEOUT=30.0
Configuration File (config.yaml)
api_key: "your-api-key"
base_url: "https://api.tnsaai.com"
timeout: 30.0
max_retries: 3
default_model: "NGen3.9-Pro"
Direct Parameters
client = TNSA(
api_key="your-api-key",
base_url="https://api.tnsaai.com",
timeout=30.0,
max_retries=3
)
Available Models
- NGen3.9-Pro - High-performance model for complex tasks
- NGen3.9-Lite - Fast, efficient model for general use
- NGen3-7B-0625 - Specialized model variant
- Farmvaidya-Bot - Agricultural domain-specific model
Error Handling
from tnsa_api_v2 import TNSAError, RateLimitError, AuthenticationError
try:
response = client.chat.completions.create(
model="NGen3.9-Pro",
messages=[{"role": "user", "content": "Hello!"}]
)
except AuthenticationError:
print("Invalid API key")
except RateLimitError:
print("Rate limit exceeded")
except TNSAError as e:
print(f"API error: {e}")
Documentation
For detailed documentation, examples, and API reference, visit: https://docs.tnsaai.com
Support
- 📧 Email: info@tnsaai.com
- 🐛 Issues: GitHub Issues
- 📖 Documentation: https://docs.tnsaai.com
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for tnsa-api 2.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tnsa_api-2.1.2.tar.gz | 41.5 kB | Without provenance | Details for tnsa_api-2.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tnsa_api-2.1.2-py3-none-any.whl | Python 3 | none | any | Details for tnsa_api-2.1.2-py3-none-any.whl |
Total release size: 92.2 kB
Release files / tnsa_api-2.1.2.tar.gz
| Download URL | tnsa_api-2.1.2.tar.gz |
|---|---|
| Size | 41.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1e5cc29226a4419cf9436c3cc28d1f7a12a11c582ba1e89bdc4e3d0299306940
|
|
BLAKE2b-256 checksum How to use checksums |
765976cafd2e11ad1892a00c484e66b7b97cc6c90a55e2a14b3ff3bc2df500f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Release files / tnsa_api-2.1.2-py3-none-any.whl
| Download URL | tnsa_api-2.1.2-py3-none-any.whl |
|---|---|
| Size | 50.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1bfa5a5c38df5991da1a63029d5e4a236a6bd0b035c134e14d28061ab7bde3b1
|
|
BLAKE2b-256 checksum How to use checksums |
0c7d095be0ac22c6c88ef9a9399ceda5be16e7d5d632bb2b2918827a55ca2ab1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Security for tnsa-api 2.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.