raw_post

View as MarkdownOpen in Claude

An async context manager that yields the underlying response for one JSON-RPC call before the SDK parses its body. ChatGateway uses it when relaying a response body.

Prefer the typed methods unless you are genuinely relaying bytes.

Parameters

method
strRequired

The JSON-RPC method name.

params
dict[str, Any]Required

The method’s parameters. The client wraps them in the envelope and supplies the request id.

Returns

aiohttp.ClientResponse, yielded by the context manager with its body unread.

You own interpreting the result. Check the HTTP status first; on 200, inspect the JSON-RPC body for an error member and compare its code with AI chat errors. You can iterate resp.content for chunk-level access, but the public endpoint may already have buffered the response it received from the AI chat service.

Example

1import asyncio
2
3from signalwire.ai_chat import AIChatClient
4
5
6async def relay(conversation_id: str, message: str):
7 async with AIChatClient(space="your-space") as client:
8 params = {"id": conversation_id, "message": message}
9
10 async with client.raw_post("chat", params) as resp:
11 async for chunk in resp.content.iter_any():
12 yield chunk