A Python library for interacting with the TAMU Chat AI API
Project description
TAMU Chat API Python Library
A simple, clean Python library for interacting with the TAMU Chat API. This library provides an easy-to-use interface for generating chat completions using various LLM models.
Features
- 🚀 Simple and intuitive API
- 🔒 Secure API key management via environment variables
- 📦 Type hints throughout for better IDE support
- 🎯 Support for multiple models (o3, GPT-4, Claude, Gemini, etc.)
- 🔄 Handles both JSON and SSE streaming responses
- ⚡ Built-in error handling with custom exceptions
- 📝 Full response objects with easy access to text content
Installation
pip install tamu-chat
Or install from source:
git clone https://github.com/yourusername/tamu-chat.git
cd tamu-chat
pip install -e .
Quick Start
Basic Usage
from tamu_chat import TAMUChatClient
# Initialize client with API key
client = TAMUChatClient(api_key="sk-your-api-key-here")
# Simple string input
result = client.chat_completion("What is the capital of India?")
print(result.text)
# Output: "The capital of India is New Delhi."
# Access full response
print(result.model) # Model used
print(result.id) # Response ID
print(result.full_response) # Complete API response
Using Environment Variables
You can set the API key via environment variable or .env file:
Option 1: Environment Variable
import os
os.environ['TAMU_CHAT_API_KEY'] = 'sk-your-api-key-here'
from tamu_chat import TAMUChatClient
# API key will be automatically loaded from environment
client = TAMUChatClient()
Option 2: .env File (Recommended)
Create a .env file in your project root:
TAMU_CHAT_API_KEY=sk-your-api-key-here
TAMU_CHAT_BASE_URL=https://chat-api.tamu.ai/openai
Then use the client:
from tamu_chat import TAMUChatClient
# API key will be automatically loaded from .env file
client = TAMUChatClient()
Note: The library uses python-dotenv to automatically load .env files. Make sure to add .env to your .gitignore to keep your API key secure!
Advanced Usage
# Different model
result = client.chat_completion(
"Explain quantum computing",
model="protected.gpt-4o"
)
# With bypass filter
result = client.chat_completion(
"What is Python?",
bypass_filter=True
)
# Multi-turn conversation
messages = [
{"role": "user", "content": "My name is Alice."},
{"role": "assistant", "content": "Hello Alice! How can I help you?"},
{"role": "user", "content": "What's my name?"}
]
result = client.chat_completion(messages)
print(result.text) # "Your name is Alice."
# List available models
models = client.list_models()
for model in models:
print(model['id'])
API Reference
TAMUChatClient
Main client class for interacting with the TAMU Chat API.
__init__(api_key=None, base_url=None)
Initialize the client.
Parameters:
api_key(str, optional): API key for authentication. If not provided, will try to get fromTAMU_CHAT_API_KEYenvironment variable.base_url(str, optional): Base URL for the API. Defaults tohttps://chat-api.tamu.ai/openai.
Raises:
AuthenticationError: If API key is not provided and not found in environment.
chat_completion(messages, model="protected.o3", bypass_filter=False, stream=False)
Generate chat completion.
Parameters:
messages(str | List[Dict[str, str]]): String or list of message dictionaries with 'role' and 'content' keys.model(str): Model ID to use. Default:"protected.o3".bypass_filter(bool): Whether to bypass content filtering. Default:False.stream(bool): Whether to stream response. Default:False.
Returns:
- If
stream=False:ChatCompletionResponseobject - If
stream=True: Iterator of chunk dictionaries
Raises:
APIError: If API returns an errorAuthenticationError: If authentication failsInvalidModelError: If model is invalidNoResponseError: If no valid response receivedNetworkError: If network error occurs
list_models()
List available models from the API.
Returns:
- List of model dictionaries
Raises:
APIError: If API returns an errorAuthenticationError: If authentication fails
ChatCompletionResponse
Response object returned by chat_completion().
Attributes:
text(str): The actual response text contentfull_response(dict): Complete API response objectmodel(str): Model name usedid(str): Response ID
Error Handling
The library provides custom exceptions for better error handling:
from tamu_chat import (
TAMUChatClient,
APIError,
AuthenticationError,
InvalidModelError,
NetworkError
)
client = TAMUChatClient(api_key="sk-...")
try:
result = client.chat_completion("Hello")
except AuthenticationError:
print("Invalid API key")
except InvalidModelError:
print("Model not found")
except NetworkError:
print("Network error occurred")
except APIError as e:
print(f"API error: {e}")
Available Models
Common model IDs include:
protected.o3protected.gpt-4oprotected.gpt-4.1protected.gpt-5protected.Claude 3.5 Sonnetprotected.Claude Opus 4.1protected.gemini-2.0-flash
To get a complete list of available models:
models = client.list_models()
for model in models:
print(model['id'])
Configuration
Environment Variables
TAMU_CHAT_API_KEY: Your API key (required if not passed to constructor)TAMU_CHAT_BASE_URL: Base URL for the API (optional, defaults tohttps://chat-api.tamu.ai/openai)
Requirements
- Python 3.11+
- requests
- python-dotenv
Development
To contribute to this project:
- Clone the repository
- Install development dependencies:
pip install -e ".[dev]"
- Create a new branch in your forked repository for your changes.
git checkout -b <branch_name>
- Add code to the library and test it.
git add . git commit -m "Add <feature_name>" (Describe the changes you made)
- Run tests:
pytest tests/<test_file>.py - Test the library and raise a pull request.
git push forked-repository-name <branch_name>
- Wait for the pull request to be reviewed and merged.
License
MIT License
Support
For issues and questions, please open an issue on GitHub.
Creator
- Dheeraj Mudireddy (meetdheerajreddy@gmail.com)
Changelog
0.1.0 (2025-11-20)
- Initial release
- Basic chat completion support
- Model listing support
- Custom exception handling
- Environment variable configuration
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tamu_chat-0.1.0.tar.gz.
File metadata
- Download URL: tamu_chat-0.1.0.tar.gz
- Upload date:
- Size: 13.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ac3ccf4279da307eaef46d5dc814771949828853f036405f050e0b2e0a43a61
|
|
| MD5 |
4246621508b729dcff418275c1e72bf1
|
|
| BLAKE2b-256 |
eebb166f29ca3eea092a526084cc2e218a4a24a6c584500509bc347b8048bf1c
|
File details
Details for the file tamu_chat-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tamu_chat-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ecbd0e4b43059a9bcf5d065cb0b79ba01559f557a1e67ac17eee0837cfc65c4
|
|
| MD5 |
fd3f6503879f6373470d2575e37aba1e
|
|
| BLAKE2b-256 |
4a4cbfe9a61bc810e68c8dce15b1998bedb65928ce499a2a8b48fea52b9e1ffb
|