> ## Documentation Index
> Fetch the complete documentation index at: https://trytilde.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Embed chat

> Let your application's signed-in users chat with Tilde agents on your own pages.

Embedded chat uses the [native Tilde chat](https://trytilde.ai/docs/chat-channels.md) channel. Your server proxies the chat API and says who the user is; the browser renders the chat components.

## With an embed key CLOUD

Name the agents on the embed key (project **Embed** tab), then list them on the server:

```ts lib/tilde.ts theme={"system"}
import { createEmbed } from "@trytilde/embed-server";

export const embed = createEmbed({
  apiKey: process.env.TILDE_EMBED_KEY!,
  agents: ["<agent id>"],
  resolveIdentity: async (request) => {
    const user = await getSession(request);
    return user ? { id: user.id } : null;
  },
});
```

The handler serves the chat API under `/api/tilde/chat`. Render the components:

```tsx theme={"system"}
import { Chat, ListSessions, chatProxy } from "@trytilde/embed/react";
import "@trytilde/embed/style.css";

<ListSessions proxy={chatProxy()} identity={user.id} onSelectSession={(session) => setSession(session)} />;
<Chat proxy={chatProxy()} agentId="<agent id>" sessionId={session} identity={user.id} />;
```

The `identity` prop only groups the components' caches. Your server's `resolveIdentity` decides who the user is.

## With an agent's chat key

Without an embed key, and in Tilde OSS, use `@trytilde/chat-proxy` with the agent's chat key from the agent's **Chat providers** tab:

```ts theme={"system"}
import { createChatProxy } from "@trytilde/chat-proxy";

const proxy = createChatProxy({
  agentId: "<agent id>",
  apiKey: process.env.TILDE_CHAT_API_KEY!,
  resolveIdentity: async (request) => (await getSession(request))?.id ?? null,
});
```

`@trytilde/chat-next` adapts it to Next.js route handlers, and `@trytilde/chat-ui` provides the same `Chat` and `ListSessions` components.

## Who may chat

The agent's channel access applies to embedded users like any other channel. A private agent accepts only users you allow on its **IAM** tab; a public agent accepts every user your server vouches for. Each user sees only their own sessions.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.