|
| 1 | +# Hyperbeam Timeout example |
| 2 | + |
| 3 | +Bring down costs and add quickly add paywalls using timeouts. |
| 4 | + |
| 5 | +## What is this useful for? |
| 6 | + |
| 7 | +The Hyperbeam API lets you specify absolute, inactive and offine timeouts for your browser sessions. This is useful to bring down costs, add paywalls, reduce the number of concurrent sessions and more. |
| 8 | + |
| 9 | +## Usage |
| 10 | + |
| 11 | +```ts |
| 12 | +// Server |
| 13 | +const response = await axios.post( |
| 14 | + "https://engine.hyperbeam.com/v0/vm", |
| 15 | + { |
| 16 | + timeout: { |
| 17 | + offline: 10, // when clients are offline |
| 18 | + inactive: 30, // when clients have the vm open but are inactive |
| 19 | + absolute: 60, // absolute time before the vm is terminated |
| 20 | + warning: 15, // time before the vm is terminated to show a warning |
| 21 | + webhook: { |
| 22 | + url: webhookUrl, // url to send the timeout webhook event to |
| 23 | + bearer, // bearer token to send with the webhook |
| 24 | + }, |
| 25 | + }, |
| 26 | + }, |
| 27 | + { headers } |
| 28 | +); |
| 29 | +``` |
| 30 | + |
| 31 | +## Steps |
| 32 | + |
| 33 | +- Use `npm install` to install the dependencies altogether and navigate to the examples you want to run for more information. |
| 34 | +- Set your API key by running the following command in your terminal: |
| 35 | + |
| 36 | +```bash |
| 37 | + |
| 38 | +# Linux/macOS |
| 39 | +export HB_API_KEY=your_api_key |
| 40 | + |
| 41 | +# Windows |
| 42 | +set HB_API_KEY=your_api_key |
| 43 | +``` |
| 44 | + |
| 45 | +Replace `your_api_key` with your API key from the [Hyperbeam dashboard](https://hyperbeam.com/dashboard). |
| 46 | + |
| 47 | +- Run `npm run start`, a server should be listening on port 8080. |
| 48 | + |
| 49 | +- Open <http://localhost:8080> on your browser. You should be able to see the browser session being terminated after 60 seconds. |
| 50 | + |
| 51 | +## Need more help? |
| 52 | + |
| 53 | +Send us an email at [founders@hyperbeam.com](mailto:founders@hyperbeam.com) or join our community [Discord server](https://discord.gg/D78RsGfQjq). |
0 commit comments