SDKs & Libraries
Integrate GreenMetric environmental scoring into your application using the REST API directly. Official SDKs are coming soon — in the meantime, use the examples below.
>_
cURL / REST API
Available Now
No SDK required. Call the API directly from any language or tool using your API key.
1. Submit an Analysis
curl -X POST https://api.greenmetric.ai/v1/analysis/text \
-H "x-api-key: gm_live_xxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"text": "Used iPhone 14 Pro Max, excellent condition",
"destinationCountry": "US"
}'
# Response (202 Accepted)
# {
# "success": true,
# "data": { "id": "analysis_abc123", "status": "pending" }
# }2. Poll Until Complete
Analysis is asynchronous. Poll the result endpoint until status is "completed" or "failed".
curl https://api.greenmetric.ai/v1/analysis/analysis_abc123 \ -H "x-api-key: gm_live_xxxxxxxxxxxx" # Poll every 2-3 seconds. Status transitions: pending → processing → completed
Analyze by URL
curl -X POST https://api.greenmetric.ai/v1/analysis/url \
-H "x-api-key: gm_live_xxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{"url": "https://www.amazon.com/dp/B0CHX3QBCH"}'List Analyses (Paginated)
curl "https://api.greenmetric.ai/v1/analysis?page=1&limit=20&status=completed" \ -H "x-api-key: gm_live_xxxxxxxxxxxx"
Error Response
# 429 Too Many Requests (rate limit or quota exceeded)
{
"success": false,
"error": "Rate limit exceeded",
"message": "Too many requests. Please try again later.",
"retryAfter": 10
}JS
JavaScript / TypeScript
Coming Soon
The official JavaScript SDK is coming soon. Use the REST API directly in the meantime.
Using fetch()
const API_KEY = "gm_live_xxxxxxxxxxxx";
const BASE_URL = "https://api.greenmetric.ai";
// Submit an analysis
const submitRes = await fetch(`${BASE_URL}/v1/analysis/text`, {
method: "POST",
headers: {
"x-api-key": API_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify({
text: "Used iPhone 14 Pro Max, excellent condition",
destinationCountry: "US",
}),
});
const { data } = await submitRes.json();
const analysisId = data.id;
// Poll until complete
let result;
while (true) {
const pollRes = await fetch(`${BASE_URL}/v1/analysis/${analysisId}`, {
headers: { "x-api-key": API_KEY },
});
result = await pollRes.json();
if (result.data.status === "completed" || result.data.status === "failed") {
break;
}
await new Promise((r) => setTimeout(r, 3000)); // wait 3s
}
console.log(result.data.scores.overallScore); // 87
console.log(result.data.scores.rating); // "A+"Py
Python
Coming Soon
The official Python SDK is coming soon. Use the REST API directly in the meantime.
Using requests
import requests
import time
API_KEY = "gm_live_xxxxxxxxxxxx"
BASE_URL = "https://api.greenmetric.ai"
headers = {
"x-api-key": API_KEY,
"Content-Type": "application/json",
}
# Submit an analysis
resp = requests.post(f"{BASE_URL}/v1/analysis/text", headers=headers, json={
"text": "Used iPhone 14 Pro Max, excellent condition",
"destinationCountry": "US",
})
analysis_id = resp.json()["data"]["id"]
# Poll until complete
while True:
result = requests.get(
f"{BASE_URL}/v1/analysis/{analysis_id}",
headers={"x-api-key": API_KEY},
).json()
if result["data"]["status"] in ("completed", "failed"):
break
time.sleep(3)
print(result["data"]["scores"]["overallScore"]) # 87
print(result["data"]["scores"]["rating"]) # "A+"