Python example
Python Example: Calling the /ask Endpoint
import requests
# Replace this with your actual API key
API_KEY = "your-api-key-here"
# Base URL of the LawyerGPT API
BASE_URL = "https://api.lawyergptai.cc/v1"
# Example payload for the /ask endpoint
payload = {
"question": "Can I terminate a lease early in California without penalty?",
"language": "en"
}
# Set headers including the API key
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
# Make the POST request
response = requests.post(f"{BASE_URL}/ask", json=payload, headers=headers)
# Handle the response
if response.status_code == 200:
data = response.json()
print("๐ฌ Answer:", data.get("answer"))
print("๐ Source:", data.get("source"))
else:
print("โ Error:", response.status_code, response.text)
Requirements
To run the above example, make sure you have the requests
library installed:
pip install requests
Output Example
๐ฌ Answer: In California, you can terminate a lease early if you're a victim of domestic violence, called to active military duty, or if your landlord significantly breaches the lease terms.
๐ Source: California Civil Code ยงยง 1946.7, 1951.2
Last updated