Last update: 2025-05-08T12:27:33.000Z
Content:
---
title: "Multi-tenant real-time APIs with Clerk and Tinybird · Tinybird Docs"
theme-color: "#171612"
description: "In this guide, you'll learn how to build a multi-tenant real-time API with Clerk and Tinybird."
inkeep:version: "forward"
---




# Multi-tenant real-time APIs with Clerk and Tinybird [¶](https://www.tinybird.co/docs/forward/work-with-data/publish-data/guides/multitenant-real-time-apis-with-clerk-and-tinybird#multi-tenant-real-time-apis-with-clerk-and-tinybird)

Copy as MD 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 [¶](https://www.tinybird.co/docs/forward/work-with-data/publish-data/guides/multitenant-real-time-apis-with-clerk-and-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 [¶](https://www.tinybird.co/docs/forward/work-with-data/publish-data/guides/multitenant-real-time-apis-with-clerk-and-tinybird#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.



<-figure->
![](/docs/_next/image?url=%2Fdocs%2Fassets%2Fguides%2Fclerk%2Fclerk-jwt-tinybird.png&w=3840&q=75)

<-figcaption->
Clerk JWT tokens Tinybird template

</-figcaption->


</-figure->
Modify the Tinybird JWT template with these claims:

{
	"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.

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.


