docs

    Troubleshooting

    Diagnose and fix the most common issues integrating the CHRT API. Organized by symptom — find the error you're seeing, then apply the fix.

    Looking for the full status-code reference instead? See Error Codes. Every CHRT error follows the same JSON shape: { "error", "message", "details" }. When in doubt, read the message and details — they name the exact problem.

    401 Unauthorized — "Invalid or missing API key"

    The request never authenticated. Common causes:

    • The key is missing, mistyped, or passed in the wrong header.
    • You're using a test key against live data (or a live key in test) — environments are separate.
    • The key was regenerated or revoked. Regenerating invalidates the old secret immediately.

    Fix: CHRT authenticates with the x-api-key header (or a ?key= query parameter for style/tile URLs) — not an Authorization: Bearer header. Confirm the key is active in /app/keys and matches your environment (chrt_pk_live_… vs chrt_pk_test_…).

    terminal
    # Correct — x-api-key header
    curl -I "https://api.chrt.co/v1/features?bbox=-71,42,-70,43&limit=1" \
      -H "x-api-key: chrt_pk_live_acme_x7k9m2..."
    
    # Correct — query parameter (for style.json / tile URLs)
    curl -I "https://api.chrt.co/v1/tiles/style.json?key=chrt_pk_live_acme_x7k9m2..."

    403 Forbidden — three different causes

    A 403 means you authenticated successfully but aren't allowed to perform this request. Read details to tell the three cases apart.

    1. Missing scope

    The key lacks the scope the endpoint requires. Keys carry some combination of tiles:read,features:read, and cells:read. A tiles-only key cannot call the Feature API, and vice versa. Grant the missing scope when editing the key in /app/keys.

    2. Coverage not in your plan

    This is CHRT-specific. API keys inherit chart-source access from your team's purchased coverage regions. Requesting data for a source your plan doesn't include returns 403 — coverage gating is a sovereignty feature, not a bug.

    response.json
    // 403 Forbidden
    {
      "error": "forbidden",
      "message": "Your coverage plan does not include this chart source.",
      "details": {
        "required_coverage": "CA",
        "current_coverage": ["US"]
      }
    }

    Fix: add the region to your plan from /app, or request data only within your covered sources.

    3. Domain allowlist — 403 Domain not allowed

    The key has an Allowed domains list, and the browser origin making the request isn't on it. Add the hostname to the key, or clear the list to remove the restriction.

    List bare hostnames — example.com, not https://example.com/. A URL, a *.example.com wildcard, or a port is accepted and normalized to the hostname for you. Subdomains are always included, so example.com covers app.example.com.

    Only browser requests are checked. If you're seeing this from a browser but not from curl, that's expected — requests with no Origin header aren't restricted.

    4. IP allowlist — 403 ip_*

    The key has an IP allowlist, and the code field says why the request was refused:

    • ip_not_allowed: the address the request came from isn't on the list. From behind a NAT, proxy or cloud gateway, that's the address your traffic leaves from. Add it, or a range that covers it.
    • ip_allowlist_requires_gateway: the request didn't come through https://api.chrt.co. A key with an allowlist works only there; call the API at that address.
    • ip_attestation_invalid: rare. Retry through https://api.chrt.co, and contact support if it persists.
    • ip_allowlist_unavailable: a temporary problem on our side. Keys without an allowlist are not affected.

    Clearing the list removes the restriction. See Authentication.

    429 Too Many Requests — two variants

    Check the error field — a 429 is one of two very different things:

    errorMeaningClears
    rate_limit_exceededPer-minute sliding window tripped (too many requests too fast)Within seconds — honor Retry-After
    monthly_limit_exceededYour monthly tile-serve / feature-call cap is used upNot until resets_at (next billing period)

    For the per-minute case, back off and retry using the Retry-After header. For the monthly cap, retrying won't help — raise your caps in /app/limits, enable overage, or upgrade your plan. See Rate Limits for the per-plan numbers.

    backoff.ts
    async function fetchWithBackoff(url: string, maxRetries = 4): Promise<Response> {
      for (let attempt = 0; attempt < maxRetries; attempt++) {
        const res = await fetch(url, { headers: { "x-api-key": API_KEY } });
    
        if (res.status !== 429) return res;
    
        const body = await res.clone().json().catch(() => ({}));
        // Monthly cap won't clear by retrying — surface it instead.
        if (body.error === "monthly_limit_exceeded") return res;
    
        const retryAfter = Number(res.headers.get("Retry-After")) || 2 ** attempt;
        await new Promise((r) => setTimeout(r, retryAfter * 1000));
      }
      throw new Error("Rate limited: exhausted retries");
    }

    Empty results or 404 — no data where you expect it

    The request succeeded but returned nothing, or a 404 not_found. Usual culprits:

    • Swapped bbox coordinates. CHRT expects bbox=west,south,east,north (longitude first). Passing lat,lng order silently returns an empty set.
    • Outside your coverage. The area is real but not in a chart source your plan includes.
    • Zoom too high, or wrong tileset/source-layer. Detail only exists where the source ENC provides it.
    bbox.ts
    // ✅ Correct — west, south, east, north (Boston Harbor)
    const bbox = "-71.0557,42.3601,-71.0402,42.3735";
    
    // ❌ Wrong — lat,lng order returns no data
    const wrong = "42.3601,-71.0557,42.3735,-71.0402";
    
    const res = await fetch(`https://api.chrt.co/v1/features?bbox=${bbox}`, {
      headers: { "x-api-key": API_KEY },
    });

    Chart tiles don't appear on the map

    The basemap loads but CHRT chart data is missing. Work through these:

    • CHRT serves vector tiles, not raster. Tiles are Mapbox Vector Tiles (.pbf / MVT), not .png images. Add them as a vector source and draw layers from asource-layer (e.g. DEPARE) — a raster/image source will render nothing.
    • Always go through api.chrt.co. Never hardcode Supabase or upstream tile URLs — the gateway handles auth, coverage, and provenance. The SDK's styleUrl() / transformRequest() do this for you.
    • Authenticate the tile requests. Attach x-api-key via transformRequest, or use style.json?key=…. Check the browser Network tab for 401/403 on tile requests.
    map.ts
    import { Chrt } from "@chrtco/sdk";
    import maplibregl from "maplibre-gl";
    
    const chrt = new Chrt("YOUR_API_KEY");
    
    const map = new maplibregl.Map({
      container: "map",
      style: chrt.styleUrl(),                 // vector style via api.chrt.co
      transformRequest: chrt.transformRequest(), // adds x-api-key to every tile request
      center: [-70.86, 42.02],
      zoom: 12,
    });

    CORS errors in the browser

    A console error like "Access to fetch … has been blocked by CORS policy" almost always means one of two things:

    • You're using a secret key client-side. Only public keys (chrt_pk_…) are valid from a browser. Secret keys (chrt_sk_…) are server-only and must never ship to the client.
    • You're calling something other than api.chrt.co. The gateway returns Access-Control-Allow-Origin: * on every response, so any origin may call it from a browser. A CORS failure means the request never reached the gateway — check the host and path.

    A key's Allowed domains setting is not the cause of a CORS error — the gateway returns Access-Control-Allow-Origin: * to every origin. A blocked origin gets a 403 Domain not allowed response, not a CORS failure.

    Still stuck?

    • Full status-code reference: Error Codes.
    • Live service status and incidents: Status (or status.chrt.co).
    • Email [email protected]. Include your key prefix (first and last 4 chars — never the full key), the request URL, the full error JSON, the HTTP status, a timestamp, and the bbox/coordinates involved.

    For situational awareness only — not for primary navigation. CHRT is not an ECDIS and is not SOLAS-compliant.

    CHRT uses only the cookies and local storage the site needs to work — keeping you signed in, remembering your preferences, and protecting the forms. There is no analytics, no advertising and no cross-site tracking, so there is nothing here to opt out of. Privacy Policy