By TAU Group
Access Texas A&M University's AI services with just 2 lines of code, and use any of the provided LLMs for free! (Exclusive for Aggies)
This library is still in development and the API may be subject to change. You need to get your API key from chat.tamu.ai
- π Simple and intuitive usage
- π 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
pip install tamu-chatOr install from source:
git clone https://github.com/yourusername/tamu-chat.git
cd tamu-chat
pip install -e .from tamu_chat import TAMUChatClient
# Initialize client with API key (or add it to the .env file)
client = TAMUChatClient(api_key="sk-your-api-key-here")
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)
print(result.id)
print(result.full_response)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!
# Get a list of available models
models = client.list_models()
for model in models:
print(model['id'])
# Make sure to use this model id in 'model' parameter of chat_completion()
# 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."Main client class for interacting with the TAMU Chat API.
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.
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 available models from the API.
Returns:
- List of model dictionaries
Raises:
APIError: If API returns an errorAuthenticationError: If authentication fails
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
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}")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'])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)
- Python 3.11+
- requests
- python-dotenv
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.
MIT License
For issues and questions, please open an issue on GitHub.
If you see this error during installation via pip, please ignore or report it via issues.
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
conda-repo-cli 1.0.75 requires requests_mock, which is not installed.
anaconda-cloud-auth 0.1.4 requires pydantic<2.0, but you have pydantic 2.11.1 which is incompatible.
conda-repo-cli 1.0.75 requires clyent==1.2.1, but you have clyent 1.2.2 which is incompatible.
conda-repo-cli 1.0.75 requires requests==2.31.0, but you have requests 2.32.5 which is incompatible.
streamlit 1.30.0 requires cachetools<6,>=4.0, but you have cachetools 6.2.1 which is incompatible.
streamlit 1.30.0 requires packaging<24,>=16.8, but you have packaging 24.2 which is incompatible.
streamlit 1.30.0 requires protobuf<5,>=3.20, but you have protobuf 6.33.0 which is incompatible.- Dheeraj Mudireddy (meetdheerajreddy@gmail.com)
- Initial release
- Basic chat completion support
- Model listing support
- Custom exception handling
- Environment variable configuration