HOST
Go
No framework required. net/http plus the module is the host. Templates only render chat buttons when the origin is set.
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. Add the module
Local playgrounds use a
replace
to the sibling
sveda-go
checkout. No Gin or Echo required.
go get github.com/neresson/sveda-go 3. Env
SVEDA_CLIENT_BASE_URL=http://127.0.0.1:8787
SVEDA_CLIENT_HOST_API_KEY=replace-me 4. POST /sveda/session
sveda.StartHostSession
returns a struct tagged
origin,
token,
expires_in,
appearance.
Empty env returns an error — map that to 503.
mux.HandleFunc("POST /sveda/session", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
session, err := sveda.StartHostSession(r.Context(), sveda.Config{
BaseURL: os.Getenv("SVEDA_CLIENT_BASE_URL"),
HostAPIKey: os.Getenv("SVEDA_CLIENT_HOST_API_KEY"),
}, "go-playground")
if err != nil {
w.WriteHeader(http.StatusServiceUnavailable)
json.NewEncoder(w).Encode(map[string]string{"message": err.Error()})
return
}
json.NewEncoder(w).Encode(session)
}) 5. Templates
Only emit
data-sveda-*,
chat buttons, and
sveda-host.js
when
SvedaOrigin
is non-empty.
<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>