> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bayse.markets/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Make your first API call to Bayse Markets in minutes

## Get your API credentials

Before you can trade on Bayse Markets programmatically, you need an API key pair.

<Note>
  This quickstart assumes you already have a Bayse Markets account. If not, sign up at [link.bayse.markets](https://link.bayse.markets/app).
</Note>

### Step 1: Create an API key

Create an API key in the Bayse web app at [app.bayse.markets/settings/api-keys](https://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](#manage-api-keys-programmatically).

<Warning>
  Save your **secret key** securely. You need it to sign write requests, and you may not be able to view it again later.
</Warning>

### Step 2: Make a read request

Try a simple read request to list prediction market events:

```bash theme={null}
curl -X GET "https://relay.bayse.markets/v1/pm/events?limit=10" \
  -H "X-Public-Key: pk_live_abcdef123456"
```

<Accordion title="Response example">
  ```json theme={null}
  {
    "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
    }
  }
  ```
</Accordion>

### 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}`:

<CodeGroup>
  ```bash cURL theme={null}
  # 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"
  ```

  ```javascript Node.js theme={null}
  import crypto from 'crypto';

  const PUBLIC_KEY = 'pk_live_abcdef123456';
  const SECRET_KEY = 'sk_live_secret789xyz';
  const timestamp = Math.floor(Date.now() / 1000);
  const method = 'POST';
  const path = '/v1/pm/events/evt_123/markets/mkt_456/orders';
  const body = JSON.stringify({ side: 'BUY', outcome: 'YES', amount: 100, currency: 'USD' });

  // Compute body hash (SHA-256 hex digest)
  const bodyHash = crypto.createHash('sha256').update(body).digest('hex');

  // Create HMAC signature of the full payload
  const payload = `${timestamp}.${method}.${path}.${bodyHash}`;
  const signature = crypto
    .createHmac('sha256', SECRET_KEY)
    .update(payload)
    .digest('base64');

  // Make the request
  const response = await fetch(`https://relay.bayse.markets${path}`, {
    method,
    headers: {
      'X-Public-Key': PUBLIC_KEY,
      'X-Timestamp': timestamp.toString(),
      'X-Signature': signature,
      'Content-Type': 'application/json',
    },
    body,
  });
  ```

  ```python Python theme={null}
  import hmac
  import hashlib
  import base64
  import json
  import time
  import requests

  PUBLIC_KEY = 'pk_live_abcdef123456'
  SECRET_KEY = 'sk_live_secret789xyz'
  timestamp = int(time.time())
  method = 'POST'
  path = '/v1/pm/events/evt_123/markets/mkt_456/orders'
  body = json.dumps({'side': 'BUY', 'outcome': 'YES', 'amount': 100, 'currency': 'USD'})

  # Compute body hash and create signature
  body_hash = hashlib.sha256(body.encode()).hexdigest()
  payload = f'{timestamp}.{method}.{path}.{body_hash}'
  signature = base64.b64encode(
      hmac.new(SECRET_KEY.encode(), payload.encode(), hashlib.sha256).digest()
  ).decode()

  # Make the request
  response = requests.post(
      f'https://relay.bayse.markets{path}',
      headers={
          'X-Public-Key': PUBLIC_KEY,
          'X-Timestamp': str(timestamp),
          'X-Signature': signature,
          'Content-Type': 'application/json',
      },
      data=body,
  )
  ```
</CodeGroup>

<Accordion title="Response example">
  ```json theme={null}
  {
    "id": "ord_789",
    "eventId": "evt_123",
    "marketId": "mkt_456",
    "side": "buy",
    "outcomeIndex": 0,
    "amount": 100,
    "status": "filled",
    "filledAt": "2026-02-16T10:35:00Z"
  }
  ```
</Accordion>

## 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:

```bash theme={null}
curl -X POST https://relay.bayse.markets/v1/user/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "you@example.com",
    "password": "your-password"
  }'
```

<Accordion title="Response example">
  ```json theme={null}
  {
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "deviceId": "d_abc123",
    "userId": "usr_456def"
  }
  ```
</Accordion>

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:

```bash theme={null}
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"}'
```

<Note>
  Each API key must have a unique name. If you already have a key called `"My API Key"`, choose a different name.
</Note>

<Accordion title="Response example">
  ```json theme={null}
  {
    "id": "key_abc123",
    "publicKey": "pk_live_abcdef123456",
    "secretKey": "sk_live_secret789xyz",
    "name": "My API Key",
    "createdAt": "2026-02-16T10:30:00Z"
  }
  ```
</Accordion>

<Warning>
  Save your **secretKey** securely — it's only shown once.
</Warning>

## Next steps

<CardGroup cols={2}>
  <Card title="Authentication guide" icon="shield-check" href="/authentication">
    Learn about API key authentication and HMAC signing in detail.
  </Card>

  <Card title="API reference" icon="book" href="/api-reference/introduction">
    Explore all available endpoints and parameters.
  </Card>

  <Card title="Prediction markets" icon="chart-line" href="/concepts/prediction-markets">
    Understand how prediction markets work on Bayse.
  </Card>

  <Card title="Error handling" icon="triangle-exclamation" href="/api-reference/introduction#errors">
    Learn how to handle API errors gracefully.
  </Card>
</CardGroup>
