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:
| Connection type | Access token placement |
|---|---|
| WebSocket | Inside request JSON parameters, as an access_token field |
| HTTP (REST) | Header Authorization: Bearer <Token> value |
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).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.Authentication Methods
Deribit’s primary authentication endpoint ispublic/auth. Calling this will return a JSON object containing an access_token and a refresh_token, among other fields.
- Client Credentials
- Client Signature
- Refresh Token
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: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:| Connection type | Access token placement |
|---|---|
| WebSocket | Inside request JSON parameters, as an access_token field |
| HTTP (REST) | Header Authorization: Bearer <Token> value |
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.
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:-
Prepare the components:
grant_type– Must beclient_signatureclient_idandclient_secret– Can be found on the API page on the Deribit website after creating the API keytimestamp– 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 rejectedsignature– Value for the signature calculated as described belownonce– Single-use, user-generated initialization vector for the server tokendata– Optional field, which contains any user-specific value
- Build the string to sign:
- Always include the two newline characters shown above.
- If Data is omitted, treat it as an empty string, so the string still ends with
\nafter Nonce. - Use UTF‑8 for all strings.
- Send the lowercase hex of the HMAC as signature.
timestampis milliseconds since epoch.nonceshould be unique per request.
Shell (OpenSSL) one‑liner
General form, works on Linux and macOS:Example
- Send the request:
public/auth with grant_type=client_signature and include:
client_idtimestampnoncesignature(the HMAC you calculated)data(if used in the signature)
Parameters
When connecting through WebSocket, user can request for authorization usingclient_signature method, which requires providing following parameters (as a part of JSON request):
| JSON parameter | Description |
|---|---|
| grant_type | Must be client_signature |
| client_id | Can be found on the API page on the Deribit website (the user can configure up to 8 different IDs - with different privileges) |
| timestamp | Time when the request was generated - given as milliseconds. It’s valid for 60 seconds since generation, after that time any request with an old timestamp will be rejected. |
| signature | Value for signature calculated as described above |
| nonce | Single usage, user generated initialization vector for the server token |
| data | Optional field, which contains any user specific value |
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 withpublic/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 asaccess_tokenin 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 theexpires_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
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_invalue). - Persist the latest refresh token if your application restarts.
Fork and Exchange Tokens
Fork Token
Session tokens can be “cloned” using thepublic/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 callpublic/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. Callpublic/exchange_token with:
refresh_tokenfrom your current sessionsubject_idof the destination subaccount- optional
scopeto override scopes and to set asession:nameif 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 usepublic/auth to get a bearer token and use that for subsequent calls.
Basic User Credentials
Everyprivate 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 theAuthorization header:
Signature Formula for HTTP REST
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
| Deribit credential | Description |
|---|---|
| ClientId | Can be found on the API page on the Deribit website (the user can configure up to 8 different IDs - with different privileges) |
| Timestamp | Time when the request was generated - given as milliseconds. It’s valid for 60 seconds since generation, after that time any request with an old timestamp will be rejected. |
| Signature | Value for signature calculated as described above |
| Nonce | Single usage, user generated initialization vector for the server token |
Logout
Finally, you can log out and invalidate tokens usingprivate/logout (WebSocket only) if needed, but generally tokens will expire automatically after their expires_in duration.