Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.firstflow.app/llms.txt

Use this file to discover all available pages before exploring further.

import { getFirstflowConfig } from "@firstflow/nextjs/server";
Fetches the agent config on the server and returns it for hydration via FirstflowProvider’s initialSdkPayload prop. When provided, the client skips the initial config fetch and renders immediately — no loading flash.

Usage

Call getFirstflowConfig() in your root layout (a Server Component):
// app/layout.tsx
import { getFirstflowConfig } from "@firstflow/nextjs/server";
import { FirstflowProvider } from "@firstflow/nextjs";

export default async function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  const config = await getFirstflowConfig();

  return (
    <html>
      <body>
        <FirstflowProvider
          agentId={process.env.FIRSTFLOW_AGENT_ID!}
          initialSdkPayload={config}
        >
          {children}
        </FirstflowProvider>
      </body>
    </html>
  );
}

Environment variables

getFirstflowConfig() reads the following variables automatically. No arguments required.
# .env.local
FIRSTFLOW_AGENT_ID=your-agent-id
FIRSTFLOW_API_KEY=your-api-key
These are server-only variables — they do not need NEXT_PUBLIC_ prefix and are not exposed to the browser.

Return value

Returns a Promise<SdkPayload | null>. The returned value is opaque — pass it directly to initialSdkPayload without inspecting or modifying it. If the fetch fails (network error, invalid credentials), getFirstflowConfig() returns null. The provider falls back to a client-side fetch automatically.

Notes

  • Only works in Server Components (App Router). Not compatible with the Pages Router.
  • The config is fetched fresh on every server render. For caching, wrap with Next.js’s unstable_cache or use route segment config (export const revalidate = 300).
  • If FIRSTFLOW_AGENT_ID or FIRSTFLOW_API_KEY are missing, the function logs a warning and returns null.