Skip to content

fix(core): keep the X-PAYMENT header ASCII so 402 challenges with non-ASCII extensions are payable - #110

Merged
vapi-development merged 1 commit into
vAPI-Network:mainfrom
ege-arhan:fix/x-payment-ascii-header
Dec 1, 2026
Merged

vapi-development merged 1 commit into
vAPI-Network:mainfrom
ege-arhan:fix/x-payment-ascii-header

Conversation

@ege-arhan

Copy link
Copy Markdown
Contributor

What & why

vapi pay aborted every call to a server whose 402 challenge carried non-ASCII text in extensions, with Cannot convert argument to a ByteString because the character at index ... has a value of 8230 and no receipt. Fixes #109.

The challenge metadata is echoed into the payment payload. PAYMENT-SIGNATURE is base64 and carries UTF-8 fine, but the legacy X-PAYMENT header is a raw JSON string, and Headers.set rejects any code point above 0xff. The text came from the server's own bazaar description (ECB reference rates are…), so the failure depends on the resource, not on the wallet or the amount. Reproduced against https://api.stablecoingateways.com/v1/fx/rates?base=EUR&symbols=USD,GBP, which returns a 402 with three U+2026 characters in extensions.bazaar.

Changes

  • packages/core/src/x402.ts: new encodeLegacyPaymentHeader, which serializes the compatibility payload and escapes every code point from U+007F up as \uXXXX. buildCompatibleX402Payment uses it for X-PAYMENT.
  • packages/mcp/src/x402.ts: the same builder there uses the shared helper instead of a second JSON.stringify.
  • packages/core/src/x402.test.ts: a challenge whose bazaar info contains … now produces a header that Headers.set accepts, and parsing it returns the extensions unchanged.
  • CHANGELOG.md: entry under Unreleased.

Escaping rather than dropping keeps the payload byte-identical after JSON.parse, so a facilitator reads the same extensions that PAYMENT-SIGNATURE carries and the compatibility header stays a faithful copy. Only the header encoding changes; no protocol field is added, renamed or removed.

Checked with pnpm format:check, pnpm lint, pnpm typecheck, pnpm test, pnpm build and pnpm pack:check. packages/core ran 2492 tests and packages/mcp 40 in x402.test.ts; nothing else was touched. The first full pnpm test run hit two timeouts in vault-key.test.ts, which passed when the file ran alone and in the next full run.

Checklist

  • pnpm lint && pnpm typecheck && pnpm test && pnpm build && pnpm pack:check pass locally
  • Tests added or updated for behaviour changes
  • No runtime dependencies added to a published package (everything is bundled)
  • Keys, payments, and telemetry stay on the user's machine (non-custodial invariant in AGENTS.md)
  • Docs/README updated if the CLI, MCP tools, or config changed
  • Commits are signed off (git commit -s, Developer Certificate of Origin)

Breaking changes

None. The header is still a JSON object with the same keys and values after parsing; only characters above U+007E are written as escapes.

@ege-arhan
ege-arhan force-pushed the fix/x-payment-ascii-header branch from 31160e4 to b63331e Compare December 1, 2026 07:40
…-ASCII extensions are payable

A 402 challenge echoes its own metadata back into the payment payload. When a
server's `extensions` carried typographic text such as `…` (U+2026), the legacy
`X-PAYMENT` header was a raw JSON string with that code point in it, so
`Headers.set` threw `Cannot convert argument to a ByteString because the
character at index ... has a value of 8230` before the request left the machine.
Every paid call to such a server failed, and `vapi pay` printed no receipt.

Non-ASCII code points are now escaped when the compatibility header is built.
The JSON parses back to the same value that `PAYMENT-SIGNATURE` carries, so
facilitators see the extensions unchanged.

Fixes vAPI-Network#109

Signed-off-by: ege-arhan <[email protected]>
@ztsrdev
ztsrdev force-pushed the fix/x-payment-ascii-header branch from b63331e to 769d8f2 Compare December 1, 2026 10:45

@vapi-development vapi-development left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks — this is the right fix. X-PAYMENT was the only header carrying raw JSON (PAYMENT-SIGNATURE and SIGN-IN-WITH-X are base64 of UTF-8), so escaping there covers every case. I rebased onto main and moved the changelog line under the current Unreleased section.

@vapi-development
vapi-development merged commit db84a20 into vAPI-Network:main Dec 1, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vapi pay crashes with "Cannot convert argument to a ByteString" (char 8230) calling stablecoingateways

2 participants