> 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

Authenticating to the WebSocket API

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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
