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

# Environments & Endpoints

> Base URLs, health check, authentication, and server location for the AI Exchange API.

## Environments

AI Exchange provides two environments. Use **sandbox** for development and testing. Use **production** when you are ready to trade with real funds.

| | Production | Sandbox |
| - | - | - |
| Web app | `https://ai.exchange` | `https://sandbox.ai.exchange` |
| REST: accounts, market data, portfolio | `https://gateway.ai.exchange/api` | `https://gateway.sandbox.ai.exchange/api` |
| REST: orders | `https://gateway.ai.exchange/orders` | `https://gateway.sandbox.ai.exchange/orders` |
| WebSocket: market data | `wss://gateway.ai.exchange/md/ws` | `wss://gateway.sandbox.ai.exchange/md/ws` |
| WebSocket: orders | `wss://gateway.ai.exchange/orders/ws` | `wss://gateway.sandbox.ai.exchange/orders/ws` |

Each environment has its own accounts and API keys. A key created in one environment does not work in the other.

## Health Check

Both environments expose a public health endpoint that requires no authentication:

```
GET /health
```

Example: `https://gateway.ai.exchange/api/health`

Use this to verify connectivity or check whether the service is up.

## Authentication

Every endpoint except `/health` requires a session token. You get a token by exchanging an API key and its secret.

1. Create an API key in the web app of the environment you want to use: [sandbox](https://sandbox.ai.exchange) or [production](https://ai.exchange/account/api). The app shows the key and its secret.
2. Exchange the key and secret for a token with [`POST /authenticate`](https://docs.ai.exchange/api-reference/user-management/authenticate). `expiration_seconds` sets how long the token is valid.

```bash theme={null}
curl -s -X POST https://gateway.sandbox.ai.exchange/api/authenticate \
  -H "Content-Type: application/json" \
  -d '{"api_key":"YOUR_KEY","api_secret":"YOUR_SECRET","expiration_seconds":3600}'
# Response: {"token":"<token>"}
```

3. Send the token in the `Authorization` header of every REST request and of every WebSocket upgrade request:

```
Authorization: Bearer <token>
```

Do not send the API key itself as the Bearer value. Request a new token before the current one expires.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.