Looking for other authentication documentation?
- Coinbase App APIs: For accessing consumer Coinbase accounts, see Coinbase App Authentication
- CDP v2 APIs: For the latest CDP authentication with Ed25519 support, see CDP v2 Authentication
- Secret API Keys: For server-to-server communication (i.e., REST APIs).
- Client API Keys: For client-side communication (i.e., JSON-RPC).
Prerequisites
It is assumed you are logged into an existing CDP account (if not, create one).1. Create an API key
Your CDP account should include a project by default. Navigate to your API keys dashboard. From the top drop-down, select your desired project.
Server
To create a Secret API key (for server-to-server communication), ensure the Secret API Keys tab is selected as shown in the previous step. Click the Create API key button and give your key a name. You also have the option to:- Set an IP allowlist for the key
- Restrict granular permissions such as the ability to trade or transfer funds
- Select between Ed25519 (Recommended) or ECDSA signature algorithms
Optional API Key File DownloadFor enhanced security, API key files are no longer automatically downloaded. If you need to reference your API key via file path in your code, click the Download API key button in the modal to save the key file. However, it is recommended to copy the key details directly from the modal and use them as environment variables for better security.
To regenerate a Secret API key, click Configure to delete and recreate the key.
Client
To create a Client API key (for use in front-end components) ensure the Client API Key tab is selected.
Click the Rotate button to expire this key and generate a new one.
2. Generate JWT (Server only)
You can generate a JSON Web Token (JWT) using the following code snippets.More on JWTs
More on JWTs
A JWT is a compact, self-contained, stateless token format used to securely transmit API keys as a JSON object for authentication with the CDP API.Read more in our JWT documentation.
- Set up your environment for JWT generation by configuring environment variables and installing dependencies
- Export your generated JWT as an environment variable
Never include Secret API key information in your code.Instead, securely store it and retrieve it from an environment variable, a secure database, or other storage mechanism intended for highly-sensitive parameters.
Setup
To begin, export the following environment variables:KEY_NAME
: The name of the API key you want to useKEY_SECRET
: The secret of the API key you want to useREQUEST_METHOD
: The HTTP method of the endpoint you want to targetREQUEST_PATH
: The path of the endpoint you want to targetREQUEST_HOST
: The host of the endpoint you want to target
Newlines must be preserved to properly parse the key secret. Do this on one line by using \n to escape new lines, or via a multi-line string.
Install required dependencies:
Export
Now that your environment is setup, you can create the code to generate the JWT and export it as an environment variable.Your JWT is valid for 2 minutes. After 2 minutes, you will need to generate a new JWT to ensure uninterrupted access to the CDP APIs.
Create a new file for JWT generation code:It should contain the following:Finally, run the script to generate the JWT output and export it as an environment variable.
main.py
3. Authenticate
Server
To authenticate your server-side code, use the JWT token you generated in the previous step as a Bearer Token within your request:Client
To authenticate your client-side code, include it with your JSON-RPC request:What to read next
- Security Best Practices: Learn how to secure your API keys and other sensitive information.
- CDP API Keys: Learn how to create and manage your API keys.
- JWT Authentication: More information on JWT authentication.
- CDP cURL: Learn how to use our CLI tool to interact with the CDP API.
- Postman Files: Download our Postman collection and environment files to get started.