# Authentication

You must authenticate yourself when subscribing to any of the sFOX WebSocket feeds.

{% hint style="info" %}
All WebSocket feeds require authentication.
{% endhint %}

Authentication commands should be JSON with the following properties:

<table><thead><tr><th width="129">Property</th><th width="100">Type</th><th>Command</th></tr></thead><tbody><tr><td><strong><code>type</code></strong></td><td>string</td><td><code>"authenticate"</code></td></tr><tr><td><strong><code>apiKey</code></strong></td><td>string</td><td><code>"&#x3C;YOUR-API-KEY>"</code></td></tr></tbody></table>

### Authentication Message

To authenticate yourself to the WebSocket API, you must send an `authenticate` message to the server with an API key for your account. This message is mandatory as all WebSocket feeds require authentication.

#### Authenticate Message

```json
// Request -> Authenticate
{
    "type": "authenticate", 
    "apiKey": "<REPLACE WITH YOUR API KEY>"
}
```

Once a `authenticate` message is received the server responds with an `authenticate` message that specifies whether authentication succeeded or failed.

```json
// Response -> Authenticate
{
    "type": "success",
    "sequence": 1,
    "timestamp": 1727391983733911769,
    "payload": {
        "action": "authenticate"
    },
    "action": "authenticate"
}
```

### Example Code

{% tabs %}
{% tab title="NodeJS" %}

```javascript
const authMessage = {
   type: 'authenticate',
   apiKey: '<API_KEY>',
}
ws.send(JSON.stringify(authMessage))
```

{% endtab %}

{% tab title="Python" %}

```python
auth_message={
  "type": "authenticate",
  "apiKey": "<API KEY>"
}

await ws.send(json_dump(auth_message))
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sfox.com/websocket-api/authentication.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
