Calling agents from the frontend
You can call your agents in two ways:- Via the SDK clients (type-safe, recommended). Supported for TypeScript, Python, Java, Go.
- Via plain HTTP requests (works anywhere in any language).
- Request-response: short operations where the user is waiting (< few seconds)
- Fire-and-forget: longer operations where you’ll receive updates via a separate channel (pubsub/webhooks) or want to retrieve the result later
- Scheduled/delayed calls: schedules a request to an agent with a delay
Example: TypeScript SDK client
Install the Restate SDK clients package:Example: Next.js API Route
You can use the SDK clients to send requests from your NextJS app to Restate services. Here’s an example of an API route that calls a Restate service:app/agent/[topic]/api/route.ts
Using HTTP requests
You can also call Restate services using plain HTTP requests without the SDK. For example, in JavaScript:Request deduplication / idempotency
You can let Restate deduplicate requests by adding an idempotency key to the header of your request.Re-attach to executions
Restate lets you re-attach to ongoing executions. This is useful to retrieve the response from another processs, for example after a crash or as part of your application logic.idempotency There are three ways to do this:- If you use an idempotency key, then sending the same request with the same idempotency key will re-attach you to the original invocation.
- If you have the invocation ID, then you can use that to attach to it:
- If you started the invocation with an idempotency key, then you can use that to attach to it. This does not start the invocation as opposed to point 1: