Skip to main content
Using a coding agent?
Paste this prompt into your agent. No install needed.

1. Install Bun

Already have Bun 1.4.2 or later? Skip to step 2. Check with bun --version. Otherwise, install Bun:
Open a new terminal afterwards so bun is on your PATH.

2. Create the actor project

Install the Terse CLI:
Create the project:
The template will contain two folders: actor and client. One holds the Actor code, the other is the app/cli that communicates with it. Think of it like a database to server connection.

3. Let’s Look at the Actor

Terse init defaults to giving you a little counter actor. You should already have the following under counter/actor/src/actor.ts.
src/actor.ts

4. Launch the Dev Server

Start the actor serve. Make sure you are in the root of you actor project (where the package.json is)!
Keep it running. You will be able to see all of your logs here (including console.logs in the actor).

5. A little CLI to interact with the Actor

You can plop the generated client into a web app, CLI, serverless function etc… very easily. Open a second terminal, and go to your client folder in counter/client. Generate the backend client from here:
Generated code points to http://127.0.0.1:7100/v1/projects/local/actors by default. Regenerate after making changes to actor code.

6. Try the counter!

In counter/client, run:
This will trigger the CLI and send a request to the actor. You should now see the current count on your terminal.

7. Deploy to Terse

From the actor project:
Open the Terse app. Select API keys in the sidebar. Create a token and copy it.

Test the deployed actor locally

Add these values to counter/client/.env. Use the URL from terse deploy and your Terse API token:
Regenerate the client and restart the backend from counter/client:

8. That’s it!

You know have a globally accessible Actor that anyone in the world can access. Create an many counters as your hearts desire!

Next steps

More examples

Browse AI chat, chatroom, collaborative documents, and more in the open source durable-actors project.

TypeScript guide

Learn fields, WebSockets, alarms, SQLite, and resources step by step.