---
title: Multi-tenant real-time APIs with Clerk and Tinybird
meta:
    description: In this guide, you'll learn how to build a multi-tenant real-time API with Clerk and Tinybird.
---

# Multi-tenant real-time APIs with Clerk and Tinybird

Learn how to build a multi-tenant real-time API with Clerk and Tinybird.

You can view the [live demo](https://clerk-tinybird.vercel.app/) or browse the [GitHub repo (clerk-tinybird)](https://github.com/tinybirdco/clerk-tinybird).

## Prerequisites

This guide assumes that you have a Tinybird account, and you are familiar with creating a Tinybird workspace and pushing resources to it.

You need a working familiarity with Clerk and Next.js.

## JWT Template

Create a JWT template in Clerk, and use the generated JWT to access Tinybird pipe endpoints.

In Clerk go to `Configure` > `JWT Templates` and choose Tinybird.

{% image src="/assets/guides/clerk/clerk-jwt-tinybird.png" alt="" caption="Clerk JWT tokens Tinybird template" /%}

Modify the Tinybird JWT template with these claims:

```json
{
	"name": "frontend_jwt",
	"limits": {
		"rps": 10
	},
	"scopes": [
		{
			"type": "PIPES:READ",
			"resource": "<YOUR-TINYBIRD-PIPE-NAME>",
			"fixed_params": {
				"org": "{{org.slug}}",
				"user": "{{user.id}}"
			}
		}
	],
	"workspace_id": "<YOUR-TINYBIRD-WORKSPACE-ID>"
}
```

- Use your Tinybird admin token as signking key.
- Add as many scopes as needed, use fixed params to filter your Tinybird API endpoints.
- Configure `fixed_params` to match the parameter names and values in your Tinybird API endpoints.

On your application request a token to `Clerk` using the `tinybird` template, where `tinybird` is the name you gave to the template.

```typescript
  const authentication = await auth()
  const { userId, sessionId, getToken } = authentication
  const token = await getToken({ template: "tinybird" })

  fetch('https://api.tinybird.co/v0/pipes/your_pipe.json', {
  headers: {
    Authorization: `Bearer ${token}`
  }
})
```

Use this [demo project](https://www.tinybird.co/templates/clerk-jwt) to for a fully working example.
