Integration and migration
Runnable starter examples
Node.js 24 and Python 3 standard library. Set OSRM_API_KEY as a server environment variable. Never bundle a live secret in browser code. Starters make a live call and consume normal credits.
SDKs
JavaScript SDK repository version: 1.1.0. The JavaScript and Python SDKs support async jobs, sandbox and metadata endpoints. Install JavaScript from npm and Python from PyPI.
Migration checklist
- Validate response parsing in the fixture sandbox before a paid live call.
- OSRM coordinates use longitude,latitude. The /api/1 point and matrix arrays use latitude,longitude. The example adapter makes this conversion explicit.
- Compare endpoint, profile, response fields and plan limits. Compatibility does not imply full drop-in equivalence with every provider.
- Restrict the live key by service, origin/IP, expiry and project budget, then run a low-volume real test.
- Use a 1-hour or 24-hour rotation grace period, verify the new key, then revoke old aliases.
Sandbox API
Sandbox is for validating your integration's request and response handling without spending real credits. It is not a live routing, search or navigation environment.
- Choose Sandbox as the environment when creating a key in a project. The key's service scopes apply to this endpoint too.
- For POST /api/sandbox, send the Authorization: Bearer header and a JSON body.
- It returns deterministic fixtures for geocode, route, matrix and vrp at 0 credits. Route and matrix points use latitude,longitude order.
curl --fail-with-body -X POST https://osrmroute.com/api/sandbox \
-H "Authorization: Bearer $OSRMROUTE_SANDBOX_KEY" \
-H "Content-Type: application/json" \
-d '{"operation":"geocode","input":{"q":"Berlin, Germany"}}'geocode · route · matrix · vrp
60 requests/min/key · 24,000 bytes · billed_credits: 0
Try load planning in the sandbox
After you validate response handling in sandbox, move to a low-volume real integration test with a live key.
Async jobs
Operations: geocode_batch, matrix, optimize. POST /api/jobs returns 202 and a job ID. Reusing the same Idempotency-Key and payload returns the existing job; a different payload returns 409.
curl -X POST https://osrmroute.com/api/jobs \
-H "Authorization: Bearer $OSRM_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: your-durable-operation-id-001" \
-d '{"operation":"geocode_batch","input":{"queries":["Baku, Azerbaijan"]}}'GET /api/jobs # latest 50, owned by this key
GET /api/jobs/{id}
GET /api/jobs/{id}?result=1 # stored result for completed/failed jobs
DELETE /api/jobs/{id} # queued jobs only
States: queued → running → completed | failed | unknown
queued → cancelled
Expiry: HTTP 410 after 24 hours
Inputs and results are encrypted at rest.
Unknown outcomes: investigate X-Request-Id; never auto-retry.
Normal API entitlement, origin/IP policy and credits apply at dispatch.Signed callbacks
Create a public HTTPS webhook in the console, keep the one-time secret securely and pass webhook_id when creating a job. Verify X-OSRM-Timestamp and X-OSRM-Signature against the raw body.
signature = "sha256=" + HMAC_SHA256(secret, timestamp + "." + rawBody) Reject timestamps outside ±300 seconds. Compare signatures in constant time. Persist event IDs to deduplicate. Callbacks contain event ID, job ID and state; fetch results with the API key. Timeout: 10s. At most 5 attempts with backoff. No redirects. Treat repeated delivery as normal; do not repeat a charge or job.
Problems, tracing and source metadata
Error responses retain the legacy error field and add type, title, status, detail, code, request_id and retryable. Use X-Request-Id for support and request traces.
Source metadata
Check data sources, geographic coverage and freshness by service.
GET /api/source-metadata # live key, info scope 30 requests/min/key · 0 credits Coverage/freshness/source evidence only. Snapshot can be null.