Embed API

Run published agents from external sites without API keys. Requests go to the /embed route group on the API host.

The hosted chat UI at https://app.inference.sh/embed/agents/{namespace}/{name} uses these endpoints internally. Build your own UI with the same API.

Publishing and embedding agents — workspace setup, origins, themes, and iframe snippets
Publications API — create and manage publications (POST /publications, etc.)


Base URL

code
1https://api.inference.sh/embed

No Authorization header is required. The API uses anonymous access with credentials cookies when present.

Send X-API-Version: 2 for bare JSON responses (same as the main REST API).


Origin validation

Published agents validate the request Origin header against the publication's allowed_origins:

allowed_originsBehavior
EmptyAll origins allowed
List of URLsOrigin must match an entry exactly, or the list may include *
Mismatch403 forbiddenorigin not allowed

Configure origins in the workspace Publish tab before calling the embed API from a browser.


Get published agent info

GET /embed/agents/{namespace}/{name}

Returns agent metadata and optional publication theme for styling your UI.

Response

FieldDescription
nameAgent display name
namespace, nameAgent ref components
versionActive version (description, example prompts, etc.)
themeOptional light / dark color tokens when configured

Example

bash
1curl "https://api.inference.sh/embed/agents/myteam/support-agent" \2  -H "X-API-Version: 2" \3  -H "Origin: https://example.com"

Run agent

POST /embed/agents/run

Start or continue a chat with a published agent. Billing runs on the publisher's team.

Request

FieldTypeRequiredDescription
agentstringYesAgent ref (namespace/name)
chat_idstringNoExisting chat ID (omit for a new chat)
inputobjectYesMessage payload (text, optional attachments)
streambooleanNoIf true, response is SSE instead of JSON

Example (JSON response):

bash
1curl -X POST https://api.inference.sh/embed/agents/run \2  -H "Content-Type: application/json" \3  -H "X-API-Version: 2" \4  -H "Origin: https://example.com" \5  -d '{6    "agent": "myteam/support-agent",7    "input": { "text": "Hello" }8  }'

Example (streaming): set "stream": true and use Accept: text/event-stream. Events match chat streaming.

Errors

HTTPWhen
404Agent not published or ref not found
403Origin not in allowed_origins
402Publisher team has insufficient balance

Chat and tool endpoints

After a run creates a chat, use these paths under /embed (same shapes as the authenticated Agents API, but scoped to embed access):

MethodPathPurpose
GET/chats/{id}Chat state and messages
GET/chats/{id}/statusChat status only
POST/chats/{id}Send a follow-up message
POST/chats/{id}/stopStop generation
GET/chats/{id}/streamSSE message stream
POST/tools/{toolId}Submit client tool result
POST/tools/{toolId}/invokeApprove a pending tool
POST/tools/{toolId}/rejectReject a pending tool

Embed chat access is limited to chats created in the embed session (creator-scoped). Execution and billing use the agent owner's team.


JavaScript SDK

Point the SDK at the embed base URL and omit the API key:

typescript
1import { createClient } from '@inferencesh/sdk';2import { AgentChatProvider, useAgentChat } from '@inferencesh/sdk/agent';34const embedClient = createClient({5  baseUrl: 'https://api.inference.sh/embed',6  getToken: () => '',7  credentials: 'include',8});910// Use embedClient with AgentChatProvider — same hooks as authenticated chat

Register client tool handlers for built-in embed tools when using a custom UI:

ToolHandler role
get_host_contextReturn JSON from your host page bridge
send_to_hostForward action / params to the parent window

The hosted embed page implements these via postMessage. See Publishing — host page context.


Host context tools

When host_context is enabled on the agent, the model may call:

  • get_host_context — Read URL, user info, tokens, or other data the host supplied via embed:context messages.
  • send_to_host — Request host actions (navigate, refresh, click, custom actions). The host page responds with embed:action:result.

These execute in the browser (client tools), not on inference.sh servers.


we use cookies

we use cookies to ensure you get the best experience on our website. for more information on how we use cookies, please see our cookie policy.

by clicking "accept", you agree to our use of cookies.
learn more.