Website assistant
The website assistant is a chat box for a public website. A visitor types a question, such as "can I host this myself?", and gets a short answer in plain language with numbered links to the pages the answer came from. It only answers from pages you have published, it never stores the conversation, and it is off until you turn it on.
Behind the box are two routes on the gateway, POST /public/assistant/chat and GET /public/assistant/search. They need no key, because visitors have none, so they are protected in other ways: only the websites you list may call the chat route, every visitor address has a small message allowance, the whole gateway has a daily ceiling, and every model call goes back through the gateway with a dedicated virtual key whose budget is the hard limit on what the assistant can spend.
A real-world scenario
A visitor on your pricing page wants to know whether the free plan includes single sign-on. They open the assistant and ask. The assistant searches your published documentation and website, finds the pricing page and the single sign-on guide, and answers in two sentences with links to both. When they then ask for a quote for 40 seats, the assistant does not guess a price. It shows a card that opens an email to your sales mailbox with a short summary of the question already filled in.
Your operations team sees one log line for that turn with the token count, the cost and which pages were used, but never the question, the answer or the visitor's address.
How it works
- A knowledge index is built from the finished docs site and the finished website, the same HTML a reader sees. Internal pages are never part of the docs build, and any path under
internal/is skipped even if it is present. The build splits each page by heading, creates search vectors for new or changed sections only, checks itself against a set of about 60 known questions, and publishes only when at least 90 percent of them find the right page in the top five results. - Each gateway checks for a new index every 60 seconds, verifies its checksum and swaps it in. A broken index is refused and the previous one keeps serving.
- For each question the gateway checks the Origin, the visitor allowance and the daily ceiling, finds the best matching sections with keyword and meaning search, and asks the model. The model may call at most three read-only tools per turn: search the docs, look up a published model's price and limits, estimate a workload's cost, or read one indexed page. It can also ask one clarifying question or hand the visitor to sales or support.
- Before anything is shown, the answer is checked. Citations that do not point at a page used in this turn are removed, any price that did not come from a tool result is removed, and an answer that names a competitor or other forbidden wording is replaced. An answer with no valid citation becomes a polite decline with a support card.
- The conversation lives in the visitor's browser tab as a sealed, encrypted token that expires after two hours and holds at most the last six turns. The token never grows past 8,192 characters: when a long chat would make it bigger, the oldest turns are dropped first, so a long conversation keeps working and only forgets its beginning. A chat ends after 20 turns.
Set it up
-
Create the three model groups the assistant uses, each with permission for the assistant to switch message logging off. Every call the assistant makes asks the gateway not to log the visitor's words, and the gateway only accepts that request from a caller when the model allows it. A model without the permission refuses every assistant call, so visitors see 503
unavailableon every question.In the Admin UI open Models + Endpoints, choose Add Model and add
assistant-chat(for exampleanthropic/claude-haiku-5-5). Before you save, open Advanced Settings and put this in Spanway Params:{"configurable_clientside_auth_params": ["turn_off_message_logging"]}Add
assistant-chat-fallback(for exampleopenai/gpt-5.4-mini) andassistant-embed(openai/text-embedding-3-small) the same way, with the same Spanway Params. Then open Settings, Router Settings, Fallbacks and addassistant-chat-fallbackas the fallback forassistant-chat. If the three models already exist without the setting, delete them in Models + Endpoints and add them again with it. With the API, one call per model:add_model() {curl -X POST http://localhost:4000/model/new \-H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json" \-d '{"model_name": "'"$1"'", "spanway_params": {"model": "'"$2"'", "api_key": "os.environ/'"$3"'","configurable_clientside_auth_params": ["turn_off_message_logging"]}}'}add_model assistant-chat anthropic/claude-haiku-5-5 ANTHROPIC_API_KEYadd_model assistant-chat-fallback openai/gpt-5.4-mini OPENAI_API_KEYadd_model assistant-embed openai/text-embedding-3-small OPENAI_API_KEYExpected result: each call answers 200 with the new model's
model_id. Or in the config:model_list:- model_name: assistant-chatspanway_params:model: anthropic/claude-haiku-5-5api_key: os.environ/ANTHROPIC_API_KEYconfigurable_clientside_auth_params: ["turn_off_message_logging"]- model_name: assistant-chat-fallbackspanway_params:model: openai/gpt-5.4-miniapi_key: os.environ/OPENAI_API_KEYconfigurable_clientside_auth_params: ["turn_off_message_logging"]- model_name: assistant-embedspanway_params:model: openai/text-embedding-3-smallapi_key: os.environ/OPENAI_API_KEYconfigurable_clientside_auth_params: ["turn_off_message_logging"]Add them as a proxy admin, because a team admin may only list
api_keyin this setting. The setting lets callers turn message logging off for these three models and nothing else. It does not let anyone change the provider key, the endpoint or any other part of the model, and other models keep refusing the flag. -
Create the key the assistant spends with. Open Virtual Keys, choose Create New Key, limit it to the three models above, set a budget of 5 USD that resets daily, and set a team budget for the absolute monthly ceiling. With the API:
curl -X POST http://localhost:4000/key/generate \-H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json" \-d '{"key_alias": "assistant-public", "models": ["assistant-chat", "assistant-chat-fallback", "assistant-embed"],"max_budget": 5, "budget_duration": "1d", "rpm_limit": 120, "max_parallel_requests": 16}'You do not need to turn message logging off on the key. Every model call the assistant makes carries
"turn_off_message_logging": trueitself, so the spend logs and logging callbacks never receive the visitor's words. That is why the three models need the setting from step 1. -
Tell the gateway which load balancers sit in front of it, so it can see each visitor's own address. In the Admin UI open Settings > Admin Settings > Security Settings, find Network allowlists and enter the address range of your load balancers under Trusted reverse proxies, for example the VPC range
10.40.0.0/16on the AWS stack. Enter[]when visitors reach the gateway directly. Or in the config:general_settings:trusted_proxy_ranges: ["10.40.0.0/16"]See what the trusted reverse proxies setting does for what changes when it is set, empty or missing.
-
Give the gateway that key as
SPANWAY_ASSISTANT_KEY, and make sureSPANWAY_SALT_KEYis set to the same value on every gateway, because it seals the conversation token and keys the anonymous visitor counters. -
Build the first index. The build is the
assistant-indexrole of the gateway image, so it runs as a one-off container (or a one-off Kubernetes or ECS task with the same image) and reads three environment variables. Each source is an S3 bucket name or afile://directory inside the container. This example mounts the built docs and website from the current directory and writes the index to./assistant-index:mkdir -p assistant-indexdocker run --rm --entrypoint spanway-container --user "$(id -u):$(id -g)" \-e SPANWAY_ASSISTANT_DOCS_SOURCE=file:///src/docs \-e SPANWAY_ASSISTANT_WEBSITE_SOURCE=file:///src/website \-e SPANWAY_ASSISTANT_INDEX_BUCKET=file:///out \-e OPENAI_API_KEY \-v "$PWD/docs/build:/src/docs:ro" \-v "$PWD/website/out:/src/website:ro" \-v "$PWD/assistant-index:/out" \registry.spanway.ai/spanway/spanway-ai:2.0.0 assistant-indexWith S3 sources and an S3 index bucket, drop the three mounts, pass the bucket names instead and give the task an AWS role that can read the sources and write the bucket.
Expected result: the log line
public_assistant index <version> published: <n> chunks, <n> embedded, hit rate 0.9xxand exit code 0. -
Turn the assistant on. In the Admin UI open Status Page and find the Website assistant card under Public surfaces. Fill in Allowed websites and Index bucket, click Save website assistant settings, then turn on the Serve POST /public/assistant/chat switch. Each control has a short explanation under it. A proxy admin can change them, other admins see them read only, and values set in the config file are locked. With audit logging on, every change writes a
Spanway_Configaudit row. Or in the config:general_settings:public_assistant: truepublic_assistant_index_bucket: my-assistant-index-bucketpublic_assistant_origins:- https://www.spanway.ai- https://spanway.aipublic_assistant_daily_turn_ceiling: 5000 -
Ask a question the way the website does:
curl -X POST http://localhost:4000/public/assistant/chat \-H "Origin: https://www.spanway.ai" -H "Content-Type: application/json" -H "Accept: application/json" \-d '{"message": "Can I self-host Spanway for free?", "page": "/pricing/"}'Expected result:
{"text": "Yes. Starter is free to self-host and needs no license key [1].","citations": [{"n": 1, "url": "https://www.spanway.ai/pricing/", "title": "Pricing > Starter"}],"clarifying_question": null,"handoff": null,"state": "mcp_state_v1.…","turn_id": "7f3c…","turn_index": 1,"turns_left": 19,"knowledge_updated": "2026-11-20T08:00:00Z","usage": {"input_tokens": 2100, "output_tokens": 90}}Without
Accept: application/jsonthe same answer streams as server-sent events:deltaevents with the text, then oneanswerevent with the citations, clarifying question and handoff, then adoneevent with thestatetoken for the next turn. Send that token back asstateto continue the chat. -
Check the search route the website falls back to while the assistant is paused. It calls no model:
curl 'http://localhost:4000/public/assistant/search?q=single+sign-on'
Settings
All under general_settings. They can be set in the config or in the Admin UI on the Website assistant card of Status Page.
| Key | Default | What it does |
|---|---|---|
public_assistant | false | Serves both routes. When false they answer 404 and the website hides the assistant. |
public_assistant_origins | https://www.spanway.ai, https://spanway.ai | Websites allowed to call the routes. The chat route refuses any other Origin, or none, with 403. The search route refuses a browser call from any other Origin with 403 and allows a call with no Origin header, such as curl. |
public_assistant_index_bucket | unset | S3 bucket holding index/manifest.json and the index files, or a file:// directory for local use. Unset means no index, so both routes answer 503 not_ready. |
public_assistant_daily_turn_ceiling | 5000 | Most turns the whole gateway answers per UTC day across every visitor. Without Redis this applies per gateway process, see below. |
Fixed limits per visitor address: 10 turns a minute, 60 an hour and 200 a day, plus 600 turns an hour across all visitors. Five declined questions in ten minutes from one address start a 15 minute pause for that address only. The search route allows 30 searches a minute and 300 an hour per address. Visitor addresses are never stored: the counters use a keyed hash of the address that changes every day. The address is the one your load balancer forwards, which is why trusted_proxy_ranges must be set, and both routes answer 503 unavailable until it is. With Redis configured the counters live there, so every gateway and worker shares them, and when Redis is unreachable the chat route refuses turns while the search route keeps working without its limit. Without Redis each gateway process keeps its own counters in memory, so every limit above, the 600 turns an hour across all visitors and public_assistant_daily_turn_ceiling included, applies once per process. A gateway with four workers on three replicas can then serve twelve times the limit, so configure Redis for any deployment with more than one worker or replica.
The chat route needs a Content-Length header and accepts bodies up to 24 KB, which is enough for the largest state token plus a 2,000 character message in any language. Browsers and curl send the header on their own. On AWS the web firewall applies the same limit from that header, so long chats are never cut off by the firewall's 8 KB body inspection window.
Trusted reverse proxies
A load balancer sits between most visitors and the gateway. Every request then arrives from the load balancer's own address, and the visitor's real address travels in the X-Forwarded-For header. Anyone can write that header, so the gateway only believes it when the request comes from an address you listed in trusted_proxy_ranges (Trusted reverse proxies in Settings > Admin Settings > Security Settings). It is not a switch, it has three states, and it is unset by default.
- Set to your load balancer ranges, such as
["10.40.0.0/16"]. The gateway reads each visitor's real address from the header your load balancer adds, so every visitor gets their own message allowance and one busy visitor never pauses the assistant for anyone else. A visitor who writes a fakeX-Forwarded-Forgains nothing, because the gateway skips past the entries your load balancer did not add. Use this whenever a load balancer or ingress sits in front of the gateway. - Set to an empty list,
[]. The gateway believes no forwarding header and uses the address of whoever connected. Use this only when visitors reach the gateway directly. Behind a load balancer every visitor would then share one allowance. - Not set, the default. The gateway cannot tell visitors apart safely, so both assistant routes answer 503
unavailableand the gateway logs one warning per process. This keeps the assistant off until someone decides how visitor addresses are read.
The same setting also decides which address the sign-in throttle, IP allow lists and the spend logs record, so set it to the ranges that are really in front of the gateway. A proxy admin should change it. See trusted reverse proxies for the other features that use it.
On AWS
The reference AWS deployment puts web firewall rules in front of /public/assistant/ that answer before the gateway sees the request. A country rule blocks the assistant from the countries in blocked_country_codes, or from the countries in the sanctions rules when that variable is empty, with the firewall's plain 403 page. A rate rule allows each address 60 requests in 5 minutes across chat and search together, set by waf_assistant_rate_limit_per_5_minutes, and answers 429 with {"kind": "rate_limited", "retry_after": 300} and Retry-After: 300. The body size rule refuses a chat request over 24 KB. Setting waf_assistant_bot_control to true adds the AWS Bot Control rule group, which costs about 10 USD a month plus 1 USD per million requests. Behind these rules the gateway's own allowances still apply, so the tighter of the two wins.
The gateway's CORS middleware answers the browser's preflight request. When SPANWAY_CORS_ORIGINS is set, include your website origins in it.
Runbook
- Rotate the assistant key. Create a new key with the same settings, replace
SPANWAY_ASSISTANT_KEYand restart the gateway, then delete the old key in Virtual Keys. - Rebuild the index by hand. Run the same one-off
assistant-indexcontainer or task as in step 5. An unchanged corpus publishes nothing and embeds nothing. A build that falls below the 90 percent hit rate or would embed more than 2.5 million tokens exits non-zero and leaves the published index untouched. - Raise or lower the budget. Edit the key's budget in Virtual Keys. No deploy is needed. When the budget runs out the chat route answers 503
unavailableand the website switches to search only. - Turn the assistant off. Turn off Serve POST /public/assistant/chat on the Website assistant card of Status Page. Both routes answer 404 within a few seconds and the website hides the assistant.
Privacy
Every model call the assistant makes asks the gateway to leave the messages out of its logs, so the spend logs hold the model, tokens, cost, latency and the tag public-assistant, but no prompt or answer. The gateway log gets one line per turn with the hashed address bucket, turn number, model, tokens, cost, tool names, page addresses used and the outcome, never the question, the answer, the raw address or the browser's user agent. The conversation itself exists only in the visitor's browser tab. When a visitor uses a sales or support card, their own mail app sends the email. The gateway never sees or stores it.
Errors
Every error the assistant itself returns has the same small body, {"kind": "...", "retry_after": ...}, and never carries provider error text. The 404 while the assistant is off uses the gateway's standard {"detail": "The website assistant is not enabled"} body.
| Status | kind | Meaning | Fix |
|---|---|---|---|
| 400 | invalid_request | The message is empty or longer than 2,000 characters, the body has no Content-Length header or is over 24 KB, the state token is longer than 8,192 characters, the body has unknown fields, page is not a path that starts with / (letters, digits and . _ ~ / - only, at most 256 characters), or the search q is missing, empty or over 300 characters. | Send {"message": "..."} with optional state and page. The website widget forgets its saved state after a 400 or 403, so the next message starts a fresh chat. |
| 403 | forbidden_origin | The chat route got no Origin header, or one not in public_assistant_origins. The search route got an Origin header that is not in the list. | Call it from an allowed website, or add the origin to the setting. |
| 403 | none, the firewall's own page | On AWS, the request came from a country the web firewall blocks for the assistant. | Expected for those countries. Change blocked_country_codes only with legal advice. |
| 404 | none, {"detail": "The website assistant is not enabled"} | public_assistant is off. | Turn it on. |
| 409 | ended | The chat reached 20 turns. | Start a new chat without state. |
| 429 | rate_limited | The visitor address used its chat or search allowance, the gateway reached its ceiling, the address is in its 15 minute pause, or on AWS the address sent more than 60 requests in 5 minutes and the web firewall answered with retry_after 300. Retry-After says when to try again. | Wait. Raise public_assistant_daily_turn_ceiling if the ceiling is too low for real traffic. |
| 503 | not_ready | No index is loaded yet. | Build the index and check public_assistant_index_bucket. |
| 503 | unavailable | One of the three assistant models lacks configurable_clientside_auth_params: ["turn_off_message_logging"], so the gateway refused the assistant's own model call and logged Rejected Request: turn_off_message_logging is not allowed in request body. Or the model call failed after fallback, the key budget is used up, the turn took longer than 30 seconds, the counters are unreachable, SPANWAY_ASSISTANT_KEY or SPANWAY_SALT_KEY is not set, or trusted_proxy_ranges is not set so the visitor's address is unknown. The search route answers it too when the salt key or trusted_proxy_ranges is missing. | Look in the gateway log first. A Rejected Request: turn_off_message_logging line means a model lacks the setting, so add it to the three models as in step 1. A turn failed, answering unavailable line names the failure kind and the status of the internal model call, and an admission counters are unreachable line names the Redis error, see the Logs section below. GET /health/readiness shows "coordination_redis": "error" while Redis is down. Then check the key budget, the provider keys, Redis, the two environment variables and trusted_proxy_ranges. |
Logs
| Level | Line | Meaning |
|---|---|---|
| INFO | public_assistant.turn {...} | One line per turn with counts, pages and the outcome (answered, clarified, declined, handoff_sales, handoff_support, price_scrubbed, forbidden_term, rate_limited, cooldown, unavailable, ended). Normal. Many forbidden_term or price_scrubbed outcomes mean the docs or the prompt need attention. |
| INFO | public_assistant index swapped to version ... | A gateway loaded a newly published index. Normal. |
| WARNING | public_assistant index swap refused, keeping the previous index: ... | A published index failed its checksum or validation, or could not be downloaded. The previous index keeps serving. Rebuild the index. |
| WARNING | public_assistant index first load timed out | The first download took longer than 10 seconds. The chat answers not_ready until the next check, 60 seconds later, finishes the download. A failed or cut off download is always tried again in full. Check access to the index bucket if it keeps happening. |
| WARNING | public_assistant is on but trusted_proxy_ranges is not set, ... | The gateway cannot tell visitors apart, so both routes answer 503 unavailable. Logged once per process. Set trusted_proxy_ranges as in step 3. |
| ERROR | user_api_key_auth(): Exception occured - Rejected Request: turn_off_message_logging is not allowed in request body. ... | A model the assistant calls does not allow callers to turn message logging off, so the gateway refused the assistant's own call and the visitor got 503 unavailable. Action needed. Add configurable_clientside_auth_params: ["turn_off_message_logging"] to assistant-chat, assistant-chat-fallback and assistant-embed as in step 1. |
| WARNING | public_assistant admission counters are unreachable, search is not limited (<error class>: <message>) | Redis is down. Search keeps answering without its per address limit until Redis is back. The brackets name the Redis error, for example (ConnectionError: Connection refused), cut to 160 characters. |
| WARNING | public_assistant admission counters are unreachable, refusing chat turns (<error class>: <message>) | Redis is down. Chat turns get 503 until it is back. GET /health/readiness shows "coordination_redis": "error" at the same time. |
| WARNING | public_assistant could not record a decline, counters are unreachable (<error class>: <message>) | Redis is down, so a declined question did not count towards the 15 minute pause. Check Redis. |
| WARNING | public_assistant turn failed, answering unavailable: kind=<kind> loopback_status=<status> | A chat turn answered 503 unavailable because the model call failed. kind=quota means the gateway refused the assistant key: loopback_status=422 is a spent budget, 401 a deleted key, a wrong SPANWAY_ASSISTANT_KEY or a model without the turn_off_message_logging setting from step 1, and 400, 403 or 429 a model the key may not use or a rate limit. kind=error means any other failure, such as a provider outage (loopback_status=500), an answer the assistant could not read (loopback_status=200), or no connection at all (loopback_status=none). kind=timeout means one model call took longer than 15 seconds, and kind=turn_timeout means the whole turn took longer than 30 seconds. The gateway's own error lines from the same moment, for example an authentication or budget error for the assistant key, give the details. The line never carries the question or the visitor's address. |
| INFO | public_assistant index ... published: ... | The index build published a new index. Normal. |
| INFO | public_assistant index <version> unchanged | The build found the same corpus as the published index, so it published and embedded nothing. Normal. |
| INFO | public_assistant index current: version ... | The build published a new index or confirmed the current one is up to date. Normal. On AWS the stale index alarm counts this line, so it alarms when no build has succeeded for 7 days. |
| ERROR | public_assistant index not published: golden hit rate ... below 0.90 | The new index found the right page for too few known questions, so nothing was published. Check the docs build, then rebuild. |
| ERROR | public_assistant index not published: ... embedding tokens exceed the run cap | The build would have embedded more than 2.5 million tokens, so it stopped before spending anything. Check for a runaway page or a corpus change. |
| ERROR | public_assistant index not published: no pages found in the site sources | The docs or website source was empty or unreadable. Check the bucket names and the task's read access. |
| ERROR | public_assistant index not published: the manifest changed during two attempts | Another build published at the same time twice in a row, so this one gave up. Run one build at a time. |
| ERROR | public_assistant index build needs SPANWAY_ASSISTANT_DOCS_SOURCE, SPANWAY_ASSISTANT_WEBSITE_SOURCE and SPANWAY_ASSISTANT_INDEX_BUCKET | The build was started without one of its three environment variables, so it exits with code 2 before reading anything. Set all three as in step 5. |
Related
- Public model catalogue, which the price lookup tool reads. When
public_catalogueis off the assistant cannot look up models or prices either and says so. It sees each model's name, provider, limits, prices, features and health, never its request counts or error rates. - Trusted reverse proxies for
trusted_proxy_ranges. - Virtual keys and budgets for the assistant key.
- Audit logs for the rows that settings changes write.
- Settings reference for every general setting.