Authentication

Access to the API is controlled by API tokens. Each token is tied to your Ocean.io account and inherits the permissions of your subscription plan.

Generating a token#

  1. Sign in to your Ocean.io account
  2. Navigate to Account Settings → API Tokens
  3. Click Generate new token
  4. Copy the token and store it securely — it will not be shown again

Note

Treat your API token like a password. Do not commit it to version control or expose it in client-side code.

Authenticating requests#

Include your token on every request using one of the following methods. Do not use both simultaneously — this will result in a 400 error.

Method 1 — Request header (recommended):

curl -X GET "https://api.ocean.io/v2/credits/balance" \
  -H "X-Api-Token: YOUR_API_TOKEN"
import requests

response = requests.get(
    'https://api.ocean.io/v2/credits/balance',
    headers={'X-Api-Token': 'YOUR_API_TOKEN'},
)
const response = await fetch('https://api.ocean.io/v2/credits/balance', {
  headers: { 'X-Api-Token': 'YOUR_API_TOKEN' },
});

Method 2 — Query parameter:

curl -X GET "https://api.ocean.io/v2/credits/balance?apiToken=YOUR_API_TOKEN"
import requests

response = requests.get(
    'https://api.ocean.io/v2/credits/balance',
    params={'apiToken': 'YOUR_API_TOKEN'},
)
const response = await fetch(
  'https://api.ocean.io/v2/credits/balance?apiToken=YOUR_API_TOKEN',
);

Headers don't appear in server logs or browser history — query parameters do.

Token errors#

Scenario Status code Response
Token missing from request 403 {"detail": "API token should be provided in headers or query parameters"}
Token is invalid or unrecognised 403 {"detail": "Invalid API token"}
Token provided in both header and query param 400 {"detail": "Conflicting API tokens provided in query parameters and headers"}

Rotating tokens#

If you suspect a token has been compromised, revoke it immediately in Account Settings and generate a new one. Update all systems using the old token before revoking to avoid downtime.