This repository contains examples and documentation for integrating with AI Chat APIs. Examples are provided for both OpenWebUI (local/self-hosted) and Expedient AI Cloud Gateway.
For OpenWebUI v0.6.32+ (local or self-hosted deployments)
-
Get your API key or JWT token from OpenWebUI:
- Click on your User icon (top right)
- Select Settings
- Go to Account tab
- Under API Keys section, click Show to reveal your keys
- Copy either the API Key (sk-...) or JWT Token (eyJ...)
-
Create and activate a virtual environment:
# Create virtual environment python -m venv venv # Activate virtual environment # On macOS/Linux: source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt -
Update the configuration in the v3 example files:
- Set
chat_urlto your OpenWebUI URL (e.g.,"http://localhost:3000") - Set
api_keyorjwt_tokenwith your credentials
- Set
-
Run the OpenWebUI examples:
# Quick test (simplest) python v3_quick_start.py # Standard streaming with API Key python v3_example.py # Using JWT Token authentication python v3_example_jwt.py
For Expedient AI hosted service
- Get your API key from Expedient AI
- Create and activate a virtual environment (see above)
- Install dependencies:
pip install -r requirements.txt - Update the API key in the example file that you are running
- Run the examples:
# Quick test (simplest) python quick_start.py # Standard streaming models python example.py # Reasoning models (for complex analysis) python reasoning_example.py # Web access models with citations (for live web search) python citation_example.py # OR use cURL commands directly (see curl.md) curl -X POST "[ ENTER_CHAT_URL_HERE ]/chat/completions" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer [ ENTER_API_KEY_HERE ]" \ -d '{"model": "gpt-4.1", "messages": [{"role": "user", "content": "Hello!"}]}'
Minimal OpenWebUI example for immediate testing. Features:
- Ultra-simple code (~40 lines)
- OpenWebUI API endpoint configuration
- Perfect for local/self-hosted OpenWebUI instances
- Copy-paste ready
Complete OpenWebUI streaming example with API Key authentication. Features:
- Real-time streaming responses
- API Key authentication (recommended for scripts)
- Detailed comments and explanations
- Works with any OpenWebUI-compatible model
OpenWebUI streaming example with JWT Token authentication. Features:
- Same streaming functionality as v3_example.py
- JWT Token authentication (session-based)
- Demonstrates alternative authentication method
- Useful for web applications
Minimal example for immediate testing. Features:
- Ultra-simple code (30 lines)
- No comments or explanations
- Just the essentials for quick API testing
- Perfect for copy-paste and quick modifications
Complete Python script demonstrating streaming AI responses with standard models. Features:
- Real-time streaming responses
- Standard AI models (GPT, Claude, Gemini, Perplexity)
- Detailed comments and explanations
- Production-ready streaming implementation
Advanced reasoning models with animated thinking indicators. Features:
- Complex analytical problem solving
- Step-by-step reasoning processes
- Animated thinking dots while processing
- Models: o4-mini, o3, Claude 4, Gemini 2.5
Perplexity web reasoning models with real-time data and citations. Features:
- Real-time web search during AI responses
- Current events and fact-checking capabilities
- Automatic citation detection and reporting
- Animated search indicators
Complete Postman collection documentation with:
- 8 ready-to-use API request examples
- All supported AI models and providers
- Parameter explanations and usage tips
- Import instructions for Postman
Command-line cURL examples for developers and scripters. Features:
- 8 cURL commands matching all Postman examples
- Advanced options and streaming processing
- Environment variable setup for security
- Batch processing and error handling examples
Python-specific gitignore file that excludes:
- Virtual environments
- API keys and sensitive files
- Python cache files
- IDE configuration files
Both OpenWebUI and Expedient AI Cloud Gateway support models from multiple providers:
- OpenAI: GPT-4.1, GPT-5, o3, o4-mini (reasoning), GPT-4o, GPT-4o-mini, GPT-3.5-turbo
- Anthropic: Claude-Sonnet-4, Claude-Sonnet-4.5, Claude-3.7-Sonnet, Claude-3-Haiku, Claude-3-Opus
- Google: Gemini-2.5-Pro, Gemini-2.5-Flash, Gemini-1.5-Pro, Gemini-1.5-Flash
- Perplexity: Sonar-Pro, Sonar-Reasoning-Pro, Sonar (web-connected with real-time data)
Note: Available models depend on your OpenWebUI configuration or Expedient AI subscription.
β
Unified Interface - One API for multiple AI providers
β
Real-time Streaming - See responses as they're generated
β
Multiple Models - Choose the best model for your use case
β
Web Access & Citations - Real-time data with source transparency
β
Quick Start - Ultra-simple 30-line example for immediate testing
β
Enterprise Ready - Production-grade error handling
β
Easy Integration - Simple REST API with JSON
http://localhost:3000/api/v1/chat/completions
Or replace localhost:3000 with your OpenWebUI instance URL.
[ ENTER_CHAT_URL_HERE ]/chat/completions
Get your credentials from OpenWebUI:
- Click on your User icon β Settings β Account
- Under API Keys, click Show
- Copy either:
- API Key (sk-...) - Recommended for scripts and automation
- JWT Token (eyJ...) - For session-based authentication
All requests require a Bearer token:
Authorization: Bearer YOUR_API_KEY_OR_JWT_TOKEN
All requests require a Bearer token in the Authorization header:
Authorization: Bearer [ ENTER_API_KEY_HERE ]
import requests
import json
# Simple streaming request to OpenWebUI
response = requests.post(
"http://localhost:3000/api/v1/chat/completions",
headers={
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_KEY"
},
json={
"model": "gpt-4.1",
"messages": [{"role": "user", "content": "Hello, world!"}],
"stream": True
},
stream=True
)
# Process streaming response
for line in response.iter_lines(decode_unicode=True):
if line and line.startswith("data: "):
data_str = line[6:]
if data_str.strip() == "[DONE]":
break
try:
data = json.loads(data_str)
if "choices" in data and data["choices"]:
delta = data["choices"][0].get("delta", {})
if "content" in delta:
print(delta["content"], end="", flush=True)
except:
continueimport requests
import json
# Simple streaming request to Expedient AI
response = requests.post(
"[ ENTER_CHAT_URL_HERE ]/chat/completions",
headers={
"Content-Type": "application/json",
"Authorization": "Bearer [ ENTER_API_KEY_HERE ]"
},
json={
"model": "gpt-4.1",
"messages": [{"role": "user", "content": "Hello, world!"}],
"stream": True
},
stream=True
)
# Process streaming response (same as OpenWebUI)
for line in response.iter_lines(decode_unicode=True):
if line and line.startswith("data: "):
data_str = line[6:]
if data_str.strip() == "[DONE]":
break
try:
data = json.loads(data_str)
if "choices" in data and data["choices"]:
delta = data["choices"][0].get("delta", {})
if "content" in delta:
print(delta["content"], end="", flush=True)
except:
continue- Python 3.6 or higher
requestslibrary (pip install requests)- Either:
- Running OpenWebUI instance (v0.6.32+), OR
- Valid Expedient AI API key
- Clone this repository
- Create and activate a virtual environment:
# Create virtual environment python -m venv venv # Activate virtual environment # On macOS/Linux: source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Get your API key from OpenWebUI: User β Settings β Account β API Keys β Show
- Update
chat_urlandapi_keyin the v3 scripts - Run the OpenWebUI examples:
python v3_quick_start.py # or v3_example.py or v3_example_jwt.py
- Copy your API key from the Expedient AI dashboard
- Update the
api_keyvariable in the script you want to use - Run the examples:
# Quick test python quick_start.py # Standard streaming models python example.py # Reasoning models python reasoning_example.py # Web search with citations python citation_example.py
Choose the right model for your needs:
| Use Case | Recommended Models |
|---|---|
| Advanced Reasoning & Logic | o4-mini, claude-sonnet-4-20250514, gemini/gemini-2.5-pro |
| Complex Analysis | gpt-4.1, gpt-4o, claude-3-7-sonnet-20250219, gemini/gemini-1.5-pro |
| Large Text Processing | gemini/gemini-2.5-flash (1M+ token context) |
| Creative Writing | claude-sonnet-4-20250514, claude-3-7-sonnet-20250219, gpt-4o |
| Code Generation | gpt-4.1, claude-sonnet-4-20250514, gpt-4o |
| Fast Responses | gpt-4o-mini, claude-3-haiku-20240307, gemini/gemini-1.5-flash |
| Current Events & Web Data | perplexity/sonar-reasoning-pro, perplexity/sonar-pro |
| General Purpose | gpt-4.1 (default), gpt-3.5-turbo |
- v3 Quick Start - Minimal OpenWebUI example
- v3 API Key Example - Detailed OpenWebUI implementation with API key
- v3 JWT Example - OpenWebUI with JWT token authentication
- Postman Collection - Complete API testing examples
- cURL Examples - Command-line examples for terminal and scripts
- Quick Start - Minimal example for immediate testing
- Standard Streaming Example - Detailed implementation with comments
- Reasoning Example - Advanced reasoning with thinking animation
- Citation Example - Web search with real-time citations
- Live Swagger API Documentation - Visit
[ ENTER_CHAT_URL_HERE ]/docsin your browser for interactive API documentation - API Documentation - Contact Expedient AI for detailed API docs
For technical support and API access:
- Website: Expedient AI
- Documentation: See
postman.mdfor comprehensive examples - Issues: Use this repository's issue tracker for code-related questions
π Never commit API keys to version control
π Use environment variables for production deployments
π Rotate API keys regularly
π Monitor API usage and costs
This example code is provided for demonstration purposes. Please check with Expedient AI for licensing terms for the API service itself.