Docs
Cloudflare
Railway
CodeRabbit
SerpAPI
AG Grid
Netlify
Clerk
WorkOS
OpenRouter
Prisma
Sentry
Electric
Unkey
Cloudflare
Railway
CodeRabbit
SerpAPI
AG Grid
Netlify
Clerk
WorkOS
OpenRouter
Prisma
Sentry
Electric
Unkey
Class References
Function References
Interface References
Type Alias References
Variable References

chatParamsFromRequest

Function: chatParamsFromRequest()

ts
function chatParamsFromRequest(req): Promise<{
  aguiContext: object[];
  context: object[];
  forwardedProps: Record<string, unknown>;
  messages: (
     | ModelMessage<
     | string
     | ContentPart<unknown, unknown, unknown, unknown, unknown>[]
     | null>
    | UIMessage<unknown>)[];
  parentRunId?: string;
  runId: string;
  state: unknown;
  threadId: string;
  tools: object[];
}>;
function chatParamsFromRequest(req): Promise<{
  aguiContext: object[];
  context: object[];
  forwardedProps: Record<string, unknown>;
  messages: (
     | ModelMessage<
     | string
     | ContentPart<unknown, unknown, unknown, unknown, unknown>[]
     | null>
    | UIMessage<unknown>)[];
  parentRunId?: string;
  runId: string;
  state: unknown;
  threadId: string;
  tools: object[];
}>;

Defined in: packages/ai/src/utilities/chat-params.ts:134

Read an HTTP , parse its JSON body, and validate it as an AG-UI — collapsing the standard + pair into a single call.

On a malformed body or invalid AG-UI shape, this throws a with status 400 and a migration-pointing message in the body. Frameworks that natively handle thrown objects (TanStack Start, SolidStart, Remix, React Router 7) will return the 400 to the client automatically, so the handler reduces to:

ts
export async function POST(req: Request) {
  const params = await chatParamsFromRequest(req)
  // ...use params
}
export async function POST(req: Request) {
  const params = await chatParamsFromRequest(req)
  // ...use params
}

In frameworks that do not auto-handle thrown objects (Next.js Route Handlers, SvelteKit, Hono, raw Node), wrap the call with try/catch and return the caught Response yourself, or use directly with your own JSON-parsing.

Parameters

req

Returns

<{ : []; : []; : <, >; : ( | < | | <, , , , >[] | > | <>)[]; : ; : ; : ; : ; : []; }>

Throws

400 on malformed JSON or invalid AG-UI shape.