# Panvaya: Sea distance and transit time

Public developer guide: https://panvaya.com/developers
OpenAPI 3.1 specification: https://api.panvaya.com/api/v1/openapi.json
Pricing and access: https://panvaya.com/pricing

These examples describe the public API contracts; they do not run requests.
Keep API keys server-side. Both test and live keys can contact real providers and consume credits.
Read the organization's configured product costs and limits before starting a billable workflow.
Example responses are illustrative snapshots, not current shipment or vessel observations.

## API pricing, access and integration

### How much does the Panvaya tracking API cost?
At public default rates, Tracking starts at $10 per 30 days with 20 shared Ocean/Air shipments and 1,200 API credits. Ocean tracking costs 2 credits per successful API response and Air tracking costs 5 by default, including cache hits. Organization-specific rates and product access remain authoritative; check the usage endpoint before a billable workflow.

### Do Web and API tracking use separate shipment allowances?
No. Ocean and Air tracking share one shipment allowance across Web and API. Web refreshes consume no API credits. Successful API calls consume the configured credits even when served from cache, while repeat API tracking of the same enrolled reference in one billing cycle does not add another distinct shipment. API errors are not billed.

### How do I get a container tracking API key?
Sign in to the Panvaya API Dashboard and select Create API key. Choose Sandbox (test) for development or Live for production. Send the key in the X-API-Key header from your server or integration backend. Store it in a secret manager or server-side environment variable.

### Does the sandbox return mock tracking data?
Sandbox keys use the same endpoints, response contracts and workspace limits as live keys. Tracking requests can contact real carriers and consume your workspace's credits and shipment allowance. Use the published JSON examples as fixtures for offline tests. Start with the unbilled GET /api/v1/usage request to verify your key and check available products, configured rates and remaining allowances before trying tracking.

### Are sailing schedules charged per sailing or per carrier?
The public default is 5 credits for each carrier returning usable sailings, regardless of how many sailings that carrier returns. Empty or failed carriers cost zero. Partial and cached results with usable sailings can be billable; your organization's configured price is authoritative.

### How do I connect Panvaya to a TMS or ERP?
Your backend or middleware keeps the API key server-side, calls the documented endpoints and maps the returned JSON to your own shipment records. The integration guide includes shared Ocean/Air request examples, field mappings and starter downloads. Scheduled Ocean webhooks and embedded tracking are also documented. These are integration building blocks, not a claim of a native vendor connector.

### Worked Ocean API example
100 ocean containers checked twice daily
100 containers × 2 checks/day × 30 days × 2 credits = 12,000 credits
At public defaults, 6,000 successful checks use all 12,000 credits in a $100 Tracking allocation. The 100 distinct references use 100 of its 200 shared shipment slots during one billing cycle.

## 1. General Architecture & Authentication
- **Base URL:** `https://api.panvaya.com/api/v1`
- **Authentication:** Pass the API key in the header:
  ```http
  X-API-Key: pv_live_your_key_here
  ```
  (Or as `Authorization: Bearer <key>`). Live keys are prefixed `pv_live_`; sandbox test keys are prefixed `pv_test_`.
- **Content-Type:** `application/json`
- **Rate Limits:** All API keys in one organization share a UTC-minute limit (Free 5, Enterprise 15 requests/minute by default). Each enabled product has a separate organization-wide cap (D&D Tariffs 20; Sailing Schedules 5; Ocean/Air Tracking 10; computational APIs 10; lightweight APIs 10 requests/minute by default). Admins may customize both.
  - Headers returned: `X-Request-Id`, `X-RateLimit-Limit`, `X-RateLimit-Remaining`, and for metered products `X-Product-RateLimit-Limit` and `X-Product-RateLimit-Remaining`.
  - `X-Request-Id` is optional on requests; if omitted, Panvaya generates it and returns it in the response.
  - When throttled, returns `HTTP 429 RATE_LIMIT_EXCEEDED` (organization) or `PRODUCT_RATE_LIMIT_EXCEEDED` (product) with a `Retry-After: <seconds>` header. Integrations should automatically wait and retry.
  - Higher rate limits are available for enterprise accounts on request. Contact Panvaya support to unlock a higher limit.
- **Error Envelope:**
  ```json
  {
    "errors": [
      {
        "code": "INVALID_REQUEST",
        "title": "Invalid request",
        "detail": "One of container, bol, or bk is required."
      }
    ]
  }
  ```
  Always branch on the stable string `code` (e.g. `INVALID_REQUEST`, `CARRIER_NOT_SUPPORTED`, `CARRIER_MAINTENANCE`, `NOT_FOUND`, `QUOTA_EXCEEDED`, `RATE_LIMIT_EXCEEDED`, `PRODUCT_RATE_LIMIT_EXCEEDED`, `RATE_LIMIT_UNAVAILABLE`, `UPSTREAM_ERROR`, `UPSTREAM_UNAVAILABLE`).

### 6) Sea Distance & Transit Time
- **Method & Path:** `POST /api/v1/distance-time/calculate`
- **Request Body (JSON):**
  - `origin` (string, optional): Origin UN/LOCODE (e.g. `"NLRTM"`). Required if waypoints not supplied.
  - `destination` (string, optional): Destination UN/LOCODE (e.g. `"SGSIN"`). Required if waypoints not supplied.
  - `waypoints` (array, optional): Multi-stop array (up to 6 stops) with `[{"locode": "CNSHA"}, {"locode": "NLRTM"}]`.
  - `avoidDangerZones` (boolean, default false): Set true to reroute around Red Sea / Suez Canal via Cape of Good Hope.
- **Example 200 OK Response:**
```json
{
  "safe": false,
  "totalNm": 8305.2,
  "totalKm": 15381.2,
  "speedKnots": 13,
  "transitHours": 638.9,
  "legs": [
    {
      "fromName": "Rotterdam",
      "fromLocode": "NLRTM",
      "from": [
        51.9244,
        4.4777
      ],
      "toName": "Singapore",
      "toLocode": "SGSIN",
      "to": [
        1.264,
        103.84
      ],
      "distanceNm": 8305.2,
      "cached": true,
      "error": null,
      "route": [
        [
          51.9244,
          4.4777
        ],
        [
          50.5,
          0.1
        ],
        [
          36,
          -5.3
        ],
        [
          31.2,
          32.3
        ],
        [
          12.6,
          43.3
        ],
        [
          1.264,
          103.84
        ]
      ]
    }
  ]
}
```

Full guide: https://panvaya.com/developers/docs.md
