تكامل إنتاجي آمن
Key handling, timeouts, retries, cancellation and what to do when the wallet runs dry.
Keep the key on the server
| Surface | Safe? | Why |
|---|---|---|
| Server process environment or secret manager | Yes | Never reaches the client |
| Browser bundle | No | Readable by anyone with devtools |
| Mobile app binary or JS bundle | No | Extractable with standard tooling |
| Static style or tile URL | Conditional | Only with a short-lived embed key, never the organization key |
| CI log or error report | No | Keys leak through logs more often than through attackers |
When a client needs location data, give it a proxy route on your own backend, or a short-lived client token minted for a specific subject. The React Native SDK enforces the proxy pattern by requiring a proxyBaseUrl, which is deliberate.
Timeouts are mandatory
Retrieval operations take tens of milliseconds in the normal case, but a routing request can take much longer than a search. Set a timeout per family: a search at 3 seconds, routing at 10, a matrix at 15. Without a timeout a stalled upstream becomes a stalled request queue in your own service.
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), 10_000);
try {
return await client.maps.routing.directions(body, { signal: controller.signal });
} finally {
clearTimeout(timer);
}Retry the right things
- Retry 429, 500, 503, 504, and only with an Idempotency-Key or for a GET.
- Honour Retry-After. When it is absent use exponential backoff with jitter, starting at 250 ms.
- Never retry 401, 403, 404, 409, 413 or 422: they are deterministic.
- Cancel in-flight work when the user navigates away. An aborted request is not a failure to retry.
- A retry storm after an outage is your own denial of service. Cap concurrency as well as attempts.
When the wallet runs out
quota_exceeded is a terminal state until the balance is topped up. Treat it as a distinct branch: do not retry, do not fall back to another key (it shares the same wallet), and surface an actionable message to the operator rather than a generic failure to the end user.
try:
result = client.maps.places.search(query)
except BardiyaApiError as failure:
if failure.code == "quota_exceeded":
alert_operator("Bardiya wallet exhausted") # actionable, not retried
return degraded_response() # your own fallback
if failure.code == "rate_limited":
return retry_later(after=failure.retry_after)
raiseCache what is cacheable
- A style document changes rarely: cache it for minutes, not per request.
- Tile responses are immutable for a given (source, z, x, y): cache them aggressively at your edge.
- Place details for a place_id are stable enough to cache for a short window.
- Search and directions are position- and time-sensitive: do not cache them across users.
Log the correlations
Record X-Bardiya-Request-Id, the operation, the status code and your own correlation id for every outbound call. When something goes wrong at 2 a.m., that tuple is the difference between a five-minute diagnosis and an hour of guessing.
