Appearance
Chat widget
26 operations. Paths are relative to https://api.frege.io.
The embeddable chat widget
GET/v1/embed.js
The JavaScript a business puts in their own page with one script tag. Public and unauthenticated — the file itself holds no secret; Frege.setApiKey supplies one at runtime. Mount it with Frege.setApiKey(key) then Frege.mount({el, project, stage}). The version is in the path so a page that pasted this URL keeps working.
Authentication: none.
Responses
| Status | Description | Body |
|---|---|---|
| 200 | JavaScript |
What an embedded chat is talking to
GET/v1/embed/agent
Authenticated by an embed token. Returns the agent this token may drive, the customer it speaks for, and whether writes pause for approval in this environment.
Authentication: bearer token.
Responses
| Status | Description | Body |
|---|---|---|
| 200 | OK | data |
| 401 | Unauthorized | error envelope |
Attach a file from an embedded chat
POST/v1/embed/attachments
Authenticated by an embed token. Same rules as the project upload: the bytes decide whether a file can be read, recognised binary formats are refused by name, and the id returned goes in the next turn's "attachments". The upload belongs to the customer the token names, so one customer can never pull another's file into their conversation. A recording — a voice note, an audio or a video file — becomes its transcript, as there.
Authentication: bearer token.
Request body (application/x-www-form-urlencoded)
Type: string.
Request body (multipart/form-data)
Type: object.
Responses
| Status | Description | Body |
|---|---|---|
| 201 | Created | data |
| 401 | Unauthorized | error envelope |
| 413 | Request Entity Too Large | error envelope |
| 422 | Unprocessable Entity | error envelope |
List this customer's past conversations
GET/v1/embed/sessions
Authenticated by an embed token. Every session this customer has ever had with this environment's agent, most recently active first. Refused when history is disabled for this widget.
Authentication: bearer token.
Responses
| Status | Description | Body |
|---|---|---|
| 200 | OK | data |
| 401 | Unauthorized | error envelope |
| 403 | Forbidden | error envelope |
Delete every one of this customer's past conversations
DELETE/v1/embed/sessions
Authenticated by an embed token. This customer's own "clear my history" — it never reaches another customer's rows, even one in the same environment. Refused when history is disabled for this widget.
Authentication: bearer token.
Responses
| Status | Description | Body |
|---|---|---|
| 204 | No Content | |
| 401 | Unauthorized | error envelope |
| 403 | Forbidden | error envelope |
Read one of this customer's past conversations
GET/v1/embed/sessions/{sessionID}
Authenticated by an embed token. Text only — the messages this session's turns exchanged, in order; not the tool calls between them. Refused when history is disabled for this widget.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
sessionID (required) | path | string | Session ID |
Responses
| Status | Description | Body |
|---|---|---|
| 200 | OK | data |
| 401 | Unauthorized | error envelope |
| 403 | Forbidden | error envelope |
| 404 | Not Found | error envelope |
Delete one of this customer's past conversations
DELETE/v1/embed/sessions/{sessionID}
Authenticated by an embed token. Removes every turn of this session; it never reaches another customer's rows. Refused when history is disabled for this widget.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
sessionID (required) | path | string | Session ID |
Responses
| Status | Description | Body |
|---|---|---|
| 204 | No Content | |
| 401 | Unauthorized | error envelope |
| 403 | Forbidden | error envelope |
| 404 | Not Found | error envelope |
List the tools this customer always allows
GET/v1/embed/tool-approvals
Authenticated by an embed token. Every approval the customer the token names has given beyond one turn, across agents, newest first: for one conversation (scope conversation), or "always allow" (scope always) for 30 days from when it was last given (expires_at). They last until then, until the customer signs in again, or until withdrawn.
Authentication: bearer token.
Responses
| Status | Description | Body |
|---|---|---|
| 200 | OK | data |
| 401 | Unauthorized | error envelope |
Stop always allowing a tool
DELETE/v1/embed/tool-approvals/{approvalID}
Authenticated by an embed token. The tool asks again next time. An id belonging to another customer is 404.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
approvalID (required) | path | string | Approval ID |
Responses
| Status | Description | Body |
|---|---|---|
| 204 | No Content | |
| 404 | Not Found | error envelope |
Run one turn of an embedded chat
POST/v1/embed/turn
Authenticated by an embed token, streamed as server-sent events in exactly the vocabulary the dashboard's own chat reads. The turn runs as the customer the token names, through the agent the token names, against this environment's own MCP server — so grants, the write policy, redaction and the audit trail apply as they would to any other caller. Fields a browser must not decide are ignored if sent: identity, client_id, model and history. One frame is the widget's own: "call_offer", carrying the label of a button that starts a live call, sent when the agent offers one — only while calls are on and ready for this widget, as call_enabled reports.
Authentication: bearer token.
Request body (application/json)
Schema: api.runAgentRequest.
| Field | Type | Description |
|---|---|---|
approvals | agent.Answer[] | |
attachments | integer[] | |
client_id | integer | |
history | agent.Message[] | |
identity | string | |
message | string | |
model | string | |
playground_session_id | string | |
session_id | string |
Responses
| Status | Description | Body |
|---|---|---|
| 200 | SSE stream | |
| 401 | Unauthorized |
Open a live voice session with this widget's agent
POST/v1/embed/voice-session
Authenticated by an embed token; scoped to the customer and agent the token names, with no client_id to choose. Mints a short-lived LiveKit access token exactly like the dashboard's own voice session (see startAgentVoiceSession) — the room only answers once Frege's voice worker joins it. Refused (403) when calls are disabled for this widget (call_enabled), 409 when the agent's environment has no speech vendor chosen or connected, 503 when this deployment has no LiveKit configured, 429 when this customer has opened one too recently. Every session is recorded as a voice call.
Authentication: bearer token.
Responses
| Status | Description | Body |
|---|---|---|
| 201 | Created | data |
| 401 | Unauthorized | error envelope |
| 403 | Forbidden | error envelope |
| 409 | Conflict | error envelope |
| 429 | Too Many Requests | error envelope |
| 503 | Service Unavailable | error envelope |
Turn one recorded voice note into text
POST/v1/embed/voice-transcribe
Authenticated by an embed token. Speech-to-text only: the audio is sent to this environment's agent's own stt_model and the resulting text is returned as-is — nothing is sent to the agent, nothing is spoken back. The caller sends the text on afterwards, through the ordinary POST /embed/turn, exactly as if it had been typed. Refused (403) when voice is disabled for this widget or this agent has no stt_model configured.
Authentication: bearer token.
Request body (application/x-www-form-urlencoded)
Type: string or string.
Request body (multipart/form-data)
Type: object.
Responses
| Status | Description | Body |
|---|---|---|
| 200 | OK | data |
| 401 | Unauthorized | error envelope |
| 403 | Forbidden | error envelope |
| 413 | Request Entity Too Large | error envelope |
| 422 | Unprocessable Entity | error envelope |
| 429 | Too Many Requests | error envelope |
| 502 | Bad Gateway | error envelope |
| 503 | Service Unavailable | error envelope |
Sign an embed end user into this project's upstream
GET/v1/projects/{id}/embed/connect
The page an embedded chat's browser is bounced to when its customer has never connected an upstream account. Same recipe form the direct-MCP customer door renders — the tenant's own uploaded page if one is set, Frege's own otherwise. Unauthenticated by construction: this IS how a customer proves who they are. return_url must be one of this environment's verified embed origins.
Authentication: none.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
stage | query | string | staging or live |
return_url (required) | query | string | Where to send the browser back once connected |
Responses
| Status | Description | Body |
|---|---|---|
| 200 | HTML | |
| 400 | HTML | |
| 404 | HTML |
Run the recipe with what the embed end user just typed
POST/v1/projects/{id}/embed/connect
Runs the project's upstream recipe with the posted fields, exactly as the MCP customer door does. A multi-step recipe re-renders this same page with a fresh prompt; on success the customer's ProjectClient is created or found by the recipe's own subject and its credential bundle is written, then the browser is sent back to the return_url the GET validated, with frege_remember appended: the value the page sends to mint embed tokens for this person.
Authentication: none.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
Request body (application/x-www-form-urlencoded)
Type: string.
Responses
| Status | Description | Body |
|---|---|---|
| 302 | Found | |
| 400 | HTML |
The snippet that puts this environment's chat on a page
GET/v1/projects/{id}/embed/install
Manager-only, like the origin list it reports. Returns the exact <script> block to paste into the tenant's page and the call their own backend must make to mint a token, both filled in for this deployment, this project and this environment. ready is false until at least one embed origin has proved itself by DNS — the snippet still comes back, so it can be read while that is being set up, but the chat will refuse to start until an origin is verified. Pass ?agent= to have the backend example name a real agent; without it the example carries a placeholder.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
agent | query | string | Agent ID to write into the example |
Responses
| Status | Description | Body |
|---|---|---|
| 200 | OK | data |
| 403 | Forbidden | error envelope |
| 422 | Unprocessable Entity | error envelope |
Sites allowed to embed this environment's chat
GET/v1/projects/{id}/embed/origins
Manager-only in both directions. Each entry carries its DNS challenge and whether that challenge has been met. enabled counts only verified entries: minting an embed token for an environment with none is refused, and an existing token stops working on its next request.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
Responses
| Status | Description | Body |
|---|---|---|
| 200 | OK | data |
| 403 | Forbidden | error envelope |
List a site that may embed this environment's chat
POST/v1/projects/{id}/embed/origins
Manager-only, for the same reason the credential destination is: this decides which sites may hold a token that runs an agent as one of this environment's customers. The value is scheme + host + optional port and nothing else — no path, no trailing slash, no wildcard, because a wildcard trusts every subdomain including one somebody else has taken over. http is accepted only for localhost. The site is listed but NOT yet trusted: the response carries a DNS TXT record to publish, and POST .../verify is what turns it on. Localhost and the loopback addresses are the exception and are verified immediately, since DNS cannot prove a name that resolves to the machine asking.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
Request body (application/json)
Schema: api.addEmbedOriginRequest.
| Field | Type | Description |
|---|---|---|
origin | string |
Responses
| Status | Description | Body |
|---|---|---|
| 201 | Created | data |
| 403 | Forbidden | error envelope |
| 409 | Conflict | error envelope |
| 422 | Unprocessable Entity | error envelope |
Stop trusting a site to embed this environment's chat
DELETE/v1/projects/{id}/embed/origins/{originID}
Takes effect immediately, including for tokens already minted: every turn re-reads this list. Removing the last verified origin turns the embed off entirely.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
originID (required) | path | integer | Embed origin ID |
Responses
| Status | Description | Body |
|---|---|---|
| 204 | No Content | |
| 403 | Forbidden | error envelope |
| 404 | Not Found | error envelope |
Check an embed origin's DNS challenge
POST/v1/projects/{id}/embed/origins/{originID}/verify
Looks up the _frege-challenge.<host> TXT record and compares it against this origin's token. ALWAYS returns 200 — even when the record is missing or wrong — because "not verified yet" is the expected state while someone is still editing their DNS zone, not a caller error. Read verified and last_check_error in the response to see the outcome. Once verified, re-running this is a no-op that reports the existing state without a new DNS lookup: a later missing record does not revoke an origin that already proved ownership, since nothing re-verifies.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
originID (required) | path | integer | Embed origin ID |
Responses
| Status | Description | Body |
|---|---|---|
| 200 | OK | data |
| 403 | Forbidden | error envelope |
| 404 | Not Found | error envelope |
Mint a token for an embedded chat
POST/v1/projects/{id}/embed/tokens
Called by the widget itself, holding the project's API key (Frege.setApiKey) — see the package doc comment for the trade-off that accepts. Returns a short-lived bearer token bound to one customer, one environment and one agent. The token cannot be withdrawn before it expires, which is why the lifetime is minutes — but revoking the customer, or clearing this environment's embed origins, stops it on the next request. Requires the environment to have at least one embed origin set, which is what turns the embed on.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
Request body (application/json)
Schema: api.mintEmbedTokenRequest.
| Field | Type | Description |
|---|---|---|
agent | string | |
client_id | integer | |
remember | string | Remember is what the sign-in gave the browser; ClientID is for a server holding a secret key. |
ttl_seconds | integer |
Responses
| Status | Description | Body |
|---|---|---|
| 201 | Created | data |
| 404 | Not Found | error envelope |
| 422 | Unprocessable Entity | error envelope |
Which features this environment's chat widget offers
GET/v1/projects/{id}/widget-config
An environment that never set this gets the defaults: history and file on, voice and calls off. Read back inside GET /embed/agent so the widget itself knows what to render.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
Responses
| Status | Description | Body |
|---|---|---|
| 200 | OK | data |
Set which features this environment's chat widget offers
PUT/v1/projects/{id}/widget-config
Voice and calls are off by default on purpose — a session it opens spends real vendor minutes and a real customer credential, so turning it on is a deliberate choice, not an inherited default. call_enabled shows the call button, which also needs the environment's Voice settings to be usable; omitted, it keeps its current value. Manager only.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
Request body (application/json)
Schema: api.setWidgetConfigRequest.
| Field | Type | Description |
|---|---|---|
call_enabled | boolean | CallEnabled is optional so a client that predates calls, sending only the three older flags, does not switch calls off as a side effect. |
file_enabled | boolean | |
history_enabled | boolean | |
voice_enabled | boolean |
Responses
| Status | Description | Body |
|---|---|---|
| 200 | OK | data |
This environment's chat widget HTML
GET/v1/projects/{id}/widget-template
custom is false when the environment has no template of its own, which is the ordinary state — the widget then renders its own built-in skeleton and html is omitted.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
Responses
| Status | Description | Body |
|---|---|---|
| 200 | OK | data |
Set this environment's chat widget HTML
PUT/v1/projects/{id}/widget-template
Rejects anything that could run script or leave the document once it is live on a tenant's own page: <script>, every on* attribute, javascript:/external href or src, <iframe>/<object>/<embed>/<link>/<base>, <foreignObject> inside SVG, and @import or an external url(...) inside a <style> block. Sending blank HTML removes the template, which is how a project goes back to the widget's own default. Manager only.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
Request body (application/json)
Schema: api.setWidgetTemplateRequest.
| Field | Type | Description |
|---|---|---|
html | string |
Responses
| Status | Description | Body |
|---|---|---|
| 200 | OK | data |
| 422 | Unprocessable Entity | error envelope |
The brand applied to this environment's CHAT WIDGET
GET/v1/projects/{id}/widget-theme
The chat widget is the chatbot a tenant embeds in their own page. Its brand is separate from the one applied to tool views — they are different surfaces, and a colour that reads well in an AI client's panel is not the one a chatbot in a tenant's own site wants. custom is false when the environment has no brand, which is the ordinary state.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
Responses
| Status | Description | Body |
|---|---|---|
| 200 | OK | data |
Set the CHAT WIDGET's brand
PUT/v1/projects/{id}/widget-theme
Sending every field empty removes the brand, which is how a tenant goes back to the widget's own look. Manager only.
Authentication: bearer token.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
id (required) | path | string | Project ID |
Request body (application/json)
Schema: api.setWidgetThemeRequest.
| Field | Type | Description |
|---|---|---|
accent | string | |
background | string | |
border | string | |
font_key | string | |
foreground | string | |
logo_data_uri | string | |
muted | string | |
radius_px | integer |
Responses
| Status | Description | Body |
|---|---|---|
| 200 | OK | data |
| 422 | Unprocessable Entity | error envelope |