Installation
Install the MeshAI Python SDK using pip:Quick Start
Client Configuration
Basic Configuration
Core Methods
execute_task()
Execute a single AI task with automatic agent selection.| Parameter | Type | Description | Default |
|---|---|---|---|
task_type | str | Type of AI task to execute | Required |
input_data | Any | Input data for the task | Required |
quality_level | str | Quality level: “basic”, “standard”, “high”, “premium" | "standard” |
max_cost | float | Maximum cost in SOL | None |
timeout | int | Timeout in milliseconds | 30000 |
agent_requirements | dict | Specific agent requirements | None |
TaskResult object with output, metadata, and metrics.
- Basic Usage
- With Options
- Error Handling
create_workflow()
Create multi-step workflows with task dependencies.Workflow Management
Workflow Class
Task Dependencies
- Sequential Tasks
- Parallel Tasks
- Complex Dependencies
Task Types
Available Task Types
| Task Type | Description | Input Format | Output Format |
|---|---|---|---|
text_generation | Generate text content | str or dict | str |
text_analysis | Analyze text sentiment, entities | str | dict |
text_summarization | Summarize long text | str | str |
document_ocr | Extract text from documents | dict with URL/base64 | str |
image_analysis | Analyze and caption images | dict with URL/base64 | dict |
image_generation | Generate images from text | str | dict with URL |
code_generation | Generate code | str or dict | str |
translation | Translate text | dict with text and languages | str |
audio_transcription | Convert speech to text | dict with audio URL | str |
Task-Specific Examples
- Text Generation
- Image Analysis
- Translation
Response Objects
TaskResult
WorkflowResult
Error Handling
Exception Types
Error Handling Patterns
- Basic Error Handling
- Retry Logic
- Graceful Degradation
Advanced Features
Batch Processing
Streaming Results
Custom Agent Selection
Monitoring and Analytics
Usage Statistics
Task History
Performance Monitoring
Configuration Options
Environment Variables
Configuration File
Testing and Development
Mock Client for Testing
Development Mode
Best Practices
Error Handling
Error Handling
Always implement proper error handling for production applications:
- Handle network timeouts gracefully
- Implement retry logic for transient failures
- Provide fallback mechanisms for critical features
- Log errors for debugging and monitoring
Performance Optimization
Performance Optimization
Optimize your usage for better performance and costs:
- Use appropriate quality levels for your use case
- Implement caching for repeated similar requests
- Use batch processing for multiple related tasks
- Monitor usage and costs regularly
Security
Security
Follow security best practices:
- Store API keys securely (environment variables)
- Validate and sanitize input data
- Use HTTPS for all communications
- Monitor for unusual usage patterns