Python SDK
Use the official Lexa Python SDK to integrate Lexa AI into your applications with an OpenAI-compatible interface.Install from PyPI
Get the latest version:
pip install lexaQuick Start
Installation
Basic Usage
Features
- OpenAI-Compatible - Drop-in replacement for OpenAI SDK
- Async Support - Full async/await support for high-performance applications
- Type Safety - Comprehensive type hints and validation with Pydantic
- Streaming - Real-time streaming responses for interactive applications
- Auto SSL - Automatic SSL certificate handling - works out of the box
- Multiple Models - Support for all Lexa models (lexa-mml, lexa-x1, lexa-rho)
- Flexible Configuration - Optional SSL and configuration overrides
- High Performance - Optimized HTTP clients with connection pooling
Available Models
The SDK provides access to the following Lexa models:lexa-mml
Multimodal model with vision capabilities (8,192 context window, 4,096 max tokens)
lexa-x1
Fast, lightweight text-based model (4,096 context window, 2,048 max tokens)
lexa-rho
Reasoning model with enhanced capabilities (16,384 context window, 8,192 max tokens)
Usage Examples
Basic Chat Completion
Async Support
Streaming Responses
List Available Models
Advanced Configuration
Custom SSL Configuration
API Reference
Client Methods
client.chat.completions.create()- Create chat completionclient.chat.completions.acreate()- Async chat completionclient.models.list()- List available modelsclient.models.alist()- Async list models
Parameters
model: Model to use (required)messages: List of messages (required)temperature: Sampling temperature (0.0 to 2.0)max_tokens: Maximum tokens to generatestream: Enable streaming responsestop_p: Nucleus sampling parameterfrequency_penalty: Frequency penaltypresence_penalty: Presence penalty
Security & SSL
The Lexa SDK automatically handles SSL certificate verification:- Default: Uses enhanced SSL with automatic certificate management
- Fallback: Gracefully falls back to standard SSL verification
- Manual Override: Allows custom SSL configuration when needed
Migration from OpenAI
If you’re currently using OpenAI’s SDK, migrating to Lexa is straightforward:- Before (OpenAI)
- After (Lexa)
Installation Options
- pip
- pip with version
- From source
Requirements
- Python: 3.8 or higher
- Dependencies: Automatically managed by pip
- SSL: Automatic certificate handling (no manual setup required)
Get Your API Key
1
Visit Lexa Chat
Go to https://www.lexa.chat
2
Sign up or log in
Create an account or sign in to your existing account
3
Navigate to Account settings
Click your avatar → Settings → Account tab
4
Generate API key
Find “API Keys” and click “Show” to view your key
5
Use in your application
Copy the key and use it in your Lexa SDK initialization
Links
PyPI Package
View on PyPI registry
GitHub Repository
Source code and issues
Lexa Chat
Try Lexa online
Community
Join our community
Support
- Issues: GitHub Issues
- Email: lexa@robiai.com
- Community: Robi AI Community