Skip to content

Authentication with an API key

13 min read

This page explains how to authenticate with the Ferry system using an API key: passing the HTTP header, key structure, resource permission scopes, key lifecycle states (pause, revoke, zero-downtime rotation with grace, expiration), optional per-key rate limits, and how to distinguish authentication error codes.

Every request sent to partner-tier endpoints must include the API key in the HTTP request header using standard Bearer format:

Authorization: Bearer <API_KEY>

The Ferry system reads only the Authorization header. X-API-Key or any other custom header has no authentication effect.

A complete API key consists of 3 parts joined by underscores (_):

  1. System prefix: A prefix string configured by Ferry per environment. Partners do not need to parse or split the prefix; simply send the issued key string verbatim.
  2. Key identifier: A 24-character hexadecimal string identifying the key record in the system.
  3. Secret token: A 64-character cryptographically random hexadecimal string. Ferry stores only its SHA-512 hash and compares secrets in constant time.

This documentation never prints a sample key string. Always send the issued key string verbatim without trimming, prepending, or modifying any character.

The diagram below illustrates the authentication, lifecycle validation, rate-limit, and authorization flow for an API request:

sequenceDiagram
autonumber
participant Partner as Partner System
participant Gateway as Ferry API Gateway
participant Auth as Key Auth Layer
participant Perm as Permission Layer
participant Core as Business Layer
Partner->>Gateway: Send request with Authorization header
Gateway->>Auth: Lookup key, verify hash, check status and expiry
alt Missing header, wrong secret, or not found
Auth-->>Partner: 401 Unauthorized (Invalid API Key)
else Valid secret but revoked, disabled, or expired
Auth-->>Partner: 401 with ApiKeyRevoked / ApiKeyDisabled / ApiKeyExpired
else Source IP outside allowlist
Auth-->>Partner: 403 with ApiKeyIpNotAllowed
else Per-key rate limit exceeded
Auth-->>Partner: 429 with ApiKeyRateLimited and Retry-After
else Key valid
Auth->>Perm: Pass organization context and key scopes
alt Missing scope or transient authorization outage
Perm-->>Partner: 403 (ApiKeyScopeDenied / Access denied)
else Authorized
Perm->>Core: Execute business logic
Core-->>Partner: 200 OK with response payload
end
end

Partners cannot create API keys through public API endpoints. Key creation is restricted to agency users holding the admin role on the web Dashboard interface.

Steps to create a key on the Dashboard:

  1. An administrator signs in to the agency Dashboard, opens the Settings menu, switches to the API Keys tab, and clicks Add New.

    API Keys tab in Dashboard Settings showing the Add New button
    API Keys tab in Dashboard Settings showing the Add New button
  2. Enter a descriptive name for the key (such as the integrating service name), select scopes, optional expiration date, per-minute rate limit, and IP allowlist if needed, then click Create New.

    Create API Key dialog with key name field and Create New action
    Create API Key dialog with key name field and Create New action
  3. A confirmation dialog displays the newly generated key. Click the copy icon to save the full key string into your secret manager.

    Dialog displaying the newly created API key with one-time copy warning
    Dialog displaying the newly created API key with one-time copy warning

For complete Dashboard operational instructions, see API Key Management on Dashboard.

Each key carries a primary state and several optional constraints:

StateMeaningReversible
activeOperational (subject to expiration, IP allowlist, rate limit, and scope checks)—
disabledPaused; every request returns 401 ApiKeyDisabledYes, via Re-enable on Dashboard
revokedRevoked; every request returns 401 ApiKeyRevokedNo. Record is retained for audit history

Key metadata on the Dashboard also exposes a computed effective_status of active, disabled, revoked, or expired (expired when a key is active but past expires_at).

Optional attributes:

  • Expiration (expires_at): Up to 2 years from when it is set; leaving it blank means no expiration. Expired keys return 401 ApiKeyExpired. Legacy keys and keys created with only a name have no expiration.
  • Permission scopes (scopes): Detailed in the next section.
  • Per-key rate limit (rate_limit_per_minute): 10–10,000 requests/minute; leaving it blank applies only the global per-IP rate limits.
  • IP allowlist (allowed_ips): Up to 50 IPv4/IPv6/CIDR entries; leaving it blank allows any source IP.

Key revocation is a soft revocation: the record and audit trail remain visible under the Revoked tab on the Dashboard, while the original hash is moved aside and the primary hash overwritten so the key can never authenticate again even across rollbacks. Pausing, re-enabling, and revoking are performed by agency administrators on the Dashboard; invalid state transitions (such as re-enabling an already active key) return HTTP 409.

Each API key is bound to a single agency organization and acts on behalf of that organization. Alongside organization-level authorization (deciding which organization a key can access), the key carries resource scopes deciding what kind of work it may perform.

A key holds a list of scopes formatted as <resource>:read or <resource>:write. Core rules:

  • write implies read on the same resource: a key with bookings:write can also read bookings.
  • * grants full access across all resources, matching legacy key behavior.
  • * cannot be mixed with explicit scopes on the same key.
ResourceCoverage
authSign-up, sign-in, OTP verification, social login (supports write only)
voyagesVoyage schedules, seat counts, boat layouts, ticket price additions, and voyage disruption lookups (/api/v1/disruptions, /api/v1/disruptions/{id}, /api/v1/bookings/{id}/disruptions)
bookingsBookings, booking email notifications, orders, ticket cancellation requests
customersCustomers, companies, leads
paymentsFinancial transactions, debt ledgers
vouchersVouchers and voucher applicability checks
reportsRevenue and operational reports
organizationsOrganization profile, settings, and child organizations
filesStored file assets

By default, required access follows the HTTP method: GET, HEAD, and OPTIONS require read, while other methods require write. Several read-only queries that use POST are explicitly mapped to read: vouchers/check-aplicability, ticket-price-additions/check, organizations/settings/check-slug, and files/getFile/:id. By contrast, organizations/settings/check-smtp-config requires write because it opens an outbound SMTP connection using supplied parameters.

Querying voyage disruption endpoints (/api/v1/disruptions, /api/v1/disruptions/{id}, /api/v1/bookings/{id}/disruptions) requires both the voyages:read scope (or voyages:write / *) on the API key and the view_disruption permission on the organization; missing the organization permission returns 403 Access denied (see Voyage search and remaining seats).

When creating a key on the Dashboard, you can pick a preset instead of selecting individual scopes:

PresetIncluded scopes
full* — full access, matching legacy keys
read_onlyEvery readable partner resource (voyages:read, bookings:read, customers:read, payments:read, vouchers:read, reports:read, organizations:read, files:read)
tenant_websiteThe 4 partner scopes called with an organization key by a branded booking website: auth:write, voyages:read, vouchers:read, organizations:read. Bookings, payments, customers, and files are called from the browser with the visitor’s session JWT rather than the org key, so this preset omits them
partner_otavoyages:read, bookings:write, payments:read

No restricted preset other than full includes organizations:write.

Widening permissions requires admin authority

Section titled “Widening permissions requires admin authority”

Adding scopes (or switching to *), removing IP allowlist entries, raising or removing rate_limit_per_minute, or extending/removing expires_at constitutes permission widening and requires administrator authority equivalent to creating a key. Non-admin users delegated to edit keys can only narrow constraints; widening attempts return 403 ApiKeyWideningForbidden.

Important authorization boundaries and risks:

  • Risk of *: A full-access key can create, modify, and delete child organizations within your agency hierarchy. A leaked * key can be abused to delete sub-agencies.
  • No access to internal areas: API keys cannot perform Ferry system administration or invoke Dashboard endpoints requiring user session JWTs.
  • Missing response fields due to role serialization: API keys belong to the api-key serialization group. Responses include only fields explicitly exposed to this group. If a field appears on the Dashboard (such as detailed commission breakdowns) but is absent from an HTTP 200 API response, that field is not exposed to api-key. This is not a scope error (no 403 is returned); contact Ferry to expose required fields rather than retrying with query parameters.

Alongside global per-IP throttling (see Rate limits), each key can configure rate_limit_per_minute between 10 and 10,000. The counter uses a fixed 1-minute window evaluated independently per key.

  • Keys without a per-key limit: responses omit RateLimit-* headers.
  • Keys with a per-key limit: every successful response includes RateLimit-Limit, RateLimit-Remaining, and RateLimit-Reset.
  • When exceeded: HTTP 429 with error code ApiKeyRateLimited, accompanied by Retry-After (seconds), RateLimit-Limit, RateLimit-Remaining: 0, and RateLimit-Reset.
  • Fixed windows allow up to 2× burst across a minute boundary (end of one minute plus start of the next). This is an intentional trade-off to keep counting predictable.
  • If Ferry’s Redis cluster experiences an outage, per-key rate limiting fails open and logs internally so live partner traffic is not blocked.

Seven-day usage statistics (daily request counts and throttled counts) are visible in the key detail drawer on the Dashboard.

A key can restrict callers to specific IPv4/IPv6 addresses or CIDR blocks. When allowed_ips is non-empty and the feature is enabled for the environment, requests from unlisted IPs receive 403 ApiKeyIpNotAllowed.

This feature is disabled by default until client IP forwarding is verified for the environment. While disabled, submitting allowed_ips returns 422 ApiKeyIpAllowlistDisabled.

There are two ways to rotate an API key; prefer the first method.

Method 1 — Rotate with grace (zero downtime)

Section titled “Method 1 — Rotate with grace (zero downtime)”

The Rotate key action on the Dashboard creates a replacement key inheriting the same name, scopes, IP allowlist, and per-minute rate limit, returning the new key string once. The previous key continues authenticating during the chosen grace window:

GraceBehavior
nonePrevious key is revoked immediately; calls using it receive 401 ApiKeyRevoked
1h, 24h, 7dPrevious key remains valid for that duration, never exceeding its original expires_at

Procedure:

  1. An administrator clicks Rotate key with grace 24h (or 7d for slower rollouts) and saves the new key string.
  2. Deploy the new key to environment variables across all backend instances.
  3. Verify that 100% of live workers and background jobs have switched to the new key.
  4. Once the grace window elapses, the old key expires automatically with no further action needed.

The new key becomes active before the rotation response returns (permissions are committed synchronously), so deploying it immediately never causes transient 403 errors.

Only active keys can be rotated. Disabled, revoked, expired, or already-rotated keys return 409 — re-enable a paused key first or create a fresh key instead.

Method 2 — Create a new key, then revoke the old key

Section titled “Method 2 — Create a new key, then revoke the old key”
  1. Create a new key (matching scopes and limits) and store the key string.
  2. Deploy the new key across your backend servers.
  3. Confirm all traffic has migrated to the new key.
  4. Click Revoke on the old key in the Dashboard (this action is irreversible).

With this method, the old key stays alive until manually revoked, giving manual cutover control without automatic expiration.

If a key is leaked and active compromise is suspected, prioritize stopping abuse: pause the key immediately (if brief downtime is acceptable) or rotate with grace none, then deploy the replacement key.

Once the secret hash matches, Ferry evaluates checks in strict order: revoked → disabled → expired → IP allowlist → per-key rate limit → resource scope. Whenever the secret itself is wrong, Ferry returns a single generic 401 response, never revealing whether a key ID exists or its current state.

HTTP CodeError code (error)Root causeResolution
401(none) — Invalid API KeyMissing header, bad format, unknown key ID, or wrong secretCheck Authorization: Bearer <key> syntax; paste the full key verbatim
401ApiKeyRevokedKey was revoked, or rotation grace window endedSwitch to the rotated replacement key or create a new key
401ApiKeyDisabledKey is currently pausedAsk an agency administrator to re-enable it on the Dashboard
401ApiKeyExpiredCurrent time passed expires_atCreate a new key (expired keys cannot be rotated and return 409)
403ApiKeyIpNotAllowedSource IP is outside allowed_ipsSend requests from an approved egress IP or update the allowlist
429ApiKeyRateLimitedExceeded rate_limit_per_minuteWait for Retry-After seconds before retrying
403ApiKeyScopeDeniedKey lacks required scope; includes required field (e.g. bookings:write)Add the required scope (admin required) or use an appropriately scoped key
403ApiKeyScopeUnmappedTarget route lacks a resource mapping on FerryReport to Ferry; this indicates a server-side route declaration issue
403Access deniedOrganization permission layer denied access or suffered a transient glitchIf sudden on a previously working route, retry once with backoff, then contact Ferry

Important notes:

  • Generic 401 responses on wrong secrets intentionally omit whether the format, key ID, or secret failed.
  • 403 Access denied from the organization authorization layer does not distinguish missing organization permissions (such as view_disruption) from transient authorization service glitches. If 403 errors appear suddenly on working endpoints, retry briefly with backoff before concluding permissions changed.
  • Lifecycle 401 codes (ApiKeyRevoked, ApiKeyDisabled, ApiKeyExpired) appear only when the secret hash matched; never rely on them to probe keys.
MisconceptionRealityCorrect practice
Sending the key via custom headersFerry reads only the Authorization headerAlways send Authorization: Bearer <key>
Embedding keys in mobile or browser appsKeys act on behalf of your agency organizationKeep keys strictly on backend servers
Revoking the old key before deploying the new oneRevocation is immediate and breaks live trafficUse Rotate with grace, or deploy a new key first
Assuming every key has full accessScoped keys (e.g. bookings:read) return 403 on other resourcesInspect required in ApiKeyScopeDenied and choose matching scopes/presets
Assuming keys expire automatically by defaultOnly keys configured with expires_at expireSet expires_at when policy requires it and monitor effective_status
Assuming 403 always means a revoked key403 also signals missing scope, unlisted IP, or authorization glitchesInspect the error code to identify the exact cause
Assuming missing response fields mean missing scopesCertain fields are not serialized for the api-key role groupContact Ferry to expose required fields for the API key role
Assuming revoking a key erases audit logsSoft revocation disables the key permanently while keeping history in RevokedUse Pause on the Dashboard if you only want a temporary halt

This guide corresponds to the Authorize button in the top bar of the Scalar UI — Ferry VN API portal.

To test endpoints in the Scalar interface:

  1. Click the Authorize button.
  2. Paste your API key into the Bearer token input.
  3. Call a simple read endpoint such as Voyages or Bookings to verify that your key authenticates properly.
GuideRecommended next reading
Integration surface overviewReview permission boundaries and partner-accessible business groups
Rate limitsGlobal per-IP throttling and optional per-key rate limits
EnvironmentsManaging separate keys across the UAT sandbox and Production
WebhooksStandard Webhooks signature verification, deduplication, and retry schedule
API Key Management on DashboardStep-by-step Dashboard guide for agency administrators