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