Learn how to authenticate to the Public API and make your first request.
Prefer not to write code? Connect Claude, ChatGPT, or Perplexity to your Public account with our hosted MCP server and trade using natural language.
Set up the hosted MCP →Go to the settings page and generate a secret key.
Important: Keep your secret keys secure and never expose them in client-side code.
Use the secret key to exchange for an access token.
curl --request POST \
--url https://api.public.com/userapiauthservice/personal/access-tokens \
--header 'Content-Type: application/json' \
--data '{
"validityInMinutes": 123,
"secret": "YOUR_SECRET_KEY"
}'Receive an access token in the response:
{
"accessToken": "YOUR_ACCESS_TOKEN"
}Subsequently you use the accessToken to authenticate any API request:
Authorization: Bearer YOUR_ACCESS_TOKENHere's how to make your first API request to get account information:
curl --request GET \
--url https://api.public.com/userapigateway/trading/account \
--header 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
--header 'Content-Type: application/json'A successful response will return a JSON object with the account information:
{
"accounts": [
{
"accountId": "string",
"accountType": "BROKERAGE",
"optionsLevel": "NONE",
"brokerageAccountType": "CASH",
"tradePermissions": "BUY_AND_SELL"
}
]
}The API returns standard HTTP status codes. Here are some common error responses:
Invalid or missing access token
{
"error": "Unauthorized",
"message": "Invalid access token"
}Invalid request parameters
{
"error": "Bad Request",
"message": "Error message"
}