Skip to content

Next.js Pages Router integration

Frames.js can be easily integrated with Next.js application that uses Pages Router.

Create Frames handler

Frames handler is responsible for rendering your Frames and also reacts to user interactions with buttons.

/* eslint-disable react/jsx-key */
import { createFrames, Button } from "frames.js/next/pages-router/server";
const frames = createFrames({
  basePath: "/api/frames",
const handleRequest = frames(async () => {
  return {
    image: <span>Test</span>,
    buttons: [<Button action="post">Click me</Button>],
export default handleRequest;

Render initial frame on your existing page

In order to render the initial frame of your Frames app on some of your pages, you need to render frame metadata. That can be achieved using getServerSideProps() API in combination with fetchMetadata() function.

import type { InferGetServerSidePropsType, GetServerSideProps } from "next";
import Head from "next/head";
import {
} from "frames.js/next/pages-router/client";
export const getServerSideProps = async function getServerSideProps() {
  return {
    props: {
      metadata: await fetchMetadata(
        new URL(
          process.env.VERCEL_URL || "http://localhost:3000"
} satisfies GetServerSideProps<{
  metadata: Awaited<ReturnType<typeof fetchMetadata>>;
export default function Page({
}: InferGetServerSidePropsType<typeof getServerSideProps>) {
  return (
        <title>Frames.js app</title>