ByteChef LogoByteChef
EmbeddedQuick Start

Sample App

A reference Next.js + Fastify implementation that demonstrates the embedded SDK and APIs end-to-end.


bytechef-embedded-sample-app is a runnable reference implementation of an embedded integration. It shows how the pieces described in this section work together in one application.

For a minimal host app, the ByteChef repository contains a small Next.js host at sdks/frontend/embedded/test-apps. It has server-side JWT minting (app/api/generate-jwt), an integrations proxy (app/api/integrations) and an Automation Hub page (app/hub). It is also the SDK's development harness, so it tracks the current SDK version.

The sample app has two parts:

  • back-end/ - a small Fastify + TypeScript server that signs JWTs (RS256) for end-user sessions using a Signing Key.
  • front-end/ - a Next.js app that consumes those JWTs to drive the embedded SDK and several embedded APIs.

What the sample demonstrates

Page in the sampleDemonstratesUnderlying API or SDK
Integrations (/integrations)Letting an end user connect a third-party service via the ByteChef connect dialog.useConnectDialog from @bytechef/embedded
Automations (/automations)Customer-facing workflow management - list / create / enable / disable / delete the user's own workflows.GET/POST/DELETE /api/embedded/v1/automation/workflows
ComponentKit Playground (/component-kit)Invoking a single component action directly, without authoring a workflow first.POST /api/embedded/v1/{externalUserId}/components/{componentName}/versions/{componentVersion}/actions/{actionName}
Chat MCP (/chat-mcp)Using a ByteChef MCP Server as the tool source for an AI assistant chat.MCP transport against your MCP Server URL, authenticated with the end-user JWT
Chat Component Kit (/chat-component-kit)Exposing every component action available to a user as tools for an AI assistant.GET /api/embedded/v1/{externalUserId}/tools
Generate a workflow from a prompt (on /automations)Creating a workflow for the user from a natural-language prompt.POST /api/embedded/v1/automation/workflows/generate (requires AI Copilot enabled on the server, BYTECHEF_AI_COPILOT_ENABLED=true)
App Event (/app-event)Firing an App Event from your application to start every one of the connected user's enabled App Event-triggered workflows.POST /api/embedded/v1/app-events
Request (/request)Triggering a single workflow synchronously via its Request trigger and reading the workflow's response back.POST /api/embedded/v1/workflows/{workflowUuid}

Together these cover the most common embedded integration patterns: the connect flow, programmatic workflow CRUD, ad-hoc action execution, MCP-based tooling, tool-by-tool LLM integration, prompt-based workflow generation, App Event firing, and synchronous request-triggered workflows.


How the pieces wire up

┌──────────────────────────────────────────┐
│  Browser (Next.js front-end :3000)       │
│  ──────────────────────────────────────  │
│  - useConnectDialog (Integrations)       │
│  - fetch() to its own /api/* routes      │
└──────────────┬───────────────────────────┘
               │  (1) request JWT
               ▼
┌──────────────────────────────────────────┐
│  Fastify back-end (:3001)                │
│  ──────────────────────────────────────  │
│  POST /api/token                         │
│    body: { externalUserId, name, ... }   │
│  → signs RS256 JWT with private key      │
│    and kid from your Signing Key         │
└──────────────┬───────────────────────────┘
               │  (2) JWT returned to browser
               ▼
┌──────────────────────────────────────────┐
│  Browser uses JWT to call ByteChef       │
│  Authorization: Bearer <jwt>             │
│  X-Environment: DEVELOPMENT              │
└──────────────┬───────────────────────────┘
               ▼
        ByteChef Embedded API
        (app.bytechef.io or self-hosted :8080)

The back-end does not proxy ByteChef traffic; it only mints JWTs. The browser, or the Next.js API routes acting for it, calls ByteChef directly with the JWT.


Running the sample locally

Prerequisites

  • A ByteChef instance with Embedded enabled, either:
    • ByteChef Cloud at https://app.bytechef.io, or
    • self-hosted ByteChef EE, by default at http://localhost:8080.
  • A Signing Key created in Embedded → Settings → Signing Keys on that same instance. Copy the private key (shown once) and the Key Id (kid). A key created on Cloud does not verify on a self-hosted instance, and vice versa.
  • Node.js 18+ and npm.

Configure the back-end

cd bytechef-embedded-sample-app/back-end
npm install

Create .env in back-end/:

BYTECHEF_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----
...your private key from Signing Keys...
-----END PRIVATE KEY-----"
BYTECHEF_KID=<your-key-id>
VariableRequiredDefaultDescription
BYTECHEF_PRIVATE_KEYyes-PEM private key of your Signing Key. The back-end signs the connected-user JWT with it (RS256). Keep the double quotes around the multi-line value.
BYTECHEF_KIDyes-Key Id of the same Signing Key, written to the JWT kid header so ByteChef picks the matching public key.
PORTno3001Port the back-end listens on. If you change it, update NEXT_PUBLIC_BACKEND_APP_BASE_URL in the front-end.
TOKEN_EXPIRYno1hLifetime of each issued JWT (30m, 1h, 7d, ...).

Run it:

npm run dev
# Backend listening on http://localhost:3001

Configure the front-end

cd ../front-end
npm install

Create .env.local in front-end/ for any value whose default doesn't fit. Against ByteChef Cloud, the one line you need is:

NEXT_PUBLIC_BYTECHEF_APP_BASE_URL=https://app.bytechef.io

Against a self-hosted instance on the default http://localhost:8080, you can skip the file entirely.

VariableDefaultDescription
NEXT_PUBLIC_BYTECHEF_APP_BASE_URLhttp://localhost:8080Your ByteChef instance: https://app.bytechef.io for Cloud, or your self-hosted URL.
NEXT_PUBLIC_BACKEND_APP_BASE_URLhttp://localhost:3001The sample back-end that signs JWTs (POST /api/token).
NEXT_PUBLIC_BYTECHEF_ENVIRONMENTDEVELOPMENTEnvironment every call targets - DEVELOPMENT, STAGING or PRODUCTION - sent as the X-ENVIRONMENT header. Integrations, connections and workflows are separate per environment.
NEXT_PUBLIC_BYTECHEF_EXTERNAL_USER_ID1234567890Your app's id for the demo end user; it becomes the JWT sub, so ByteChef scopes that user's connections and workflows to it. Change it to act as a different user.
NEXT_PUBLIC_BYTECHEF_MCP_SERVER_URL(empty)URL of a ByteChef MCP Server. Only needed for the Chat MCP page.
OPENAI_API_KEY(none)OpenAI key for the Chat MCP and Chat Component Kit pages.

NEXT_PUBLIC_* values are inlined when Next.js compiles, so restart npm run dev after changing them.

Run it:

npm run dev
# Frontend on http://localhost:3000

Open http://localhost:3000, go to the Integrations page, click an integration card and complete the Connect dialog. The new connection appears in the user's detail sheet under Embedded → Connected Users in the ByteChef UI.


Developing against a local SDK build

To test changes to the embedded React SDK in the sample app:

# Terminal 1 - rebuild the SDK on save
cd <repo-root>/sdks/frontend/embedded/library
npm run watch

# Terminal 2 - after each rebuild, re-link into the sample app
cd <repo-root>/../bytechef-embedded-sample-app/front-end
npm install --install-links
rm -rf .next
npm run dev

--install-links is required because Next.js Turbopack cannot resolve symlinked packages. The flag copies the SDK build into the sample's node_modules instead of creating a symlink.


Where to look in the source

You want to see...Open...
How to wire useConnectDialogfront-end/src/app/integrations/page.tsx
Listing / creating / enabling user workflowsfront-end/src/lib/api.ts + front-end/src/app/automations/page.tsx
Running a single component actionfront-end/src/app/api/component-kit/route.ts
Using ByteChef as an MCP tool sourcefront-end/src/app/api/chat-mcp/route.ts
Loading per-user tools into an LLMfront-end/src/app/api/chat-component-kit/route.ts
Firing an App Event for the connected userfront-end/src/app/app-event/page.tsx + front-end/src/app/api/app-event/route.ts
Triggering a workflow via its Request triggerfront-end/src/app/request/page.tsx + front-end/src/app/api/request/route.ts
The JWT signing referenceback-end/src/index.ts

The other pages in this section describe the ByteChef admin UI behind each demo.

How is this guide?

Last updated on

On this page