Skip to main content
This means you must obtain an access token (and accompanying refresh token) using your API key credentials before calling private endpoints. Public API methods (market data, etc.) do not require authentication, but authenticated connections have higher rate limits and more features (raw event feed). This guide explains how to set up API keys, authenticate with the Deribit API, manage tokens (including fork_token usage), and handle access scopes for different permission levels. Example of a JSON request with token:
The API consists of public and private methods. The public methods do not require authentication. The private methods use OAuth 2.0 authentication. This means that a valid OAuth access token must be included in the request, which can be achieved by calling method public/auth. When the token was assigned to the user, it should be passed along, with other request parameters, back to the server:

Creating and Managing API Keys

Before authenticating, create an API key in your Deribit account. You can choose either a Deribit-generated key (for Client ID/Secret credentials authentication) or a self-generated key (for asymmetric signature authentication).
For detailed steps on generating API keys, see the Creating new API key on Deribit and Asymmetric API keys articles.

Two-Factor Authentication using API

Certain private methods in the Deribit API (for example, withdrawals or security-related account actions) require Two-Factor Authentication (2FA). If your account has 2FA enabled, you must provide the second factor when calling these methods via API.
API requests without the required 2FA confirmation will be rejected with the error security_key_authorization_error (code: 13668). Always ensure your application flow supports sending the second factor where required.
See the Security Keys section in the API docs for the technical details on confirming operations with 2FA or hardware keys. For enabling and managing 2FA in your account, follow the steps in Two-Factor Authentication Article.

Authentication Methods

Deribit’s primary authentication endpoint is public/auth. Calling this will return a JSON object containing an access_token and a refresh_token, among other fields.
Use your Client ID and Client Secret directly to get a token (suitable for server-to-server API use). This is the simplest method – you supply grant_type=client_credentials, along with your client_id and client_secret.

Best for

Server-to-server applications, simple integrations, quick setup

Client Credentials

Example – Client Credentials Flow

Below is a sample request using client credentials, and the response structure:
On success, you receive a JSON response like:
The access_token is a long string (truncated above) which is used to authenticate subsequent requests. The expires_in field (in seconds) tells you how long the token is valid, and refresh_token can be stored to renew your access when needed. The scope shows the granted access scope of this token (more on scopes below), and token_type will be “bearer”.

Using the token

Once you have an access token, you must include it with any private API request. How to include it depends on the connection type:
If you authenticated a WebSocket connection with a session token (see Connection Management - Best Practices), the server will remember your token, allowing you to omit the token in subsequent requests on that same WebSocket connection.
Manage your tokens securely: store refresh tokens if you need long-lived access, and treat access tokens like passwords (never expose them publicly).

Client Signature (WebSocket)

The signature formula shown below is for WebSocket connections. For HTTP REST requests, use a different formula that includes HTTP method, URI, and request body. See the Deribit Signature Credentials (HTTP REST) section below for HTTP REST authentication.

Client Signature Authentication

To perform a client signature authentication for WebSocket connections:
  1. Prepare the components:
    • grant_type – Must be client_signature
    • client_id and client_secret – Can be found on the API page on the Deribit website after creating the API key
    • timestamp – Time when the request was generated, given as milliseconds. It is valid for 60 seconds since generation; after that, any request with an old timestamp will be rejected
    • signature – Value for the signature calculated as described below
    • nonce – Single-use, user-generated initialization vector for the server token
    • data – Optional field, which contains any user-specific value
  2. Build the string to sign:
Deribit’s client-signature flow signs a very specific byte sequence. Use HMAC‑SHA256 with your Client Secret as the key and hex‑encode the digest. Formula:
Important details:
  • Always include the two newline characters shown above.
  • If Data is omitted, treat it as an empty string, so the string still ends with \n after Nonce.
  • Use UTF‑8 for all strings.
  • Send the lowercase hex of the HMAC as signature.
  • timestamp is milliseconds since epoch. nonce should be unique per request.

Shell (OpenSSL) one‑liner

General form, works on Linux and macOS:

Example

  1. Send the request:
Call public/auth with grant_type=client_signature and include:
  • client_id
  • timestamp
  • nonce
  • signature (the HMAC you calculated)
  • data (if used in the signature)
Sample JSON-RPC request using values calculated before:

Parameters

When connecting through WebSocket, user can request for authorization using client_signature method, which requires providing following parameters (as a part of JSON request):
You can check the signature value using online tools like codebeautify.org/hmac-generator (remember that you should use it only with your test credentials).
On success, the server returns an access_token and refresh_token, the same as with client credentials authentication.

Python Example

You can also use the following Python code to automatically generate the signature and complete the authentication process on test environment:

Refresh Token

When you authenticate with public/auth (using client credentials or client signature), the response contains both an access_token and a refresh_token.
  • access_token – used to authorize your API calls (via Authorization: Bearer <token> in HTTP or as access_token in WebSocket requests).
  • refresh_token – used to obtain a new access token once the current one expires.

Why use a refresh token?

Access tokens have a limited lifetime (defined in the expires_in field). Instead of re-supplying your Client ID and Client Secret each time, you can call public/auth again with grant_type=refresh_token and your stored refresh token. This extends the session securely without exposing your credentials.

Example

Response contains a new access_token (and a new refresh_token).

Session behavior

  • If your token was issued with a session scope, refreshing keeps the same session active and does not consume extra session slots.
  • If you did not request a session scope, each refresh generates a new connection-scoped token and invalidates the previous one.

Best practices

  • Always keep your refresh token secure. It can be used to mint new access tokens.
  • Implement automatic refresh shortly before expiry (check the expires_in value).
  • Persist the latest refresh token if your application restarts.

Fork and Exchange Tokens

Fork Token

Session tokens can be “cloned” using the public/fork_token method. This is an advanced feature to help manage multiple sessions. public/fork_token takes a valid refresh token from an existing session-scoped token and generates a new access token for a new session (with a name you specify). In other words, it lets you fork an existing session into another session without re-supplying your client secret. This is only allowed for session-scoped tokens (you cannot fork a connection-only token).

When to use fork token?

Suppose you have an application already authenticated on one server and you want to spin up a second client (or a sub-service) using the same account and API key. Instead of storing the Client Secret or asking for credentials again, you can take the refresh token from the first session and call public/fork_token to create a new session token for the second client. The new token will have the same scopes as the original (but tied to a different session name). Both sessions can operate concurrently under the same API key.

Exchange Token

public/exchange_token lets you turn a refresh token into a new access token for a different subaccount. A subject_id identifies the target subaccount, so this method is the standard way to switch between subaccounts without sending your Client Secret again. The resulting token keeps the same permissions unless you supply a scope override.

When to use exchange token?

You are authenticated on one subaccount and need to act on another subaccount with the same API key. Call public/exchange_token with:
  • refresh_token from your current session
  • subject_id of the destination subaccount
  • optional scope to override scopes and to set a session:name if you want a session token created during the exchange. Scopes on the new token cannot exceed the permissions of the caller.

Alternative Authentication Methods

For convenience, Deribit also supports two alternative methods for HTTP requests: Basic Auth and HMAC Auth (Deribit Signature Credentials). These methods eliminate the need for a prior token request, but are typically used in advanced scenarios or if you prefer not to handle token refresh separately. Most developers find it simplest to use public/auth to get a bearer token and use that for subsequent calls.

Basic User Credentials

Every private method can be accessed by providing an HTTP Authorization: Basic XXX header with user ClientId and assigned ClientSecret (both values can be found on the API page on the Deribit website) encoded with Base64:
This is the easiest way of authenticating HTTP (REST) requests. If you don’t like the fact that you are sending ClientSecret over HTTPS connection, you can consider using one of the authorization methods described below.

Deribit Signature Credentials (HTTP REST)

The Deribit service provides a dedicated authorization method that uses user-generated signatures to increase security when passing request data. The generated value is passed in the Authorization header:
Important: The signature formula for HTTP REST requests is different from WebSocket requests. For HTTP REST, you must include the HTTP method, URI, and request body in the signature calculation.

Signature Formula for HTTP REST

Note: The newline characters in RequestData and StringToSign variables are important. If RequestBody is omitted in RequestData, it’s treated as an empty string, so these three newline characters must always be present.

Example – HTTP REST Signature

Parameters

Logout

Finally, you can log out and invalidate tokens using private/logout (WebSocket only) if needed, but generally tokens will expire automatically after their expires_in duration.
Logging out with private/logout does not trigger Cancel on Disconnect. Any outstanding orders or quotes will remain active unless explicitly canceled.