
Quick start integrating GuidedMind API with Python requests library.
This guide shows you how to integrate GuidedMind into a Python application using the requests library - no SDK required.
pip install requestsimport os
import requests
API_KEY = os.environ["GUIDEDMIND_API_KEY"]
BASE_URL = "https://api.guidedmind.ai"
headers = {
"X-API-Key": API_KEY,
"Content-Type": "application/json",
}def search(query, limit=5, threshold=0.7):
response = requests.post(
f"{BASE_URL}/rag/search",
headers=headers,
json={
"query": query,
"options": {
"limit": limit,
"threshold": threshold,
"include_metadata": True,
},
},
)
response.raise_for_status()
return response.json()
# Usage
results = search("What is the refund policy?")
for result in results["results"]:
print(f"Score: {result['score']:.2f}")
print(f"Content: {result['content'][:200]}...")
print("---")def upload_document(file_path, project_id):
with open(file_path, "rb") as f:
response = requests.post(
f"{BASE_URL}/rag/upload",
headers={"X-API-Key": API_KEY},
files={"file": f},
data={"project_id": project_id},
)
response.raise_for_status()
return response.json()
# Usage
result = upload_document("./policies.pdf", "proj_abc123")
print(f"Uploaded: {result['document_id']}")def upload_and_process(file_path, project_id):
with open(file_path, "rb") as f:
response = requests.post(
f"{BASE_URL}/rag/upload-and-process",
headers={"X-API-Key": API_KEY},
files={"file": f},
data={
"project_id": project_id,
"chunk_size": "512",
"chunk_overlap": "50",
},
)
response.raise_for_status()
return response.json()
# Usage
result = upload_and_process("./policies.pdf", "proj_abc123")
print(f"Processed: {result['chunks_created']} chunks")import time
def search_with_retry(query, max_retries=3):
for attempt in range(max_retries):
response = requests.post(
f"{BASE_URL}/rag/search",
headers=headers,
json={"query": query},
)
if response.status_code == 429:
retry_after = response.json().get("retry_after", 30)
wait_time = retry_after * (2 ** attempt)
print(f"Rate limited. Waiting {wait_time}s...")
time.sleep(wait_time)
continue
response.raise_for_status()
return response.json()
raise Exception("Max retries exceeded")import os
import requests
class GuidedMindClient:
def __init__(self, api_key=None):
self.base_url = "https://api.guidedmind.ai"
self.headers = {
"X-API-Key": api_key or os.environ["GUIDEDMIND_API_KEY"],
"Content-Type": "application/json",
}
def search(self, query, limit=5, threshold=0.7):
resp = requests.post(
f"{self.base_url}/rag/search",
headers=self.headers,
json={
"query": query,
"options": {"limit": limit, "threshold": threshold},
},
)
resp.raise_for_status()
return resp.json()
def upload(self, file_path, project_id):
with open(file_path, "rb") as f:
resp = requests.post(
f"{self.base_url}/rag/upload",
headers={"X-API-Key": self.headers["X-API-Key"]},
files={"file": f},
data={"project_id": project_id},
)
resp.raise_for_status()
return resp.json()
# Usage
client = GuidedMindClient()
results = client.search("How do I reset my password?")
print(f"Found {len(results['results'])} results")For production use, consider the Python SDK which adds type hints, async support, and automatic retries.