Complete guide to integrating EcoAI's green optimization into your applications
Get up and running with EcoAI in under 5 minutes
pip install ecoai
Sign up at ecoai.club to get your free API key.
from ecoai import EcoAI
# Initialize the SDK
eco = EcoAI(api_key="your_api_key_here")
# Optimize a prompt
result = eco.optimize_prompt("Please kindly write a comprehensive analysis of the data")
print(f"Original: {result['original']}")
print(f"Optimized: {result['optimized']}")
print(f"Tokens saved: {result['tokens_saved']}")
print(f"CO2 saved: {result['carbon_savings']['co2_g_saved']:.4f}g")
All API requests require authentication using your API key
Include your API key in the request headers:
X-API-Key: ecoai_8727f8d76454fff1aa3b786d6e980fc2
Complete reference for all EcoAI API endpoints
Optimize a prompt to reduce tokens while maintaining quality
Parameter | Type | Required | Description |
---|---|---|---|
prompt | string | Yes | The prompt to optimize |
strategy | string | No | Optimization strategy: "balanced" (default), "aggressive", "conservative" |
quality_threshold | float | No | Minimum quality score (0.0-1.0, default: 0.95) |
{
"prompt": "Please kindly write a comprehensive analysis of the data",
"strategy": "balanced",
"quality_threshold": 0.95
}
{
"success": true,
"data": {
"original": "Please kindly write a comprehensive analysis of the data",
"optimized": "Write a comprehensive analysis of the data",
"tokens_before": 12,
"tokens_after": 8,
"tokens_saved": 4,
"quality_score": 0.96,
"carbon_savings": {
"co2_g_saved": 0.0001,
"kwh_saved": 0.000003
},
"strategy_used": "balanced"
}
}
Optimize multiple prompts in a single request
{
"prompts": [
"Please kindly write a comprehensive analysis",
"Can you help me understand this concept?",
"I would really appreciate your assistance"
],
"strategy": "balanced"
}
{
"success": true,
"data": {
"results": [
{
"original": "Please kindly write a comprehensive analysis",
"optimized": "Write a comprehensive analysis",
"tokens_saved": 2
}
],
"total_tokens_saved": 6,
"total_co2_saved": 0.0002
}
}
Get your optimization analytics and impact metrics
Parameter | Type | Required | Description |
---|---|---|---|
start_date | string | No | Start date (YYYY-MM-DD) |
end_date | string | No | End date (YYYY-MM-DD) |
{
"success": true,
"data": {
"total_requests": 1250,
"total_tokens_saved": 15420,
"total_co2_saved": 0.54,
"average_quality_score": 0.96,
"cost_savings": 12.50,
"time_period": "2024-01-01 to 2024-01-31"
}
}
Integrate EcoAI with popular AI frameworks
from ecoai import EcoAI
import openai
eco = EcoAI(api_key="your_ecoai_key")
openai.api_key = "your_openai_key"
# Optimize prompt before sending to OpenAI
result = eco.optimize_prompt("Please kindly write a comprehensive analysis of the data")
response = openai.ChatCompletion.create(
model="gpt-4",
messages=[{"role": "user", "content": result["optimized"]}]
)
print(f"Saved {result['tokens_saved']} tokens")
print(f"CO2 saved: {result['carbon_savings']['co2_g_saved']:.4f}g")
from ecoai import EcoAI
from langchain import LLMChain, PromptTemplate
from langchain.llms import OpenAI
eco = EcoAI(api_key="your_ecoai_key")
llm = OpenAI(openai_api_key="your_openai_key")
# Optimize LangChain prompts
template = eco.optimize_prompt("Your template here")["optimized"]
prompt = PromptTemplate(template=template, input_variables=["input"])
chain = LLMChain(llm=llm, prompt=prompt)
result = chain.run("Your input here")
from ecoai import EcoAI
from transformers import pipeline
eco = EcoAI(api_key="your_ecoai_key")
# Optimize prompts for HuggingFace models
optimized_prompt = eco.optimize_prompt("Your prompt here")["optimized"]
classifier = pipeline("text-classification")
result = classifier(optimized_prompt)
Common error responses and how to handle them
{
"success": false,
"error": {
"code": "INVALID_API_KEY",
"message": "The provided API key is invalid",
"details": "Please check your API key and try again"
}
}
Code | Status | Description |
---|---|---|
INVALID_API_KEY | 401 | Invalid or missing API key |
RATE_LIMIT_EXCEEDED | 429 | Rate limit exceeded |
INVALID_REQUEST | 400 | Invalid request parameters |
QUOTA_EXCEEDED | 402 | API quota exceeded |
API usage limits and best practices
Plan | Requests per Minute | Requests per Day | Monthly Quota |
---|---|---|---|
Free | 60 | 1,000 | 10,000 |
Pro | 300 | 50,000 | 500,000 |
Enterprise | 1,000 | Unlimited | Unlimited |
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 59
X-RateLimit-Reset: 1640995200
Download the EcoAI SDK and start optimizing your AI applications today