> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.runpayments.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.runpayments.io/_mcp/server.

# Generate WebSocket auth token

POST https://javelin.runpayments.io/api/ws-token

Issues a single-use token for authenticating a WebSocket connection. Use this instead of polling
to get the result of a queued interaction (`read-card` or `charge-card`).

After you start an interaction, open a WebSocket connection with this token (`wss://javelin.runpayments.io/cable?token=<token>`)
and subscribe to the channel `terminal_job:{interaction_id}` to receive real-time status updates.

The token expires after 60 seconds or on first use, whichever comes first.

Reference: https://docs.runpayments.io/reference/terminal-api/authentication-web-socket/generate-ws-token

## Authentication

- `Authorization` header (bearer token, required) — Use a Payments API key as the bearer token: `Authorization: Bearer <api_key>`. Get a fresh key from [Refresh API Keys](/reference/authentication/refresh-api-keys).

## Request

### Query parameters

- `mid` (string, optional) — Merchant ID. Required when your bearer token is an ISV token acting on behalf of a merchant. If the `mid` can't be resolved to an authorized account, the request returns `400`.

## Response

### 200

Token issued

- `token` (string, required) — Single-use WebSocket auth token. Pass as `?token=<value>` when opening the connection. Expires after 60 seconds or first use, whichever comes first.

## Errors

### 401 Unauthorized Error

Unauthorized

- `errors` (list of string, optional) — Error messages.

### 429 Too Many Requests Error

Rate limit exceeded. All Terminal API endpoints share a per-credential rate limit.

- `any`

### 503 Service Unavailable Error

Service temporarily unavailable.

- `error` (string, optional) — Error message.

## Examples

**Response**

```json
{
  "token": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
}
```

**SDK Code**

```python
import requests

url = "https://javelin.runpayments.io/api/ws-token"

headers = {"Authorization": "Bearer <token>"}

response = requests.post(url, headers=headers)

print(response.json())
```

```javascript
const url = 'https://javelin.runpayments.io/api/ws-token';
const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://javelin.runpayments.io/api/ws-token"

	req, _ := http.NewRequest("POST", url, nil)

	req.Header.Add("Authorization", "Bearer <token>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://javelin.runpayments.io/api/ws-token")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://javelin.runpayments.io/api/ws-token")
  .header("Authorization", "Bearer <token>")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://javelin.runpayments.io/api/ws-token', [
  'headers' => [
    'Authorization' => 'Bearer <token>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://javelin.runpayments.io/api/ws-token");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Authorization": "Bearer <token>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://javelin.runpayments.io/api/ws-token")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```