tnsa-api


Nametnsa-api JSON
Version 2.1.2 PyPI version JSON
download
home_pagehttps://www.tnsaai.com
SummaryA powerful, OpenAI-compatible Python SDK for TNSA NGen3 Pro and Lite Models
upload_time2025-09-13 05:56:38
maintainerNone
docs_urlNone
authorTNSA AI
requires_python>=3.8
licenseMIT
keywords ai api tnsa ngen3 llm chat completion
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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

```bash
pip install tnsa-api
```

## Quick Start

```python
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

```python
# 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

```python
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

```bash
export TNSA_API_KEY="your-api-key"
export TNSA_BASE_URL="https://api.tnsaai.com"
export TNSA_TIMEOUT=30.0
```

### Configuration File (config.yaml)

```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

```python
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

```python
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](https://docs.tnsaai.com)

## Support

- 📧 Email: info@tnsaai.com
- 🐛 Issues: [GitHub Issues](https://github.com/tnsaai/tnsa-api-python/issues)
- 📖 Documentation: [https://docs.tnsaai.com](https://docs.tnsaai.com)

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

            

Raw data

            {
    "_id": null,
    "home_page": "https://www.tnsaai.com",
    "name": "tnsa-api",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "TNSA AI <info@tnsaai.com>",
    "keywords": "ai, api, tnsa, ngen3, llm, chat, completion",
    "author": "TNSA AI",
    "author_email": "TNSA AI <info@tnsaai.com>",
    "download_url": "https://files.pythonhosted.org/packages/76/59/76cafd2e11ad1892a00c484e66b7b97cc6c90a55e2a14b3ff3bc2df500f9/tnsa_api-2.1.2.tar.gz",
    "platform": null,
    "description": "# TNSA API Python Client\r\n\r\nA powerful, OpenAI-compatible Python SDK for TNSA NGen3 Pro and Lite Models.\r\n\r\n## Features\r\n\r\n- \ud83d\ude80 **OpenAI-Compatible API** - Familiar interface for easy migration\r\n- \u26a1 **Async & Sync Support** - Both synchronous and asynchronous clients\r\n- \ud83c\udf0a **Streaming Responses** - Real-time token streaming for interactive applications\r\n- \ud83d\udd27 **Comprehensive Error Handling** - Robust error handling with retry logic\r\n- \ud83d\udcca **Usage Tracking** - Built-in token counting and cost estimation\r\n- \ud83d\udcac **Conversation Management** - Automatic chat history and context management\r\n- \ud83d\udd12 **Secure Authentication** - API key management with environment variable support\r\n- \ud83d\udcdd **Type Safety** - Full type hints for better IDE support\r\n- \ud83c\udfaf **Framework Integration** - Works seamlessly with FastAPI, Django, and more\r\n\r\n## Installation\r\n\r\n```bash\r\npip install tnsa-api\r\n```\r\n\r\n## Quick Start\r\n\r\n```python\r\nfrom tnsa_api_v2 import TNSA\r\n\r\n# Initialize the client\r\nclient = TNSA(api_key=\"your-api-key\")\r\n\r\n# List available models\r\nmodels = client.models.list()\r\nprint(\"Available models:\", [model.id for model in models])\r\n\r\n# Create a chat completion\r\nresponse = client.chat.completions.create(\r\n    model=\"NGen3.9-Pro\",\r\n    messages=[\r\n        {\"role\": \"user\", \"content\": \"Hello, how are you?\"}\r\n    ]\r\n)\r\n\r\nprint(response.choices[0].message.content)\r\n```\r\n\r\n## Streaming Example\r\n\r\n```python\r\n# Streaming responses\r\nstream = client.chat.completions.create(\r\n    model=\"NGen3.9-Lite\",\r\n    messages=[{\"role\": \"user\", \"content\": \"Tell me a story\"}],\r\n    stream=True\r\n)\r\n\r\nfor chunk in stream:\r\n    if chunk.choices[0].delta.content:\r\n        print(chunk.choices[0].delta.content, end=\"\")\r\n```\r\n\r\n## Async Usage\r\n\r\n```python\r\nimport asyncio\r\nfrom tnsa_api_v2 import AsyncTNSA\r\n\r\nasync def main():\r\n    client = AsyncTNSA(api_key=\"your-api-key\")\r\n    \r\n    response = await client.chat.completions.acreate(\r\n        model=\"NGen3.9-Pro\",\r\n        messages=[{\"role\": \"user\", \"content\": \"Hello!\"}]\r\n    )\r\n    \r\n    print(response.choices[0].message.content)\r\n\r\nasyncio.run(main())\r\n```\r\n\r\n## Configuration\r\n\r\nThe client can be configured using environment variables, configuration files, or direct parameters:\r\n\r\n### Environment Variables\r\n\r\n```bash\r\nexport TNSA_API_KEY=\"your-api-key\"\r\nexport TNSA_BASE_URL=\"https://api.tnsaai.com\"\r\nexport TNSA_TIMEOUT=30.0\r\n```\r\n\r\n### Configuration File (config.yaml)\r\n\r\n```yaml\r\napi_key: \"your-api-key\"\r\nbase_url: \"https://api.tnsaai.com\"\r\ntimeout: 30.0\r\nmax_retries: 3\r\ndefault_model: \"NGen3.9-Pro\"\r\n```\r\n\r\n### Direct Parameters\r\n\r\n```python\r\nclient = TNSA(\r\n    api_key=\"your-api-key\",\r\n    base_url=\"https://api.tnsaai.com\",\r\n    timeout=30.0,\r\n    max_retries=3\r\n)\r\n```\r\n\r\n## Available Models\r\n\r\n- **NGen3.9-Pro** - High-performance model for complex tasks\r\n- **NGen3.9-Lite** - Fast, efficient model for general use\r\n- **NGen3-7B-0625** - Specialized model variant\r\n- **Farmvaidya-Bot** - Agricultural domain-specific model\r\n\r\n## Error Handling\r\n\r\n```python\r\nfrom tnsa_api_v2 import TNSAError, RateLimitError, AuthenticationError\r\n\r\ntry:\r\n    response = client.chat.completions.create(\r\n        model=\"NGen3.9-Pro\",\r\n        messages=[{\"role\": \"user\", \"content\": \"Hello!\"}]\r\n    )\r\nexcept AuthenticationError:\r\n    print(\"Invalid API key\")\r\nexcept RateLimitError:\r\n    print(\"Rate limit exceeded\")\r\nexcept TNSAError as e:\r\n    print(f\"API error: {e}\")\r\n```\r\n\r\n## Documentation\r\n\r\nFor detailed documentation, examples, and API reference, visit: [https://docs.tnsaai.com](https://docs.tnsaai.com)\r\n\r\n## Support\r\n\r\n- \ud83d\udce7 Email: info@tnsaai.com\r\n- \ud83d\udc1b Issues: [GitHub Issues](https://github.com/tnsaai/tnsa-api-python/issues)\r\n- \ud83d\udcd6 Documentation: [https://docs.tnsaai.com](https://docs.tnsaai.com)\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A powerful, OpenAI-compatible Python SDK for TNSA NGen3 Pro and Lite Models",
    "version": "2.1.2",
    "project_urls": {
        "Bug Tracker": "https://github.com/tnsaai/tnsa-api-python/issues",
        "Documentation": "https://docs.tnsaai.com",
        "Homepage": "https://www.tnsaai.com",
        "Repository": "https://github.com/tnsaai/tnsa-api-python"
    },
    "split_keywords": [
        "ai",
        " api",
        " tnsa",
        " ngen3",
        " llm",
        " chat",
        " completion"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "0c7d095be0ac22c6c88ef9a9399ceda5be16e7d5d632bb2b2918827a55ca2ab1",
                "md5": "3ad6f61e91726442710c43f2a785f2ba",
                "sha256": "1bfa5a5c38df5991da1a63029d5e4a236a6bd0b035c134e14d28061ab7bde3b1"
            },
            "downloads": -1,
            "filename": "tnsa_api-2.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3ad6f61e91726442710c43f2a785f2ba",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 50685,
            "upload_time": "2025-09-13T05:56:37",
            "upload_time_iso_8601": "2025-09-13T05:56:37.102393Z",
            "url": "https://files.pythonhosted.org/packages/0c/7d/095be0ac22c6c88ef9a9399ceda5be16e7d5d632bb2b2918827a55ca2ab1/tnsa_api-2.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "765976cafd2e11ad1892a00c484e66b7b97cc6c90a55e2a14b3ff3bc2df500f9",
                "md5": "9708dbadf8c8bd77f07c2c3d1b757631",
                "sha256": "1e5cc29226a4419cf9436c3cc28d1f7a12a11c582ba1e89bdc4e3d0299306940"
            },
            "downloads": -1,
            "filename": "tnsa_api-2.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "9708dbadf8c8bd77f07c2c3d1b757631",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 41523,
            "upload_time": "2025-09-13T05:56:38",
            "upload_time_iso_8601": "2025-09-13T05:56:38.688548Z",
            "url": "https://files.pythonhosted.org/packages/76/59/76cafd2e11ad1892a00c484e66b7b97cc6c90a55e2a14b3ff3bc2df500f9/tnsa_api-2.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-09-13 05:56:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "tnsaai",
    "github_project": "tnsa-api-python",
    "github_not_found": true,
    "lcname": "tnsa-api"
}
        
Elapsed time: 2.06988s