Testing WebSocket chat endpoints with promptfoo

Testing a streaming chat interface with promptfoo means connecting its WebSocket provider, templating messages and collapsing partial frames into one output. This page covers the setup sequence, the authentication decisions and the failure points.

On this page

Testing WebSocket chat endpoints with promptfoo

The promptfoo WebSocket provider connects to your chat endpoint, sends messages built from a template, and parses the streamed partial responses into one final output that assertions and red team graders can evaluate. Use it when your team has a streaming chat application reached over a WebSocket and needs evals or red team runs against that application, not against a raw model. Testing the raw model behind the application would miss the system prompt, retrieval, tool calls and session logic your users actually reach.

Streaming targets need parsing rules because a single answer arrives as many frames, and those frames may carry tokens, status events, heartbeats, tool activity or a closing marker. Without a parser, promptfoo would grade a fragment or a mix of control messages. Decide before you write the first test what marks the end of a response, which frames carry text, and which frames should be ignored. Capture a few real sessions from a non-production environment and check the frame order by hand, since the provider's configuration keys for templates and response parsing should match what the server really sends. Confirm them against the promptfoo WebSocket provider documentation before you rely on them.

Promptfoo runs on the tester's own machine and talks directly to the endpoint, so the socket, the test prompts and the responses stay between that machine and the application you name in the configuration. Ask your security team which network path that machine can reach, whether the endpoint sits behind a gateway or load balancer that closes idle sockets, and whether test traffic is allowed to reach production or should run against a staging deployment with test data.

Authentication on the socket needs the same planning. Many chat endpoints check a token during the WebSocket handshake or in the first message, so confirm which credential the application expects, where it comes from, and how long it lasts. Use a dedicated test account with the permissions real users have, not an administrator account, and store the token in an environment variable rather than in the configuration file that goes into version control.

What you need before the first socket connects

A WebSocket target is only testable once the tooling, the endpoint and the network path are all in place. The cards below cover what to install, what to request from the endpoint owners and how the test runner reaches an internal socket.

promptfoo version and Node.js runtime

Install promptfoo release 0.124.1 on a runtime that meets its requirement of Node.js 22.22.0 or newer. Pin the version in your repository or CI image so that a later release does not change how the provider parses frames. Check the Node.js version on the exact machine or container that will run the tests, not only on a developer laptop.

promptfoo on npm

Endpoint schema and session model

Before writing any config, confirm with the endpoint owners what a client sends and what the server returns. Ask for the message envelope, how streamed chunks are delimited, which frame marks the end of a reply, and whether the server ties messages to a session or conversation ID. Without these answers, the message template and the parser cannot be written correctly.

WebSocket URL and environment

Get the exact ws:// or wss:// URL for a non-production environment, along with any path, query parameters or subprotocol the server expects. Confirm whether the endpoint can be tested against staging data and whether it rate limits connections or messages. Record these values in your configuration plan so every run targets the same environment.

Test account and credentials

Request a dedicated test account for the socket, separate from production users and from any administrator role. Ask how credentials are issued (static token, login exchange or short-lived ticket) and how long they last, because a token that expires mid-scan will show up as failed tests. Store the credential in your secret manager or CI variables, not in the YAML file.

Network path from the test runner

Trace the route from the machine running promptfoo to the endpoint, including corporate firewalls, egress proxies, API gateways and any allow lists. WebSocket connections are long-lived and often blocked by proxies that expect short HTTP requests, so confirm that upgrade requests pass through each hop. Ask the network team to open the port for the runner's address range before the first run.

Certificates and proxy settings for internal endpoints

Internal endpoints often use certificates issued by a private certificate authority. Obtain the CA bundle and confirm that the Node.js process trusts it, which may require an environment variable pointing at the bundle. If traffic must pass through an HTTP proxy, confirm that the proxy supports WebSocket upgrades and document its settings for the test runner.

How to configure the WebSocket provider step by step

This sequence takes a streaming chat endpoint from a blank config to a verified final output that promptfoo assertions can read. Each step ends with a check so you know the socket, template and parser work before you build the full suite.

  1. Install promptfoo and confirm the runtime

    Install the promptfoo CLI on the machine or CI runner that will reach the chat endpoint. The npm release current at the time of writing requires Node.js 22.22.0 or newer, so check your Node version first. Run the promptfoo version command and confirm it prints a version without errors. If the command fails, fix the Node version or the install before touching the endpoint, because later failures will be harder to read.

  2. Declare the WebSocket provider in the config

    Create a promptfoo configuration file and add a provider entry that uses the WebSocket provider type. Keep this first config minimal, with only the provider and one prompt, so each later change is easy to isolate. Confirm the file parses by running promptfoo's config validation or a dry run. The check is that promptfoo loads the provider without a schema error.

  3. Set the socket URL and connection details

    Add the WebSocket URL for the chat endpoint, copied from the service owner's documentation or your environment, not guessed from the web app address. Use the scheme the endpoint actually serves. If the endpoint needs a path, room or session parameter, include it now. Confirm with the team that owns the endpoint which URL is used in a test environment rather than production. The check is a successful connection in the next manual run.

  4. Write the message template for the frame format

    Write the message template so the request matches the frame format the endpoint expects, including field names, nesting and any type or event key the server uses to route messages. Confirm the exact frame shape from the application's client code or protocol specification, since a near-miss format often returns an error frame rather than a clear failure. Insert the test prompt into the template variable. The check is that the frame you send, as logged in verbose output, matches a frame the real client sends.

  5. Configure the parser to assemble partial frames

    Streaming endpoints usually send many partial frames before a completion marker. Configure the response parser to collect the content fields from the partial frames, stop at the completion signal the endpoint sends, and return one concatenated string. Record which field and marker you chose. The check is that the parser output, shown in verbose logs, contains the full answer text once and does not contain frame metadata or the completion marker itself.

  6. Run one manual prompt against the endpoint

    Run promptfoo once with a single test prompt and the verbose flag so you can inspect the raw traffic and the parsed output. Check the connection, the frames sent, the frames received and the final value. Do this with a test account or a non-sensitive prompt, and confirm with the endpoint owner that the test traffic is allowed. The check is a complete response with no timeout, no truncated text and no error frame treated as success.

  7. Confirm the final output is what assertions read

    Add one simple assertion, such as a contains check for a phrase the endpoint should return for your test prompt, and run it. Assertions read the parsed output, not the raw frames, so this run proves the parser is the value that gets graded. If the assertion fails while the answer looks correct in the raw traffic, the parser is the first place to check. The check is a passing assertion against text you have confirmed by reading the parsed output.

Which socket authentication pattern fits your endpoint

Some WebSocket endpoints accept a credential as a query parameter on the connection URL, for example a token appended to the address the provider connects to. This is the simplest configuration to write and debug, because the whole credential is visible in one place in the provider settings. The cost is exposure: URLs are often written to proxy access logs, load balancer logs and client-side diagnostics, so a token placed there can end up in places a header would not.

  • Simplest to configure: the provider connects to one address with no extra header fields to set.
  • Higher logging risk: gateways and reverse proxies commonly record full request URLs, which can capture the token.
  • Short-lived tokens fit best: a credential that expires quickly limits the damage if a log is shared.
  • Confirm the parameter name: the endpoint must read the exact query key it expects, with no guessing from examples.
  • Watch for redirects: some handshakes redirect, and the token may be forwarded to a new host.

Before relying on this pattern, check your proxy and log retention settings to see whether the URL is stored.

How prompts, frames and outputs map between the test and the socket

This table pairs each promptfoo concept, from the prompt and test variables to the parsed output and assertion input, with the matching piece on the WebSocket side. Read each row as a question to answer before the first run: what leaves the test runner, what the server sends back, and where the final text is taken from. Field names should be confirmed against the WebSocket provider documentation for your promptfoo version, since the provider reads only the settings it documents.

Promptfoo conceptSocket-side equivalentWhat to confirm
PromptOutbound message body sent after connectionMessage template structure and whether your server expects a JSON envelope or plain text
Test variablePlaceholder filled into the outbound message template for each test caseVariable names match the template exactly, including case and nesting
Provider config (URL)WebSocket endpoint address, usually a wss URL for TLSScheme, path and any required query parameters for your environment
Provider config (headers or auth)Handshake fields such as bearer token or cookie sent on connectWhether the server authenticates during the handshake or on the first message
Streamed framesPartial messages the server sends before the answer is completeFrame format (JSON or text) and whether frames carry an identifier for the turn
End-of-turn markerFrame or event signaling that the response is finishedThe exact marker value your application emits and whether it is sent per turn
Parsed outputFinal text assembled from frames and returned to promptfoo as the responseWhich frames are concatenated and which are discarded, such as status or heartbeat messages
Assertion inputThe parsed output compared against your expected resultsAssertions read the parsed text, so a parsing mistake shows up as a false failure

Protecting test credentials and the socket during runs

A WebSocket target often sits in front of a real chat application, so the credentials used to reach it and the traffic it carries need the same care as production access. The cards below cover where socket tokens live, which identity runs the tests, how the connection is protected in transit, what ends up in reports, and how much probe traffic a shared endpoint can absorb.

Keep socket tokens out of config files

Test configs that open a WebSocket often carry a bearer token or session cookie in the headers block. Store that value in an environment variable or your CI secret store and reference it from the config, so the YAML can be committed and shared without exposing the credential. Check that no evaluation output, debug log or copied config repeats the raw value, and rotate any token that was ever pasted into a file under version control.

WebSocket provider docs

Run tests as a dedicated test identity

Create a separate account for promptfoo that has only the chat permissions the suite needs, such as starting conversations and sending messages. Keep it apart from staff accounts and from accounts that can change configuration, billing or user data. Ask the application owner which roles the test account holds and whether it can be disabled quickly if a run misbehaves.

Use wss with verified certificates

Point the provider at a wss:// URL so messages and tokens travel over TLS, and do not disable certificate verification to get past an internal certificate error. If the endpoint uses a private certificate authority, add that authority to the runner's trust store instead. Confirm the certificate chain and hostname with the team that operates the endpoint before the first run.

Keep tokens out of reports and logs

Eval results, HTML reports and CI artifacts record requests and responses, so a token echoed in a message, error or handshake can end up in a shared file. Review what the run writes, exclude or mask sensitive headers before sharing outputs, and set artifact retention in the CI system to match your data handling rules. Treat any report that reached a wide audience as a possible exposure.

Cap red team probe volume

Red team scans send many adversarial messages in a short period, which can slow or disrupt a shared chat service and fill its logs with test traffic. Agree a probe budget and concurrency limit with the endpoint owner, start with a small scan, and schedule larger runs in a window they approve. The Community edition lists 10k probes per month, so count your planned scans against that figure before setting limits.

How a test message travels through the socket and back to an assertion

The run starts in the promptfoo CLI on the tester's machine, which hands each test case to the WebSocket provider. The provider fills the message template, opens the socket to the target endpoint and sends the message. The application streams partial frames back, and the response parser, configured in your provider settings, joins them into one final output. Only that final output reaches the assertion or grader. Check the trust boundary: the socket crosses from your machine into the application, so the handshake and every frame must carry credentials the application accepts.

Flow of one test message from the CLI, through the socket and parser, to an assertion.

Why WebSocket test runs fail and how to fix them

This table lists the failures teams most often hit when pointing promptfoo at a streaming WebSocket chat endpoint, with the likely cause and the fix for each. Read it as a triage guide: match the symptom you see in a run to the row, check the cause first, then apply the fix before changing anything else.

FailureLikely causeFix
Handshake rejectedThe socket URL lacks the token, cookie or header the server expects, or the token has expired between runs.Pass credentials in the provider headers or query string as your server requires, and load them from environment variables so each run uses a fresh token.
Message template does not match the schemaThe message template sends fields in the wrong shape, such as a missing session ID, a renamed key or a string where the server expects an object.Send one raw message by hand from a WebSocket client, copy its exact JSON shape into the template, then rerun a single test case.
Parser returns partial textThe parser reads the first streamed chunk, or the end-of-turn signal is different from what the parser waits for.Confirm the exact final-message marker with the application team, then parse only that frame and log the raw frames for one failing case to verify it.
Timeouts on long streamsThe provider timeout is shorter than a full generated answer, or an intermediate proxy closes idle sockets during slow generation.Raise the provider timeout for long answers and check proxy and load balancer idle limits with the infrastructure team.
Connection drops between turnsThe server closes the socket after each response, or a keepalive is missing so an idle connection is dropped during test pauses.Confirm whether the server expects one connection per turn or a persistent session, then reconnect per turn or send the keepalive the server documents.
Session state leaks across testsTests share one connection or session ID, so earlier conversation context shapes later answers and skews grading.Give each test case its own session ID or connection, and treat any result that depends on test order as a finding to fix before trusting the suite.

Questions teams ask before testing a WebSocket chat app

How much effort does a promptfoo WebSocket setup take?

The effort depends mainly on how the socket protocol is shaped, not on promptfoo itself. A simple endpoint that accepts one JSON message and streams text back needs a short configuration and a few test runs to validate. Effort rises when the endpoint needs a handshake, session identifiers, several message types, or a stream that signals completion in a non-obvious way. Your team should first list the message sequence for one complete exchange, then decide which frames carry the answer. No duration is supplied for this work, so ask any implementation partner to base its estimate on a written message sequence and a sample of real frames.

What makes the WebSocket parser rules hard to get right?

Parser rules decide when a streamed response counts as finished and what text becomes the final output. Partial frames, status messages, heartbeats, and tool-call events all arrive on the same socket, and each one needs a rule that ignores it or keeps it. Teams often find that the parser is the largest source of rework, because a wrong rule produces grades on incomplete text that look like model failures. Collect several captured sessions, including error and timeout cases, before writing the parser so the rules match what the application actually sends.

Can our own team set this up without outside help?

Yes, if one engineer understands the chat protocol and another can work with authentication and test data. The WebSocket provider is configured in promptfoo's configuration file, and the documentation describes the message template and response parsing options. Outside help is most useful when the socket sits behind an unfamiliar gateway, uses token rotation, or must be tested against several environments with different access. Whether to build it internally or with a partner depends on your team's time and on how many endpoints you plan to cover.

What do application owners need to provide for the test?

Application owners should provide the message format, the sequence of frames for a complete reply, and the way the stream ends. They also need to name a test environment that accepts synthetic traffic, a test account with limited permissions, and a contact for questions about rate limits or logging. Without these, testers guess at framing and may trigger alerts in production monitoring. Ask owners to confirm in writing which environment is safe for red teaming and which data the endpoint stores.

Does promptfoo cost anything to test a WebSocket endpoint?

The WebSocket provider is part of promptfoo's open-source software, which is licensed under the MIT license. The promptfoo pricing page states that the Community edition is free and includes all LLM evaluation features, all model providers and integrations, and red teaming with 10k probes per month, with community support. Your costs for this work are mostly the people time to configure and maintain the parser, plus any model calls made by graders or red team strategies, which are billed by whichever model provider you use. Confirm your expected probe volume against the free monthly allowance before scheduling large runs.

What changes if the chat endpoint must stay on site?

Running promptfoo locally keeps evaluation traffic on the machine where it runs. The promptfoo documentation states that evals run on your machine and talk directly with the LLM, so an on-site endpoint can be tested from an on-site runner without sending data to a promptfoo service. If you need a shared team server, the self-hosted app is an Express server deployable with Docker, Docker Compose or Kubernetes with Helm, but it uses a local SQLite database that cannot be shared across replicas and lacks RBAC and built-in SSO, so it is not recommended for production use. Shared access controls and SSO are part of the Enterprise and On-Premise editions, which run on your infrastructure with a dedicated deployment engineer, priced on a custom basis. Ask the vendor to confirm the current terms before you plan around them.

How do we check the test is valid before using results?

Start with a known-good conversation and a known-bad one, and confirm the parser returns the same final text you see in the application's own interface. Then run a few repeated tests to see whether the output is stable enough to grade. Keep a short log of frames that were dropped or misread, because those notes explain most surprising scores later. Treat the first set of runs as a calibration step for the parser, not as evidence about the model.

How DeployOpen scopes and delivers WebSocket target testing

DeployOpen approaches WebSocket target testing as a scoped piece of work on your own infrastructure. We start from the chat endpoint you need tested, agree the message templates, response parsing and socket authentication in writing, then build and hand over a promptfoo configuration your team can run and extend. Engagements are fixed-scope, with ongoing support available as a retainer.

How we scope

  • Confirm which WebSocket endpoint, message schema and streaming behavior the promptfoo suite must cover
  • Agree in writing how partial frames become one final output for grading
  • Record the socket authentication method, test accounts and network path to the endpoint
  • Define whether the scope includes evals, red teaming, or both, and the environments in scope

How we build

  • Write the WebSocket provider configuration with message templates matching your client's payloads
  • Build response parsing that collects streamed chunks until the end-of-message signal arrives
  • Validate the target first with a small set of connection and single-turn checks before wider test runs
  • Run the suite against your staging environment inside your own infrastructure, not a vendor-hosted service

How we hand over

  • Deliver the promptfoo configuration, parsing logic and authentication settings as versioned files
  • Document how to rotate socket credentials, update templates and add new test cases
  • Walk your engineers through running the suite locally and from your CI pipeline
  • Provide written findings with fixes and a retest where red teaming is in scope

How we support

  • Update the provider configuration when your chat protocol or message schema changes
  • Review promptfoo upgrades against the WebSocket setup before your team adopts them
  • Extend the suite as new features, plugins or strategies are needed for your application
  • Offer ongoing support, upgrades and continuous testing as a retainer if your team wants it

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.