Docs

Conformance tests for OpenAI-compatible LLM gateways

gatewayproof catches streaming, usage, cost, concurrency, and error-handling bugs that an eyeball review of a diff will not. It compares your gateway with a deterministic mock upstream, so the expected response is known before the request is sent.

Why the bugs are easy to miss

An LLM gateway sits between your application and the model provider. On every request it re-streams the response, recomputes token usage, calculates cost, and propagates upstream failures. A gateway that drops the last streamed chunk still looks successful in a quick manual test. A wrong cost still returns a number. An upstream error swallowed as finish_reason: "stop" looks like a complete answer.

There is no ground truth when a real model is in the path, because you do not know in advance what it should say. gatewayproof replaces that provider with a scripted mock.

How it works

  1. gatewayproof starts a mock upstream that speaks /v1/chat/completions. Every response is scripted: content, token usage, and timing are the ground truth.
  2. You point the gateway under test at that mock, the same way you would point it at api.openai.com.
  3. gatewayproof sends requests through your gateway and compares what comes back with the script. Anything the gateway added, dropped, or miscalculated fails the check.

The five checks

Each check is independent. A gateway can fail one without failing the others.

CheckBug it catches
streaming-fidelityA dropped, duplicated, or reordered chunk mid-stream. The streamed response, reassembled, does not match a non-streamed call for the same request.
usage-accuracyWrong prompt_tokens, completion_tokens, or total_tokens, in a streamed final chunk or a non-streamed response body.
cost-accuracyA wrong cost calculation. The check reads the gateway's reported cost (LiteLLM's x-litellm-response-cost header by default, pluggable for others) and compares it with usage times your pricing table.
concurrent-isolationContent from one concurrent request leaking into another's stream, which shows up in gateways that multiplex streams over shared internal state.
error-propagationAn upstream error mid-stream reported to the caller as a clean finish_reason of stop, which looks exactly like success.

Quickstart

Pick a fixed local port, configure the gateway's upstream to that port, and start the gateway. The suite binds the mock to that same port, then calls the gateway.

npx gatewayproof run --target http://localhost:4000 --mock-port 5055
Mock upstream: http://127.0.0.1:5055
Target gateway: http://localhost:4000

PASS  streaming-fidelity -- Streamed content matches non-streamed content
PASS  usage-accuracy -- Reported token usage matches the upstream
FAIL  cost-accuracy -- Reported cost matches usage x the pricing table
      expected cost 0.00019999999999999998, got 0.000001
PASS  concurrent-isolation -- Concurrent streams never leak content
PASS  error-propagation -- A mid-stream failure surfaces as an error

4/5 checks passed.

Exit code 0 means every check passed. Exit code 1 means at least one failed.

Install

npm install --save-dev gatewayproof

GitHub Action

The reusable action builds the suite and runs it against a gateway you have already started. mock-port must be the port that gateway is configured to forward to.

- name: Start your gateway
  run: |
    my-gateway serve --port 4000 &
    sleep 2

- name: Run gatewayproof against it
  uses: jayblast-spec/gatewayproof@main
  with:
    target: http://localhost:4000
    mock-port: '5055'

Library

Use the library when a test owns the gateway process and can point it at the mock URL directly.

import { startMockUpstream, runChecks } from "gatewayproof";

const mock = await startMockUpstream(5055);
const gateway = await startMyGateway({ upstreamUrl: mock.url });

const report = await runChecks({ targetBaseUrl: gateway.url, mock });
console.log(report.passed, report.results);

await gateway.stop();
await mock.stop();

What v1 does not do

  • It is not a load test or a latency benchmark. The scenarios are few and scripted.
  • It is not a fuzzer. Each check uses a fixed script.
  • It does not cover provider-specific features such as function calling or vision. It covers the chat-completions streaming, usage, and cost surface that OpenAI-compatible gateways share.

This site is a static export of the project docs. The conformance suite itself runs locally or in GitHub Actions against your gateway. It does not run in the browser.

Support