This directory contains examples demonstrating how to use the Gradient Python SDK with various frameworks and for different use cases.
These examples show how to integrate the Gradient Python SDK with popular web frameworks:
- Django Integration - Simple Django views for chat completions, image generation, and agent listing
- Flask Integration - Flask routes demonstrating SDK usage with proper error handling
- FastAPI Integration - FastAPI endpoints with Pydantic models and async support
Each example is a standalone Python script that can be run directly:
# Make sure you have the required environment variables set
export DIGITALOCEAN_ACCESS_TOKEN="your_token_here"
export GRADIENT_MODEL_ACCESS_KEY="your_model_key_here"
export GRADIENT_AGENT_ACCESS_KEY="your_agent_key_here"
export GRADIENT_AGENT_ENDPOINT="https://your-agent.agents.do-ai.run"
# Run an example
python examples/django_integration.pyThe Django example shows how to create a Django view that uses the Gradient SDK for AI-powered responses.
The Flask example demonstrates integrating Gradient SDK with Flask routes for web applications.
The FastAPI example shows how to create async endpoints that leverage the Gradient SDK's async capabilities.
All examples require proper authentication setup:
DIGITALOCEAN_ACCESS_TOKEN- For DigitalOcean API operationsGRADIENT_MODEL_ACCESS_KEY- For serverless inferenceGRADIENT_AGENT_ACCESS_KEY- For agent-specific operationsGRADIENT_AGENT_ENDPOINT- Your deployed agent endpoint
When adding new examples:
- Follow the existing naming convention
- Include comprehensive comments
- Handle errors appropriately
- Use environment variables for configuration
- Add the example to this README