Skip to navigation

Posts one JSON-RPC call and returns the Response before the SDK reads its body. Use it in a proxy that has to stream the body through rather than buffer it. ChatGateway uses it to relay a chat reply.

The service pads a slow response with keepalive whitespace so that intermediaries don’t close the connection mid-turn. A proxy that waits for the whole body holds that padding back and brings back the timeout it’s there to prevent. Pass response.body on as it arrives.

Prefer the typed methods unless you are relaying bytes.

You own interpreting the result. On a slow turn the keepalive commits a 200 status before the outcome is known, so an error can arrive under 200. Decide by the body, not the status: look for an error member and compare its code with AI chat errors. Read the body to the end or cancel it, so the connection is released. The client’s readIdleTimeoutSeconds applies to each read.

Parameters

method
stringRequired

The JSON-RPC method, for example chat.

params
Record<string, unknown>Required

The method’s parameters, sent as they are. The client wraps them in the JSON-RPC envelope and supplies the request id.

Returns

Promise<Response> — the response, with its body unread.

Examples

import { serve } from '@hono/node-server';
import { Hono } from 'hono';
import { AIChatClient } from '@signalwire/sdk';
const client = new AIChatClient({ space: 'your-space' });
const app = new Hono();
app.post('/chat', async (c) => {
const { id, message } = await c.req.json<{ id: string; message: string }>();
const upstream = await client.rawPost('chat', { id, message });
return new Response(upstream.body, {
status: upstream.status,
headers: { 'Content-Type': 'application/json' },
});
});
serve({ fetch: app.fetch, port: 3000 });