Overview
Bayse Markets API uses API key authentication with HMAC-SHA256 signatures for secure request verification. Authentication requirements vary by endpoint:- Public endpoints: No authentication required.
- Read endpoints: API key only (
X-Public-Keyheader). - Write endpoints: API key + timestamp + HMAC signature.
API key structure
API keys come in pairs:- Public key (
pk_*): Identifies your API key (safe to expose in headers). - Secret key (
sk_*): Used to sign requests (keep secure, never expose).
Authentication levels
Public endpoints
Some endpoints require no authentication:Read authentication
For read operations, include your public key in theX-Public-Key header:
GET /v1/pm/portfolio.GET /v1/pm/orders.GET /v1/pm/activities.
Write authentication
Write operations require three headers:- X-Public-Key: Your public API key.
- X-Timestamp: Current Unix timestamp (seconds).
- X-Signature: HMAC-SHA256 signature of the request payload (base64-encoded).
{timestamp}.{METHOD}.{path}.{bodyHash}
- timestamp: The same Unix timestamp sent in
X-Timestamp. - METHOD: The HTTP method in uppercase (e.g.,
POST,DELETE). - path: The request path (e.g.,
/v1/pm/orders/abc123). - bodyHash: SHA-256 hex digest of the request body. Empty string if there is no body.
POST /v1/pm/events/{eventId}/markets/{marketId}/orders.DELETE /v1/pm/orders/{orderId}.
Implementing HMAC signatures
How it works
- Get the current Unix timestamp (seconds since epoch).
- Build the signing payload:
{timestamp}.{METHOD}.{path}.{bodyHash}.- If the request has a JSON body,
bodyHashis the SHA-256 hex digest of the raw body bytes. - If there is no body,
bodyHashis an empty string (the payload ends with a trailing.).
- If the request has a JSON body,
- Compute the HMAC-SHA256 of the payload using your secret key.
- Base64-encode the result.
- Send in the
X-Signatureheader along withX-Timestamp.
Code examples
Social sign-in users
If you signed up for Bayse using Apple or Google, your account doesn’t have a password yet. The API requires email and password authentication to create and manage API keys. To set up a password:- Open the Bayse app and go to Forgot Password (or use the password reset flow).
- Enter the email associated with your Apple/Google account.
- Follow the instructions to create a password.
Setting a password does not change or remove your existing sign-in method. You can continue using Apple or Google to sign in to the Bayse app as usual. The password is only needed for API access.
Managing API keys
Getting a session token
Before you can create or manage API keys, you need to log in with your Bayse account credentials to get a session token and device ID:Response
Response
token and deviceId from the response as the x-auth-token and x-device-id headers for all API key management requests below.
The login endpoint is rate-limited to 1 request per 2 minutes per email address. Cache your session token and reuse it. See Rate limits for details.
Creating API keys
With your session token and device ID, create an API key:Response
Response
Listing API keys
Revoking API keys
Rotating API keys
Generate a new secret key while keeping the same public key:Response
Response
Security best practices
Store credentials securely
Store credentials securely
- Never commit API keys to version control
- Use environment variables or secrets managers
- Rotate keys regularly
- Use separate keys for development and production
Protect your secret key
Protect your secret key
- Never expose secret keys in client-side code
- Don’t log secret keys
- Revoke compromised keys immediately
- The secret key is only shown once - save it during creation
Implement proper error handling
Implement proper error handling
- Don’t expose secret keys in error messages
- Handle authentication errors gracefully
- Implement retry logic with exponential backoff
- Monitor for suspicious authentication patterns
Use HTTPS
Use HTTPS
- Always use HTTPS in production
- Verify SSL certificates
- Never send credentials over HTTP
Common errors
Invalid signature
- Incorrect secret key.
- Timestamp mismatch (signed different timestamp than sent in
X-Timestamp). - Wrong payload format — must be
{timestamp}.{METHOD}.{path}.{bodyHash}. - Body hash mismatch — the exact bytes sent in the request body must match what was hashed when signing. Avoid trimming or reformatting the body after signing.
- Incorrect HMAC algorithm (must be SHA-256).
- Incorrect encoding (signature must be base64, body hash must be hex).
Timestamp too old
X-Timestamp is too far in the past. Ensure your system clock is synchronized.
Missing API key
X-Public-Key header is missing or invalid.
Next steps
API reference
Explore all available endpoints
Prediction markets
Learn about prediction market operations
User endpoints
Manage your API keys programmatically