Overview
The direct API approach lets you use Bloom’s proxy endpoints directly in your Python agent code. This gives you full control over the HTTP requests and responses.Example Implementation
import requests
import os
# Configuration
AGENT_ID = os.getenv("BLOOM_AGENT_ID", "your-agent-id")
ORG_API_KEY = os.getenv("BLOOM_ORG_API_KEY", "your-org-key")
def search_web(query):
"""Search using Serper via Bloom proxy"""
response = requests.post(
"https://iam.bloomtechnologies.app/https://google.serper.dev/search",
headers={"Authorization": f"Bearer {ORG_API_KEY}"},
json={
"agent_id": AGENT_ID,
"q": query,
"num": 3
}
)
return response.json() if response.status_code == 200 else None
def analyze_text(text):
"""Analyze text using OpenAI via Bloom proxy"""
response = requests.post(
"https://iam.bloomtechnologies.app/https://api.openai.com/v1/chat/completions",
headers={"Authorization": f"Bearer {ORG_API_KEY}"},
json={
"agent_id": AGENT_ID,
"messages": [{"role": "user", "content": f"Analyze: {text}"}],
"max_tokens": 200,
"model": "gpt-3.5-turbo"
}
)
if response.status_code == 200:
result = response.json()
if "choices" in result:
return result["choices"][0]["message"]["content"]
return None
# Usage example
search_results = search_web("AI agent frameworks")
analysis = analyze_text("This is sample text to analyze")
Error Handling
Always implement proper error handling:def safe_api_call(url, payload):
try:
response = requests.post(url,
headers={"Authorization": f"Bearer {ORG_API_KEY}"},
json=payload,
timeout=30
)
response.raise_for_status()
return response.json()
except requests.exceptions.RequestException as e:
print(f"API call failed: {e}")
return None
Request Format
All proxy requests follow this structure:{
"agent_id": "your-agent-id", # Required
# ... service-specific parameters
}
Ensure your agent has the appropriate scopes configured for the services you’re trying to access.