Skip to content

HOST

PHP

Framework-agnostic PHP. Factory::factory() → embed()->createToken(). Your page only receives origin and token.

1. Run sveda-server

Same sidecar as every other host. CORS must list the PHP origin.

export SVEDA_EMBED_ENABLED=true
export SVEDA_BIND=0.0.0.0:8787
export SVEDA_EMBED_HOST_API_KEY=replace-me
export SVEDA_CORS_ORIGINS=http://127.0.0.1:8000
export DEEPSEEK_API_KEY=sk-...
sveda-server

2. Install sveda-ai/client

No Laravel. No Symfony. The package talks HTTP to POST /sveda/embed/token with Authorization: Bearer.

composer require sveda-ai/client

3. Host env

The second value must match SVEDA_EMBED_HOST_API_KEY on the sidecar. If either is empty, return 503 from the session route.

SVEDA_CLIENT_BASE_URL=http://127.0.0.1:8787
SVEDA_CLIENT_HOST_API_KEY=replace-me

4. POST /sveda/session

Mint on the server. Optional host_mcp_url (and matching token) may ride on createToken. Empty token → error, do not return 200.

use Sveda\Client\Factory;

$client = Factory::factory()
    ->withBaseUri(getenv('SVEDA_CLIENT_BASE_URL'))
    ->withHostApiKey(getenv('SVEDA_CLIENT_HOST_API_KEY'))
    ->make();

$response = $client->embed()->createToken([
    'visitor_id' => 'php-host',
]);

header('content-type: application/json');
echo json_encode([
    'origin' => rtrim(getenv('SVEDA_CLIENT_BASE_URL'), '/'),
    'token' => $response->token,
    'expires_in' => $response->expiresIn,
    'appearance' => $response->appearance,
]);
{
  "origin": "http://127.0.0.1:8787",
  "token": "sveda_embed_…",
  "expires_in": 3600,
  "appearance": null
}

5. Page markup

Set origin and session attributes only when the base URL is configured. Serve sveda-host.js as a module. Buttons: data-sveda-open="js" and data-sveda-open="iframe".

<html
  lang="en"
  data-sveda-origin="http://127.0.0.1:8787"
  data-sveda-session="/sveda/session"
>
  <body>
    <button type="button" data-sveda-open="js">Open JS chat</button>
    <button type="button" data-sveda-open="iframe">Open iframe chat</button>
    <script type="module" src="/sveda-host.js"></script>
  </body>
</html>

Mint from the host.

Install the language SDK. Expose POST /sveda/session. Open JS chat or an iframe.

Host SDKs