API: Getting Started
Ready to make your first request? Let's go.
Prerequisites
Before proceeding, ensure:
- ✅ Extension is Installed: See guide
- ✅ Extension is Connected: Popup shows Connected ✓
- ✅ You have your URL: Copy it from the extension popup.
Important
Your extension can only process one request at a time. Do not send parallel requests to the same WebSocket ID. If you need 10 concurrent requests, you need 10 different browser profiles/extensions running.
Option 1: Try the Playground (Recommended)
The easiest way to verify everything is working is to use our visual playground.
- Open the Playground: https://app.aimodeapi.com/playground
- Paste your Endpoint: Enter the URL from your extension (e.g.,
https://app.aimodeapi.com/api/abc...). - Ask a Question: Type "Hello" or "What is AI?".
- Send: Click the button and watch your browser process it.
If the Playground works, your API integration will work too.
Option 2: Code Examples
Ready to write code? Here is how to call your API.
Prerequisites
- Your unique API endpoint:
https://app.aimodeapi.com/api/{your-id} - A tool to send HTTP POST requests.
test_api.py
import requests
# REPLACE with your actual endpoint from the extension
API_ENDPOINT = "https://app.aimodeapi.com/api/abc123-def456"
print(f"Sending request to {API_ENDPOINT}...")
try:
response = requests.post(
API_ENDPOINT,
json={"query": "What are the benefits of open source?"},
timeout=70 # Google AI can be slow, give it time
)
response.raise_for_status()
data = response.json()
# Access the structured data
answer = data["response"]["response_body"]
sources = data["response"]["sources"]
print("\n=== Answer ===\n")
print(answer[:200] + "...") # Print first 200 chars
print(f"\nFound {len(sources)} sources.")
except Exception as e:
print(f"Error: {e}")
test_api.js
// REPLACE with your actual endpoint from the extension
const API_ENDPOINT = "https://app.aimodeapi.com/api/abc123-def456";
async function askAI() {
console.log(`Sending request to ${API_ENDPOINT}...`);
try {
const response = await fetch(API_ENDPOINT, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
query: 'What are the benefits of open source?'
})
});
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
const data = await response.json();
console.log("\n=== Answer ===\n");
console.log(data.response.response_body.substring(0, 200) + "...");
console.log(`\nFound ${data.response.sources.length} sources.`);
} catch (error) {
console.error("Error:", error);
}
}
askAI();
Understanding the Response
You will receive a JSON object with this structure:
{
"response": {
"success": true,
"processed_at": "2023-10-27T10:00:00.000Z",
"data": {
"response_body": "Open source software provides...",
"sources": [
{
"url": "https://opensource.org/...",
"title": "Open Source Initiative",
"description": "The benefits of open source...",
"source": "opensource.org"
}
],
"follow_up_questions": [
"What are open source licenses?",
"History of open source"
]
}
}
}
success: Boolean indicating if the extension successfully processed the query.data.response_body: The main answer, formatted in Markdown.data.sources: A list of citations Google provided.data.follow_up_questions: Suggested questions for deeper research.
What Just Happened?
- You sent a JSON payload with your question.
- Our server routed it to your browser extension via WebSocket.
- Your browser opened a background tab to Google AI Mode.
- Google generated the answer, and your extension scraped it.
- The structured data was returned to your script.
Next Steps
- Explore the full API Reference.
- Check out Error Handling if you hit snags.