Open History to see the last commit
1---
2id: chatParamsFromRequest
3title: chatParamsFromRequest
4---
5
6```ts
7function chatParamsFromRequest(req): Promise<{
8 aguiContext: Context[];
9 context: Context[];
10 forwardedProps: Record<string, unknown>;
11 messages: (
12 | UIMessage<unknown>
13 | ModelMessage<
14 | string
15 | ContentPart<unknown, unknown, unknown, unknown, unknown>[]
16 | null>)[];
17 parentRunId?: string;
18 resume?: RunAgentResumeItem[];
19 runId: string;
20 state: unknown;
21 threadId: string;
22 tools: object[];
23}>;
24```
25
26Defined in: [packages/ai/src/utilities/chat-params.ts:282](https://github.com/TanStack/ai/blob/main/packages/ai/src/utilities/chat-params.ts#L282)
27
28Read an HTTP `Request`, parse its JSON body, and validate it as an
29AG-UI `RunAgentInput` — collapsing the standard `req.json()` +
30`chatParamsFromRequestBody(...)` pair into a single call.
31
32On a malformed body or invalid AG-UI shape, this **throws a
33`Response`** with status 400 and a migration-pointing message in the
34body. Frameworks that natively handle thrown `Response` objects
35(TanStack Start, SolidStart, Remix, React Router 7) will return the
36400 to the client automatically, so the handler reduces to:
37
38```ts
39export async function POST(req: Request) {
40 const params = await chatParamsFromRequest(req)
41 // ...use params
42}
43```
44
45In frameworks that do not auto-handle thrown `Response` objects
46(Next.js Route Handlers, SvelteKit, Hono, raw Node), wrap the call
47with try/catch and return the caught Response yourself, or use
48`chatParamsFromRequestBody` directly with your own JSON-parsing.
49
50## Parameters
51
52### req
53
54`Request`
55
56## Returns
57
58`Promise`\<\{
59 `aguiContext`: `Context`[];
60 `context`: `Context`[];
61 `forwardedProps`: `Record`\<`string`, `unknown`\>;
62 `messages`: (
63 \| [`UIMessage`](../interfaces/UIMessage.md)\<`unknown`\>
64 \| [`ModelMessage`](../interfaces/ModelMessage.md)\<
65 \| `string`
66 \| [`ContentPart`](../type-aliases/ContentPart.md)\<`unknown`, `unknown`, `unknown`, `unknown`, `unknown`\>[]
67 \| `null`\>)[];
68 `parentRunId?`: `string`;
69 `resume?`: [`RunAgentResumeItem`](../type-aliases/RunAgentResumeItem.md)[];
70 `runId`: `string`;
71 `state`: `unknown`;
72 `threadId`: `string`;
73 `tools`: `object`[];
74\}\>
75
76## Throws
77
78400 on malformed JSON or invalid AG-UI shape.