Brokeret LogoDocs
Getting Started/Authentication

Authentication

Learn how to authenticate your API requests using API keys and tokens.

Overview

All Brokeret API requests require authentication. We support two authentication methods depending on your use case:

MethodUse CaseSecurity Level
API Key + SecretServer-to-server integrationHigh
OAuth 2.0Third-party applications acting on behalf of usersHigh

API Key Authentication

Include your API key in the Authorization header using the Bearer scheme:

Authorization: Bearer bk_live_a1b2c3d4e5f6g7h8i9j0

For additional security, sign requests with your API Secret using HMAC-SHA256:

$timestamp = time();
$payload = $timestamp . $method . $path . $body;
$signature = hash_hmac('sha256', $payload, $apiSecret);

// Include in headers
X-Brokeret-Timestamp: 1710000000
X-Brokeret-Signature: a1b2c3d4...

Environments

We provide separate environments for development and production:

EnvironmentBase URLKey Prefix
Sandboxhttps://sandbox.api.brokeret.combk_test_
Productionhttps://api.brokeret.combk_live_
💡
TipUse sandbox keys during development. They connect to simulated trading servers and won't affect real accounts.

Error Responses

Authentication errors return a 401 Unauthorized status with details:

{
  "error": {
    "code": "invalid_api_key",
    "message": "The API key provided is invalid or has been revoked.",
    "doc_url": "https://docs.brokeret.com/authentication#error-responses"
  }
}

Common Error Codes

CodeDescriptionResolution
invalid_api_keyAPI key is malformed or does not existCheck your key and regenerate if needed
expired_api_keyAPI key has expiredRotate your key in the dashboard
invalid_signatureHMAC signature does not matchVerify timestamp, method, path, and body encoding
ip_not_whitelistedRequest IP is not in the allowed listAdd the IP in Settings → Security

Best Practices

  • Never expose secrets client-side — API secrets must only be used in server-side code
  • Rotate keys regularly — We recommend rotating keys every 90 days
  • Use IP whitelisting — Restrict production keys to known server IPs
  • Monitor usage — Review API access logs in your dashboard for anomalies
  • Use environment variables — Never hardcode credentials in source code