coeai - Professional Python Client for COE AI LLM API
Professional Python client for interacting with high-capacity multimodal Large Language Models hosted on the COE AI GPU cluster.
⚠️ Network Requirement: This API is only accessible from UPES's internal network (UPESNET). Ensure you are connected to UPES Wi-Fi to use this package.
The coeai package provides seamless LLM inference over the UPES local network, supporting both text-to-text and image-to-text operations with advanced streaming capabilities.
🚀 Quick Start
pip install coeai
from coeai import LLMinfer
# Initialize client (requires UPESNET connectivity)
llm = LLMinfer(api_key="your-api-key")
# Generate text
response = llm.generate(
model="qwen3.8",
prompt="Explain quantum computing in simple terms",
max_tokens=256
)
print(response)
✨ Features
| Feature | Description |
|---|---|
| Text Generation | Support for all available LLM models |
| Vision Models | Image-to-text with multimodal models |
| Streaming | Real-time response streaming |
| Error Handling | Comprehensive error messages with actionable guidance |
| File Management | Automatic cleanup of file handles |
| Logging | Optional debug logging for troubleshooting |
| Model Discovery | Programmatic model listing |
📋 Available Models
Get the latest list programmatically:
models = llm.list_models()
print(f"Available models: {', '.join(models)}")
Current models (as of November 2026):
| Model | Context window | Notes |
|---|---|---|
qwen3.8 |
256K tokens | Default choice for chat, coding and general tasks |
qwen3.8-1m |
1M tokens | Very long documents or codebases |
Both are the same Qwen3.8 27B model; only the context length differs. It is a reasoning model, so its thinking counts towards max_tokens. The default is 2048; avoid very small values.
Getting a key
Book a one-hour slot (the key works only during that hour), or request a 30-day persistent key (subject to approval) at https://coeai.ddn.upes.ac.in/api-access.
Use with the OpenAI SDK
The server is also OpenAI-compatible:
from openai import OpenAI
client = OpenAI(base_url="https://coeai.ddn.upes.ac.in/v1", api_key="your-api-key")
reply = client.chat.completions.create(model="qwen3.8", messages=[{"role": "user", "content": "Hi"}], max_tokens=2048)
print(reply.choices[0].message.content)
📖 Usage Examples
1. Basic Text Generation
from coeai import LLMinfer
llm = LLMinfer(api_key="your-api-key")
response = llm.generate(
model="qwen3.8",
prompt="Write a haiku about programming",
max_tokens=100,
temperature=0.8
)
print(response)
2. Streaming Response
response = llm.generate(
model="qwen3.8",
prompt="Explain the theory of relativity",
max_tokens=2048,
stream=True,
print_stream=True # Print as it generates
)
3. Single Image Analysis
response = llm.generate(
model="qwen3.8",
inference_type="image-to-text",
files=["/path/to/image.jpg"],
prompt="Describe this image in detail",
max_tokens=2048
)
print(response)
4. Multiple Image Comparison
response = llm.generate(
model="qwen3.8",
inference_type="image-to-text",
files=["/path/to/image1.jpg", "/path/to/image2.jpg"],
prompt="Compare these images and identify differences",
max_tokens=1024,
temperature=0.7
)
5. Custom Conversation
messages = [
{"role": "system", "content": [{"type": "text", "text": "You are a helpful coding assistant."}]},
{"role": "user", "content": [{"type": "text", "text": "Explain Python decorators"}]}
]
response = llm.generate(
model="qwen3.8",
messages=messages,
max_tokens=2048
)
6. Advanced Parameters
response = llm.generate(
model="qwen3.8",
prompt="Solve: What is 15! (factorial)?",
max_tokens=400,
temperature=0.1, # Lower = more deterministic
top_p=0.9 # Nucleus sampling
)
🔧 API Reference
LLMinfer Class
Initialization
LLMinfer(api_key: str, host: str = "https://coeai.ddn.upes.ac.in")
| Parameter | Type | Description | Default |
|---|---|---|---|
api_key |
str | Your COE AI API key (required) | - |
host |
str | API server URL | https://coeai.ddn.upes.ac.in |
Methods
generate()
generate(
model: str,
inference_type: str = "text-to-text",
prompt: Optional[str] = None,
messages: Optional[List[Dict]] = None,
files: Optional[List[str]] = None,
max_tokens: int = 2048,
temperature: float = 0.7,
top_p: float = 1.0,
context_window: Optional[int] = None, # deprecated, ignored
stream: bool = False,
print_stream: bool = True
) -> Dict
| Parameter | Type | Description |
|---|---|---|
model |
str | Model name (required) |
inference_type |
str | "text-to-text" or "image-to-text" |
prompt |
str | Text prompt (optional if messages provided) |
messages |
list | Custom conversation history |
files |
list | Image file paths for vision models |
max_tokens |
int | Maximum tokens to generate |
temperature |
float | Sampling temperature (0.0–2.0) |
top_p |
float | Nucleus sampling (0.0–1.0) |
context_window |
int | Deprecated and ignored (context is fixed per model) |
stream |
bool | Enable streaming response |
print_stream |
bool | Print stream to console |
Returns: Dictionary with API response
list_models()
list_models() -> List[str]
Returns list of all available model names.
🔑 Getting an API Key
Option 1: Web Dashboard (Recommended)
- Connect to UPESNET (UPES Wi-Fi)
- Visit https://coeai.ddn.upes.ac.in
- Sign in with your UPES credentials
- Generate an API key from the dashboard
Option 2: Email Request
Send an email to hpc-access@ddn.upes.ac.in from your UPES account:
Subject: API Key Request for COE AI LLM Access
Dear COE AI Team,
I am requesting access to the LLM API for my project work.
Project Details:
- Project Name: <Your Project>
- Description: <Brief description>
- Expected Usage: <How you'll use the API>
Name: <Your Name>
Email: <Your UPES Email>
Department: <Your Department>
Thank you!
Allow 2-3 business days for processing.
⚠️ Error Handling
The client provides detailed error messages:
from coeai import LLMinfer, AuthenticationError, ModelNotFoundError, InferenceError
llm = LLMinfer(api_key="your-key")
try:
response = llm.generate(
model="qwen3.8",
prompt="Hello world"
)
except AuthenticationError as e:
print(f"Auth failed: {e}")
except ModelNotFoundError as e:
print(f"Model not found: {e}")
except InferenceError as e:
print(f"Inference failed: {e}")
except FileNotFoundError as e:
print(f"Image file missing: {e}")
Common Errors
| Error | Cause | Solution |
|---|---|---|
AuthenticationError |
Invalid API key | Check key or get new one |
ModelNotFoundError |
Model doesn't exist | Use llm.list_models() to see available models |
InferenceError (429) |
Rate limit exceeded | Wait and retry |
FileNotFoundError |
Image path wrong | Verify file exists |
ConnectionError |
Can't reach server | Verify you're on UPESNET, check server status |
🔍 Troubleshooting
Enable Debug Logging
import logging
logging.basicConfig(level=logging.DEBUG)
from coeai import LLMinfer
llm = LLMinfer(api_key="your-key")
Check Package Version
import coeai
print(f"coeai version: {coeai.__version__}")
Test Connection
llm = LLMinfer(api_key="your-key")
try:
models = llm.list_models()
print(f"✅ Connected! Found {len(models)} models")
except Exception as e:
print(f"❌ Connection failed: {e}")
📊 Performance Tips
-
Model Selection
- Use
qwen3.8for everyday tasks - Use
qwen3.8-1mwhen your input is longer than ~200K tokens
- Use
-
Temperature Settings
- 0.1-0.3: Factual/technical content
- 0.7-0.9: Balanced creativity
- 1.0-2.0: Maximum creativity
-
Token Limits
- Set
max_tokensappropriately to balance quality and speed - Typical: 1024-2048 for most answers (reasoning counts towards the limit), more for long outputs
- Set
-
Streaming
- Enable
stream=Truefor long responses to see progress
- Enable
🔄 Migration from v2.x
Breaking Changes in v4.0.0
⚠️ Important: Requires UPESNET (UPES internal network) connectivity
Update Your Code:
Before (v2.x/v3.x):
llm = LLMinfer(api_key="key", host="http://coeai.ddn.upes.ac.in:8001") # Wrong port
After (v4.0.0):
# Correct - uses the default host
llm = LLMinfer(api_key="key")
# Or explicitly specify
llm = LLMinfer(api_key="key", host="https://coeai.ddn.upes.ac.in")
New Features in v4.0
- ✅ Automatic file handle cleanup
- ✅ Comprehensive error handling with custom exceptions
- ✅
list_models()method for model discovery - ✅ Debug logging support
- ✅ Relaxed vision model restrictions
- ✅ Version export (
coeai.__version__)
📜 Changelog
v4.0.0 (Current)
- BREAKING: Fixed default port from 8001 to 8000
- REQUIREMENT: Only accessible from UPES internal network (UPESNET)
- API Keys: Get your key from https://coeai.ddn.upes.ac.in
- Added
list_models()method - Improved error handling with custom exceptions
- Fixed file handle leaks
- Added logging support
- Relaxed vision model restrictions
- Added
__version__export - Updated documentation with current models
v2.3.0
- Production release with text-to-text and image-to-text support
- Streaming capabilities
- Multiple image processing
📄 License
Released under the MIT License. See LICENSE for details.
👥 Authors
Konal Puri & Sawai Pratap Khatri
Centre of Excellence: AI (COE AI), HPC Project, UPES
- PyPI: https://pypi.org/project/coeai
- GitHub: https://github.com/pkonal23/COE-AI-HPC-Project
- API Server: https://coeai.ddn.upes.ac.in (UPESNET only)
- Get API Key: https://coeai.ddn.upes.ac.in
🤝 Contributing
Contributions are welcome! Please feel free to submit issues or pull requests on GitHub.
📞 Support
For issues or questions:
- Open an issue on GitHub
- Contact:
hpc-access@ddn.upes.ac.in
Made with ❤️ at UPES Centre of Excellence: AI
Metadata
Release files for coeai 4.2.1
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 |
|---|---|---|---|---|
| coeai-4.2.1.tar.gz | 13.9 kB | Without provenance | Details for coeai-4.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| coeai-4.2.1-py3-none-any.whl | Python 3 | none | any | Details for coeai-4.2.1-py3-none-any.whl |
Total release size: 24.8 kB
Release files / coeai-4.2.1.tar.gz
| Download URL | coeai-4.2.1.tar.gz |
|---|---|
| Size | 13.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
735b666829ab917407c6bdcfc78060678a5df60ea7c5bb78691902b4dc367541
|
|
BLAKE2b-256 checksum How to use checksums |
e73ba102d3d595971654755d1b4b16096cd7b1f84f9552404b5de6ead2bd9caf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.1
|
Release files / coeai-4.2.1-py3-none-any.whl
| Download URL | coeai-4.2.1-py3-none-any.whl |
|---|---|
| Size | 10.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4a00125f1ea7709aecdd520a57bc032e5aac0eb467cd8acfd7a8face20232f92
|
|
BLAKE2b-256 checksum How to use checksums |
24c3cc019ed388aa297a9dbdd9f584226f0ae7f6793f83ee50b15d9545cf9c64
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.1
|
Security for coeai 4.2.1
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.