Skip to content

HOST

.NET

net8.0 Sveda.Client. ASP.NET is MapPost plus a layout. The library is usable from any HttpClient host.

1. Run sveda-server

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. Reference Sveda.Client

Target net8.0. Until NuGet, project-reference the sibling sveda-dotnet library. Usable from a console app or worker — ASP.NET is optional.

<ItemGroup>
  <ProjectReference Include="..\..\sveda-dotnet\src\Sveda.Client\Sveda.Client.csproj" />
</ItemGroup>

3. Env

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

4. Mint

using var client = new SvedaClient(new SvedaClientOptions
{
    BaseUrl = baseUrl,
    HostApiKey = hostApiKey,
});
var session = await client.StartHostSessionAsync(new CreateTokenRequest
{
    VisitorId = "aspnet-playground",
});

5. ASP.NET Core

JSON property names stay snake_case for expires_in so sveda-host.js can read them. Hide layout buttons when origin is empty.

app.MapPost("/sveda/session", async (IConfiguration config, CancellationToken cancellationToken) =>
{
    var baseUrl = config["SVEDA_CLIENT_BASE_URL"]?.TrimEnd('/') ?? "";
    var hostApiKey = config["SVEDA_CLIENT_HOST_API_KEY"] ?? "";
    if (baseUrl.Length == 0 || hostApiKey.Length == 0)
    {
        return Results.Json(new { message = "Set SVEDA_CLIENT_BASE_URL and SVEDA_CLIENT_HOST_API_KEY" },
            statusCode: StatusCodes.Status503ServiceUnavailable);
    }
    using var client = new SvedaClient(new SvedaClientOptions { BaseUrl = baseUrl, HostApiKey = hostApiKey });
    var session = await client.StartHostSessionAsync(new CreateTokenRequest { VisitorId = "aspnet-playground" }, cancellationToken);
    return Results.Json(new { origin = session.Origin, token = session.Token, expires_in = session.ExpiresIn, appearance = session.Appearance });
});

6. 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