Skip to main content

Get your API credentials

Before you can trade on Bayse Markets programmatically, you need an API key pair.
This quickstart assumes you already have a Bayse Markets account. If not, sign up at link.bayse.markets.

Step 1: Create an API key

Create an API key in the Bayse web app at app.bayse.markets/settings/api-keys. Or in the web app, via More > Account Settings > API Keys in the Developer Tool section. If you prefer to manage API keys programmatically, see Manage API keys programmatically.
Save your secret key securely. You need it to sign write requests, and you may not be able to view it again later.

Step 2: Make a read request

Try a simple read request to list prediction market events:
curl -X GET "https://relay.bayse.markets/v1/pm/events?limit=10" \
  -H "X-Public-Key: pk_live_abcdef123456"
{
  "events": [
    {
      "id": "evt_123",
      "title": "Will it rain tomorrow?",
      "category": "weather",
      "status": "active",
      "markets": [
        {
          "id": "mkt_456",
          "question": "Yes or No?",
          "outcomes": ["Yes", "No"],
          "engine": "AMM"
        }
      ]
    }
  ],
  "pagination": {
    "total": 50,
    "limit": 10,
    "offset": 0
  }
}

Step 3: Make a signed write request

For write operations (like placing orders), you need to sign your request with HMAC-SHA256. The signing payload format is {timestamp}.{METHOD}.{path}.{bodyHash}:
# Set your credentials
PUBLIC_KEY="pk_live_abcdef123456"
SECRET_KEY="sk_live_secret789xyz"
TIMESTAMP=$(date +%s)
METHOD="POST"
URL_PATH="/v1/pm/events/evt_123/markets/mkt_456/orders"
BODY='{"side":"BUY","outcome":"YES","amount":100,"currency":"USD"}'

# Compute body hash and create signature
BODY_HASH=$(printf '%s' "$BODY" | openssl dgst -sha256 -hex 2>/dev/null | sed 's/.*= //')
PAYLOAD="${TIMESTAMP}.${METHOD}.${URL_PATH}.${BODY_HASH}"
SIGNATURE=$(printf '%s' "$PAYLOAD" | openssl dgst -sha256 -hmac "$SECRET_KEY" -binary | base64)

# Make the request
curl -X POST "https://relay.bayse.markets${URL_PATH}" \
  -H "X-Public-Key: ${PUBLIC_KEY}" \
  -H "X-Timestamp: ${TIMESTAMP}" \
  -H "X-Signature: ${SIGNATURE}" \
  -H "Content-Type: application/json" \
  -d "$BODY"
{
  "id": "ord_789",
  "eventId": "evt_123",
  "marketId": "mkt_456",
  "side": "buy",
  "outcomeIndex": 0,
  "amount": 100,
  "status": "filled",
  "filledAt": "2026-02-16T10:35:00Z"
}

Manage API keys programmatically

Use this flow if you want to create, rotate, revoke, or list API keys through the API.

Log in

Authenticate with your Bayse account to get a session token:
curl -X POST https://relay.bayse.markets/v1/user/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "[email protected]",
    "password": "your-password"
  }'
{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "deviceId": "d_abc123",
  "userId": "usr_456def"
}
Save the token and deviceId for API key management requests.

Create an API key with the API

Use your session token and device ID to create an API key:
curl -X POST https://relay.bayse.markets/v1/user/me/api-keys \
  -H "x-auth-token: YOUR_TOKEN" \
  -H "x-device-id: YOUR_DEVICE_ID" \
  -H "Content-Type: application/json" \
  -d '{"name": "My API Key"}'
Each API key must have a unique name. If you already have a key called "My API Key", choose a different name.
{
  "id": "key_abc123",
  "publicKey": "pk_live_abcdef123456",
  "secretKey": "sk_live_secret789xyz",
  "name": "My API Key",
  "createdAt": "2026-02-16T10:30:00Z"
}
Save your secretKey securely — it’s only shown once.

Next steps

Authentication guide

Learn about API key authentication and HMAC signing in detail.

API reference

Explore all available endpoints and parameters.

Prediction markets

Understand how prediction markets work on Bayse.

Error handling

Learn how to handle API errors gracefully.