Python client library for DeepAI Chat API
Project description
DeepAI Chat API Client
A powerful Python client library for interacting with DeepAI's Chat API. Supports multiple AI models, file attachments, session management, and conversation history.
🚀 Installation
pip install deepai-chat
Or install from source:
git clone https://github.com/your-username/deepai-chat.git
cd deepai-chat
pip install -e .
📖 Table of Contents
⚡ Quick Start
Guest Mode (No Login Required)
from deepai_api import DeepAIClient
# Create anonymous client - no account needed!
client = DeepAIClient.guest()
# Chat with AI
response = client.chat("Hello, how are you?")
print(response)
Login Mode (Full Features)
from deepai_api import DeepAIClient
# Login with your DeepAI account
client = DeepAIClient.login(
email="your@email.com",
password="yourpassword"
)
# Now you can save chat history
response = client.chat("Hello!")
print(f"API Key: {client.api_key}")
✨ Features
| Feature | Guest Mode | Login Mode |
|---|---|---|
| Chat with AI | ✅ | ✅ |
| Choose AI model | ✅ | ✅ |
| Upload file attachments | ✅ | ✅ |
| Chat with files | ✅ | ✅ |
| Save chat history | ❌ | ✅ |
| Load saved sessions | ❌ | ✅ |
| List all sessions | ❌ | ✅ |
| Resume conversations | ❌ | ✅ |
🤖 Supported Models
from deepai_api import SUPPORTED_MODELS, DEFAULT_MODEL
print(SUPPORTED_MODELS)
# ['gpt-5-nano', 'gpt-4.1-nano', 'deepseek-v3.2',
# 'gemini-2.5-flash-lite', 'llama-4-scout', 'gemma2-9b-it']
print(DEFAULT_MODEL)
# 'gpt-5-nano'
| Model | Description |
|---|---|
gpt-5-nano |
Default model, lightweight, supports function calling |
gpt-4.1-nano |
GPT-4.1 nano version |
deepseek-v3.2 |
DeepSeek v3.2 |
gemini-2.5-flash-lite |
Google Gemini Flash Lite |
llama-4-scout |
Meta Llama 4 Scout |
gemma2-9b-it |
Google Gemma 2 9B Instruct |
📚 Usage Examples
Guest Mode (No Login)
from deepai_api import DeepAIClient
# Create guest client
client = DeepAIClient.guest()
# Simple chat
response = client.chat("What is Python?")
print(response)
# Chat with specific model
response = client.chat(
message="Explain machine learning",
model="deepseek-v3.2"
)
print(response)
Login Mode (Full Features)
from deepai_api import DeepAIClient
client = DeepAIClient.login(
email="your@email.com",
password="yourpassword"
)
print(f"✓ Logged in!")
print(f" API Key: {client.api_key}")
print(f" Session ID: {client.session_id}")
Chat with Files
Upload files and ask AI to analyze them:
# Upload a file
attachment = client.upload_attachment("document.pdf")
file_uuid = attachment["attachment"]["uuid"]
print(f"✓ Uploaded: {attachment['attachment']['original_filename']}")
print(f" UUID: {file_uuid}")
print(f" Size: {attachment['attachment']['file_size']} bytes")
# Chat with the file
response = client.chat(
message="Summarize this document in 3 bullet points",
attachment_uuids=[file_uuid]
)
print(response)
Upload from bytes:
# Upload from bytes (e.g., from an API response)
image_bytes = requests.get("https://example.com/image.png").content
attachment = client.upload_attachment_bytes(
file_bytes=image_bytes,
filename="downloaded_image.png",
content_type="image/png"
)
Conversation Manager
For multi-turn conversations with automatic history saving:
from deepai_api import DeepAIClient, ConversationManager
client = DeepAIClient.login(email="...", password="...")
# Create conversation manager
manager = ConversationManager(
api_key=client.api_key,
session_id=client.session_id,
csrf_token=client.csrf_token,
model="gpt-5-nano"
)
# First message - introduce yourself
result = manager.send("Hi! My name is John.")
print(f"AI: {result['content']}")
# Second message - AI remembers your name!
result = manager.send("What's my name?")
print(f"AI: {result['content']}") # "Your name is John!"
# Check session info
print(f"Session UUID: {manager.session_uuid}")
print(f"Messages: {len(manager.messages)}")
Session Management
List all your chat sessions:
sessions = client.get_chat_sessions()
print(f"You have {len(sessions['sessions'])} sessions:")
for s in sessions["sessions"]:
print(f" - {s['title']}")
print(f" UUID: {s['uuid']}")
print(f" Updated: {s['updated_at']}")
Load and resume a session:
# Load existing session
session_uuid = "a0e3917d-8f07-4efb-8c99-a0ce9be393bb"
info = manager.load_session(session_uuid)
print(f"✓ Loaded: {info['title']}")
print(f" {info['message_count']} messages")
# Continue the conversation with full context
result = manager.send("Let's continue our discussion")
Get full session history:
session = client.get_chat_session("session-uuid-here")
print(f"Title: {session['title']}")
for msg in session["messages"]:
role = msg["role"]
content = msg["content"][:50]
print(f"[{role}]: {content}...")
📋 API Reference
DeepAIClient
Class Methods
| Method | Description |
|---|---|
DeepAIClient.guest() |
Create anonymous client (no login) |
DeepAIClient.login(email, password) |
Login and create authenticated client |
Instance Methods
| Method | Parameters | Description |
|---|---|---|
chat() |
message, model, chat_history, attachment_uuids |
Send chat message |
upload_attachment() |
file_path, filename |
Upload file for chat |
upload_attachment_bytes() |
file_bytes, filename, content_type |
Upload bytes |
get_attachment() |
attachment_uuid |
Get attachment info |
get_chat_sessions() |
known_uuids |
List user's sessions |
get_chat_session() |
session_uuid |
Get session with history |
save_chat_session() |
messages, session_uuid, title |
Save session |
ConversationManager
| Method | Parameters | Description |
|---|---|---|
send() |
message, model, attachment_uuids |
Send and auto-save |
load_session() |
session_uuid |
Load existing session |
new_conversation() |
title |
Start new conversation |
get_history() |
- | Get current messages |
get_session_info() |
- | Get session metadata |
🛡️ Error Handling
from deepai_api import DeepAIClient
client = DeepAIClient.login(email="...", password="...")
try:
response = client.chat("Hello")
except Exception as e:
error_msg = str(e)
if "Invalid API key" in error_msg:
print("❌ Session expired, please login again")
elif "Rate limited" in error_msg:
print("⏳ Too many requests, please wait")
elif "Session not found" in error_msg:
print("❌ Chat session doesn't exist")
elif "Access denied" in error_msg:
print("❌ You don't have access to this session")
elif "File not found" in error_msg:
print("❌ File path is invalid")
else:
print(f"❌ Error: {error_msg}")
📦 Requirements
- Python 3.7+
- requests >= 2.25.0
📄 License
MIT License - see LICENSE file for details.
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
📞 Support
If you encounter any issues or have questions, please open an issue.
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 deepai_chat-1.0.0.tar.gz.
File metadata
- Download URL: deepai_chat-1.0.0.tar.gz
- Upload date:
- Size: 18.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5ae9a44ba156a1792adc3c637ed7853e203c47ff5d09a5ec1ff19b2d1369b6c
|
|
| MD5 |
01b898dc6c9100ecd1f3462eb73d4bcd
|
|
| BLAKE2b-256 |
91723919e3a0e2331a64b677a0f65f6d54277f58d30f374df80b91d32081d35b
|
File details
Details for the file deepai_chat-1.0.0-py3-none-any.whl.
File metadata
- Download URL: deepai_chat-1.0.0-py3-none-any.whl
- Upload date:
- Size: 15.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
baaeff2d97ed1e4d084f04dd44c419965af5ef29e89d59d2024e05de859cdb5f
|
|
| MD5 |
9073602fb6563ca4e4dba55f56d98892
|
|
| BLAKE2b-256 |
e7a3952f7818d7b4c1b81d34d0e291c2524431afabde2b85b034843e7edbab41
|