> For the complete documentation index, see [llms.txt](https://docs.sfox.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sfox.com/websocket-api/authentication.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
