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

# Login

> Authenticate with your Bayse account to get a session token

## Overview

Log in with your Bayse account credentials to obtain a session token and device ID. These are required to manage API keys (create, list, revoke, rotate).

Use this endpoint when you want to manage API keys programmatically. If you prefer a UI, you can also manage API keys 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.

<Note>
  This endpoint is rate-limited to **1 request per 2 minutes** per email address. See [Rate limits](/rate-limits) for details.
</Note>

## Request body

<ParamField body="email" type="string" required>
  Your Bayse account email address.
</ParamField>

<ParamField body="password" type="string" required>
  Your Bayse account password (max 128 characters).
</ParamField>

## Example request

<CodeGroup>
  ```bash cURL 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"
    }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://relay.bayse.markets/v1/user/login', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      email: 'you@example.com',
      password: 'your-password',
    }),
  });
  const { token, deviceId } = await response.json();
  ```

  ```python Python theme={null}
  import requests

  resp = requests.post(
      'https://relay.bayse.markets/v1/user/login',
      json={
          'email': 'you@example.com',
          'password': 'your-password',
      },
  )
  data = resp.json()
  token = data['token']
  device_id = data['deviceId']
  ```

  ```go Go theme={null}
  body := strings.NewReader(`{"email":"you@example.com","password":"your-password"}`)
  req, _ := http.NewRequest("POST", "https://relay.bayse.markets/v1/user/login", body)
  req.Header.Set("Content-Type", "application/json")
  resp, _ := http.DefaultClient.Do(req)
  ```
</CodeGroup>

## Response

<ResponseField name="token" type="string">
  Session token. Pass this as the `x-auth-token` header when managing API keys.
</ResponseField>

<ResponseField name="deviceId" type="string">
  Device identifier. Pass this as the `x-device-id` header when managing API keys.
</ResponseField>

<ResponseField name="userId" type="string">
  Your Bayse user ID.
</ResponseField>

<ResponseExample>
  ```json 200 OK theme={null}
  {
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "deviceId": "d_abc123",
    "userId": "usr_456def"
  }
  ```
</ResponseExample>

## Errors

| Status | Description                                                      |
| ------ | ---------------------------------------------------------------- |
| 400    | Invalid request body (missing or malformed email/password).      |
| 401    | Invalid credentials.                                             |
| 429    | Rate limited. Retry after the number of seconds in `retryAfter`. |

```json 429 Too Many Requests theme={null}
{
  "message": "Too many login attempts. Please try again later.",
  "retryAfter": 120
}
```

## Next steps

Use the `token` and `deviceId` from the response to [create an API key](/api-reference/user/create-api-key) programmatically:

```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"}'
```
