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

# Showing charts in your own agent's chat

> Get an AI job's chart as an interactive page and show it in your own AI chat with mountOmniFrame.

Show the chart from an `askOmni` answer in your own chat. Your backend gets the chart as an interactive page, and your app shows it in a frame. The page has hover tooltips, a chart-type picker, and a table view.

## Requirements

To follow the steps on this page, you'll need:

* A finished [setup](https://docs.omni.co/embed/customization/ai-chat/your-agent-mcp.md), so your backend can mint an MCP token for the user
* `@omni-co/embed` version 1.3.0 or later installed in your frontend
* The `jobId` from a completed `askOmni` result

## Show a chart

### 1. Get the chart page on your server

Get the page with the user's MCP token or with an organization API key, then send it to the browser.

> [tab] MCP token
>
> Call the `getJobChartPage` tool with the user's [MCP token](https://docs.omni.co/embed/customization/ai-chat/your-agent-mcp.md) and `format: "html"`. The token reads only that user's jobs.
>
> ```typescript wrap title="Your server" theme={null}
> const response = await fetch('https://<your-omni-instance>.embed-omniapp.co/mcp', {
>   method: 'POST',
>   headers: {
>     Authorization: `Bearer ${accessToken}`,
>     'Content-Type': 'application/json',
>     Accept: 'application/json, text/event-stream',
>   },
>   body: JSON.stringify({
>     jsonrpc: '2.0',
>     id: 1,
>     method: 'tools/call',
>     params: {
>       name: 'getJobChartPage',
>       arguments: { jobId, format: 'html' },
>     },
>   }),
> })
> ```
>
> The result's `structuredContent` has the HTTP `status` of the request and the page in `body`. Pass `body` to `mountOmniFrame` as `html` in the next step. If the call fails, `error` gives the reason, so show a fallback.
>
> The tool refuses a page over 200,000 characters. If it refuses, ask the question again with fewer rows, then get the chart with the new job ID.
>
> Call this tool from your own code. If your LLM calls it, the full page goes into the LLM's context.

> [tab] Organization API key
>
> Call [Render AI job visualization](https://docs.omni.co/api/ai/render-ai-job-visualization.md) with `format=html` and an organization API key. The user's MCP token doesn't work with this endpoint.
>
> An organization API key can read any job in the organization. Before you get a chart for a user, check that the `userId` from [Get AI job status](https://docs.omni.co/api/ai/get-ai-job-status.md) matches that user's Omni user ID.
>
> ```typescript title="Your server" theme={null}
> const res = await fetch(
>   `https://{instance}.omniapp.co/api/v1/ai/jobs/${jobId}/vis?format=html`,
>   { headers: { Authorization: `Bearer ${process.env.OMNI_API_KEY}` } },
> )
> // 404: the job doesn't exist or isn't complete. 422: the chart can't be drawn.
> if (!res.ok) throw new Error(`Omni API ${res.status}`)
> const html = await res.text()
> ```

### 2. Show the page in your app

Call `mountOmniFrame` from `@omni-co/embed/browser`.

```typescript title="Your page" theme={null}
import { mountOmniFrame } from '@omni-co/embed/browser'

const frame = mountOmniFrame(container, { html }, {
  onError: () => showFallback(),
})

// When the chat message unmounts:
frame.destroy()
```

`mountOmniFrame` does the following:

* Frames the page in an iframe sandboxed to `allow-scripts` only. Don't add `allow-same-origin`, because it gives the page your page's origin.
* Sizes the frame from the page's [`size`](https://docs.omni.co/embed/events/size) event.
* Calls `onError` and removes the frame when the page sends an [`error`](https://docs.omni.co/embed/events/error) event (`page_error`), or doesn't report its size within 15 seconds (`start_timeout`). A `start_timeout` usually means your Content Security Policy blocked the page's script.
* Removes the frame when you call `destroy()`.

`mountOmniFrame` also frames a signed embed URL, with `{ url: signedEmbedUrl }`, and sizes embedded dashboards and apps to their content.

## Content security policy

The page runs under your page's Content Security Policy. Allow these:

* `script-src` and `style-src`: Omni's asset origin, which is the origin of the page's `<script type="module">`
* `worker-src`: `blob:`
* `img-src`: `data:`

## Next steps

* See all chart page options in [Render AI job visualization](https://docs.omni.co/api/ai/render-ai-job-visualization.md)
* Learn about the [`size`](https://docs.omni.co/embed/events/size) and [`error`](https://docs.omni.co/embed/events/error) events the chart page sends
