Skip to content

HOST

Node

Native fetch. startHostSession talks to the sidecar. The page still opens chat with data-sveda-open buttons.

1. Run sveda-server

CORS origin is the Node host (8015–8017 in the playground). Next.js loads .env itself; Express and Nest should load it at boot.

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/node-client

ESM, Node 20+, native fetch. Until published, depend on the sibling checkout: "@sveda-ai/node-client": "file:../sveda-node".

npm i @sveda-ai/node-client

3. Env

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

4. Mint helper

No framework required: http.createServer can call startHostSession and return JSON.

import { startHostSession } from '@sveda-ai/node-client'

const payload = await startHostSession({
  baseUrl: process.env.SVEDA_CLIENT_BASE_URL,
  hostApiKey: process.env.SVEDA_CLIENT_HOST_API_KEY,
  visitorId: 'node-host',
})

5. Express

app.post('/sveda/session', async (req, res) => {
  const baseUrl = String(process.env.SVEDA_CLIENT_BASE_URL ?? '').replace(/\/$/, '')
  const hostApiKey = String(process.env.SVEDA_CLIENT_HOST_API_KEY ?? '')
  if (!baseUrl || !hostApiKey) {
    return res.status(503).json({ message: 'Set SVEDA_CLIENT_BASE_URL and SVEDA_CLIENT_HOST_API_KEY' })
  }
  res.json(await startHostSession({ baseUrl, hostApiKey, visitorId: 'express-playground' }))
})

6. NestJS

Register the controller on the root module. Missing env → 503 naming both variables.

@Controller()
export class SvedaController {
  @Post('sveda/session')
  async startSession(@Res() res: Response) {
    const session = await startHostSession({
      baseUrl: process.env.SVEDA_CLIENT_BASE_URL,
      hostApiKey: process.env.SVEDA_CLIENT_HOST_API_KEY,
      visitorId: 'nestjs-playground',
    })
    res.json(session)
  }
}

7. Next.js

App Router route app/sveda/session/route.js. Put origin on <html> in the root layout; put the buttons in the shell. Use force-dynamic so env is read per request.

// app/sveda/session/route.js
export async function POST() {
  const session = await startHostSession({
    baseUrl: process.env.SVEDA_CLIENT_BASE_URL,
    hostApiKey: process.env.SVEDA_CLIENT_HOST_API_KEY,
    visitorId: 'nextjs-playground',
  })
  return Response.json(session)
}

8. Page markup

<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