VercelLogotypeVercelLogotype
LoginSign Up

AnyCable Real-time Starter Kit

AnyCable/Next.js chat application demonstrating how to build real-time features, with all benefits of open-source. No PaaS bills.

DeployView Demo

AnyCable Next.js/Vercel Example

This is an example of how to use AnyCable with Next.js and Vercel to build real-time applications.

Learn more about AnyCable for serverless JavaScript apps in the documentation.

Prerequisites

You will need to deploy an AnyCable-Go server to the platform of your choice. We recommend using Fly.io and provide an example configuration in fly.toml.example for seamless deployments. However, Anycable-Go server can be deployed on any platform.

Using fly CLI, run the following command to create and launch a new AnyCable-Go application:

# Create a new Fly application
fly launch --image anycable/anycable-go:1.4 --generate-name --ha=false --internal-port 8080 --env PORT=8080 --env ANYCABLE_BROKER=memory

Answer "No" to all database-related questions and "Yes" to deployment. This will deploy your app and create a fly.toml file with the minimum configuration. See the fly.toml.example file to learn more about other available and recommended configuration options.

Deployment

  • Click the Deploy button

  • Fill in the required environment variables:

    CABLE_URL=wss://<YOUR_ANYCABLE_GO_HOSTNAME>/cable
    ANYCABLE_HTTP_BROADCAST_URL=https://<YOUR_ANYCABLE_GO_HOSTNAME>/_broadcast
    ANYCABLE_HTTP_BROADCAST_SECRET=<YOUR_SECRET>
    ANYCABLE_JWT_ID_KEY=<YOUR_JWT_SECRET>
    • The ANYCABLE_HTTP_BROADCAST_SECRET and ANYCABLE_JWT_ID_KEY can be any strings.
    • You can create a secure value using this CLI command openssl rand -hex 32
  • Set the following environment variables on your AnyCable-Go server:

    ANYCABLE_RPC_HOST=https://<YOUR_VERCEL_APP_HOSTNAME>/api/anycable
    ANYCABLE_HTTP_BROADCAST_SECRET=<YOUR_SECRET>
    ANYCABLE_JWT_ID_KEY=<YOUR_JWT_SECRET>

When using Fly, you can keep all env vars in the .env.production file and import the secrets using the following command:

cat .env.production | fly secrets import

When deploying to Vercel you can use the Vercel CLI to pull environment variables:

vercel env pull

Authentication

We use the AnyCable JWT identification feature to issue JWT tokens to authenticate clients. The benefit of using AnyCable JWTs is the ability to verify and identify clients at the WebSocket server side without making additional requests to the backend (Vercel functions in our case).

The ANYCABLE_JWT_ID_KEY environment variable is responsible for this.

Running locally

PNPM is required to install dependencies.

First, install the dependencies:

pnpm install

Then, start AnyCable-Go:

pnpm anycable-go

And start the Next.js app:

pnpm dev

Open http://localhost:3000 with your browser to see the result.

GitHub Repoanycable/vercel-anycable-demo
Use Cases
Realtime Apps
Stack
Next.js
Tailwind

Related Templates

Chatbot

A full-featured, hackable Next.js AI chatbot built by Vercel
Chatbot thumbnail

Chatbot UI

A ChatGPT clone for running locally in your browser.
Chatbot UI thumbnail

Get Started

  • Templates
  • Supported frameworks
  • Marketplace
  • Domains

Build

  • Next.js on Vercel
  • Turborepo
  • v0

Scale

  • Content delivery network
  • Fluid compute
  • CI/CD
  • Observability
  • AI GatewayNew
  • Vercel AgentNew

Secure

  • Platform security
  • Web Application Firewall
  • Bot management
  • BotID
  • SandboxNew

Resources

  • Pricing
  • Customers
  • Enterprise
  • Articles
  • Startups
  • Solution partners

Learn

  • Docs
  • Blog
  • Changelog
  • Knowledge Base
  • Academy
  • Community

Frameworks

  • Next.js
  • Nuxt
  • Svelte
  • Nitro
  • Turbo

SDKs

  • AI SDK
  • Workflow SDKNew
  • Flags SDK
  • Chat SDK
  • Streamdown AINew

Use Cases

  • Composable commerce
  • Multi-tenant platforms
  • Web apps
  • Marketing sites
  • Platform engineers
  • Design engineers

Company

  • About
  • Careers
  • Help
  • Press
  • Legal
  • Privacy Policy

Community

  • Open source program
  • Events
  • Shipped on Vercel
  • GitHub
  • LinkedIn
  • X
  • YouTube

Loading status…

Select a display theme:
    • AI Cloud
      • AI Gateway

        One endpoint, all your models

      • Sandbox

        Isolated, safe code execution

      • Vercel Agent

        An agent that knows your stack

      • AI SDK

        The AI Toolkit for TypeScript

      • v0

        Build applications with AI

    • Core Platform
      • CI/CD

        Helping teams ship 6× faster

      • Content Delivery

        Fast, scalable, and reliable

      • Fluid Compute

        Servers, in serverless form

      • Workflow

        Long-running workflows at scale

      • Observability

        Trace every step

    • Security
      • Bot Management

        Scalable bot protection

      • BotID

        Invisible CAPTCHA

      • Platform Security

        DDoS Protection, Firewall

      • Web Application Firewall

        Granular, custom protection

    • Company
      • Customers

        Trusted by the best teams

      • Blog

        The latest posts and changes

      • Changelog

        See what shipped

      • Press

        Read the latest news

      • Events

        Join us at an event

    • Learn
      • Docs

        Vercel documentation

      • Academy

        Linear courses to level up

      • Knowledge Base

        Find help quickly

      • Community

        Join the conversation

    • Open Source
      • Next.js

        The native Next.js platform

      • Nuxt

        The progressive web framework

      • Svelte

        The web’s efficient UI framework

      • Turborepo

        Speed with Enterprise scale

    • Use Cases
      • AI Apps

        Deploy at the speed of AI

      • Composable Commerce

        Power storefronts that convert

      • Marketing Sites

        Launch campaigns fast

      • Multi-tenant Platforms

        Scale apps with one codebase

      • Web Apps

        Ship features, not infrastructure

    • Tools
      • Marketplace

        Extend and automate workflows

      • Templates

        Jumpstart app development

      • Partner Finder

        Get help from solution partners

    • Users
      • Platform Engineers

        Automate away repetition

      • Design Engineers

        Deploy for every idea

  • Enterprise
  • Pricing
Log InContact
Sign Up
Sign Up
DeployView Demo
AI Gateway

One endpoint, all your models

Sandbox

Isolated, safe code execution

Vercel Agent

An agent that knows your stack

AI SDK

The AI Toolkit for TypeScript

v0

Build applications with AI

CI/CD

Helping teams ship 6× faster

Content Delivery

Fast, scalable, and reliable

Fluid Compute

Servers, in serverless form

Workflow

Long-running workflows at scale

Observability

Trace every step

Bot Management

Scalable bot protection

BotID

Invisible CAPTCHA

Platform Security

DDoS Protection, Firewall

Web Application Firewall

Granular, custom protection

Customers

Trusted by the best teams

Blog

The latest posts and changes

Changelog

See what shipped

Press

Read the latest news

Events

Join us at an event

Docs

Vercel documentation

Academy

Linear courses to level up

Knowledge Base

Find help quickly

Community

Join the conversation

Next.js

The native Next.js platform

Nuxt

The progressive web framework

Svelte

The web’s efficient UI framework

Turborepo

Speed with Enterprise scale

AI Apps

Deploy at the speed of AI

Composable Commerce

Power storefronts that convert

Marketing Sites

Launch campaigns fast

Multi-tenant Platforms

Scale apps with one codebase

Web Apps

Ship features, not infrastructure

Marketplace

Extend and automate workflows

Templates

Jumpstart app development

Partner Finder

Get help from solution partners

Platform Engineers

Automate away repetition

Design Engineers

Deploy for every idea