# Open the event stream — API reference

> Opens a server-sent event stream of confirmed events, test events and open incidents for the key's Company and clients.

Source: https://upfour.io/docs/api/runner/open-the-event-stream

[Developers](https://upfour.io/docs/api.md)/[Event stream (up4 CLI)](https://upfour.io/docs/api/runner.md)

Opens a server-sent event stream of confirmed events, test events and open incidents for the key's Company and clients.

GET https://app.upfour.io/v1/runner/stream

scope runner.stream.read stable returns 200

## Parameters

| Field | Type | Description |
| --- | --- | --- |
| `suspected` optional | string one of`1` | query parameter · 1 asks for monitor.suspected and monitor.suspicion_cleared, the unconfirmed early warnings. They arrive only while the machine's suspicion setting is on as well, carry unconfirmed: true and are never replayed. |
| `Last-Event-ID` optional | string | header parameter · Resume after this event ID within the replay window. |
| `X-Up4-Runner-Host` optional | string max length 255 | header parameter · Host name of the machine, shown under Connected machines. Display only. |
| `X-Up4-Runner-ID` required | uuid | header parameter · Stable UUID of the runner. |
| `X-Up4-Runner-Name` required | string length 1–64 | header parameter · Printable runner name. |

## Returns

A successful request returns `200` with text/event-stream.

## Errors

Only the errors this operation can return. Every error uses the [same envelope](https://upfour.io/docs/api/responses.md).

| Status | Code | Meaning |
| --- | --- | --- |
| 400 | [bad_request](https://upfour.io/docs/api/errors#code-bad_request) | The request is malformed or fails validation. |
| 403 | [insufficient_scope](https://upfour.io/docs/api/errors#code-insufficient_scope) | The API key lacks the scope this operation needs. **When:** Only for API keys, when the key's scopes do not include the one the operation requires; details.required_scope names it. **Fix:** Create a key with the needed scope; a missing scope never resolves by retrying. |
| 403 | [permission_denied](https://upfour.io/docs/api/errors#code-permission_denied) | The credentials do not permit this action. |
| 429 | [runner_connection_limit](https://upfour.io/docs/api/errors#code-runner_connection_limit) | The Company already has as many open runner streams as one API instance accepts. **When:** GET /v1/runner/stream when the Company's open runner connections on the answering instance reach the limit; Retry-After carries the wait in seconds. **Fix:** Close runners you no longer use, then reconnect after Retry-After with jitter. |
| 503 | [service_unavailable](https://upfour.io/docs/api/errors#code-service_unavailable) | The service or a required dependency is temporarily unavailable. |
| 403 | documented response | The key lacks runner.stream.read or has lost access to its clients. |

Every call can also return `unauthorized` (401), `rate_limit_exceeded` (429) or `internal_error` (500 / 502). See [Responses and errors](https://upfour.io/docs/api/responses.md).

[NextSend a test event](https://upfour.io/docs/api/runner/send-a-test-event.md)

## Request

### cURL

```bash
curl -s "https://app.upfour.io/v1/runner/stream" \
  -H "Authorization: Bearer $UP4_API_KEY"
```

### JavaScript

```javascript
const res = await fetch("https://app.upfour.io/v1/runner/stream", {
  headers: {
    Authorization: `Bearer ${process.env.UP4_API_KEY}`,
  },
});
console.log(res.status, await res.text());
```

### Python

```python
import os
import requests

res = requests.get(
    "https://app.upfour.io/v1/runner/stream",
    headers={"Authorization": f"Bearer {os.environ['UP4_API_KEY']}"},
)
print(res.status_code, res.text)
```

### Go

```go
package main

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

func main() {
	req, _ := http.NewRequest("GET", "https://app.upfour.io/v1/runner/stream", nil)
	req.Header.Set("Authorization", "Bearer "+os.Getenv("UP4_API_KEY"))
	res, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()
	out, _ := io.ReadAll(res.Body)
	fmt.Println(res.StatusCode, string(out))
}
```

### PHP

```php
<?php
$ch = curl_init("https://app.upfour.io/v1/runner/stream");
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer " . getenv("UP4_API_KEY"),
    ],
]);
$response = curl_exec($ch);
echo curl_getinfo($ch, CURLINFO_RESPONSE_CODE), " ", $response, "\n";
curl_close($ch);
```

## Response

### 200

```
Successful response. SSE protocol 1 opens with hello and a snapshot of visible active incidents. Each event frame carries its event ID. A gap names a missing replay cursor. A goodbye closes the connection. Keepalive comments arrive every 15 seconds.
```

### 400

```json
{
  "error": {
    "code": "bad_request",
    "message": "The request is malformed or fails validation.",
    "request_id": "req_…"
  }
}
```

### 403

```json
{
  "error": {
    "code": "insufficient_scope",
    "message": "The API key lacks the scope this operation needs.",
    "request_id": "req_…"
  }
}
```

### 429

```json
{
  "error": {
    "code": "runner_connection_limit",
    "message": "The Company already has as many open runner streams as one API instance accepts.",
    "request_id": "req_…"
  }
}
```

### 503

```json
{
  "error": {
    "code": "service_unavailable",
    "message": "The service or a required dependency is temporarily unavailable.",
    "request_id": "req_…"
  }
}
```
