@@ -192,6 +192,64 @@ app.use(
192192
193193Single-route Express works identically to the Hono version: send the JSON envelope described earlier, and set ` useSingleEndpoint ` on the client.
194194
195+ ### NestJS (Express backend)
196+
197+ NestJS uses Express by default. Mount the Express router in ` main.ts ` :
198+
199+ ``` ts
200+ // main.ts
201+ import { NestFactory } from ' @nestjs/core' ;
202+ import { AppModule } from ' ./app.module' ;
203+ import { NestExpressApplication } from ' @nestjs/platform-express' ;
204+ import { CopilotRuntime } from ' @copilotkitnext/runtime' ;
205+ import { createCopilotEndpointExpress } from ' @copilotkitnext/runtime/express' ;
206+ import { BasicAgent } from ' @copilotkitnext/agent' ;
207+
208+ async function bootstrap() {
209+ const app = await NestFactory .create <NestExpressApplication >(AppModule );
210+
211+ const runtime = new CopilotRuntime ({
212+ agents: {
213+ default: new BasicAgent ({ model: ' openai/gpt-4o' , prompt: ' You are helpful.' }),
214+ },
215+ });
216+
217+ // Mount under /api/copilotkit (REST-style routes)
218+ app .use (
219+ ' /api/copilotkit' ,
220+ createCopilotEndpointExpress ({ runtime , basePath: ' /' }),
221+ );
222+
223+ await app .listen (3000 );
224+ }
225+ bootstrap ();
226+ ```
227+
228+ Available routes (no global prefix):
229+
230+ - ` POST /api/copilotkit/agent/:agentId/run `
231+ - ` POST /api/copilotkit/agent/:agentId/connect `
232+ - ` POST /api/copilotkit/agent/:agentId/stop/:threadId `
233+ - ` GET /api/copilotkit/info `
234+ - ` POST /api/copilotkit/transcribe `
235+
236+ If you prefer the single-route transport, mount the single-route helper instead and set ` useSingleEndpoint ` on the client:
237+
238+ ``` ts
239+ import { createCopilotEndpointSingleRouteExpress } from ' @copilotkitnext/runtime/express' ;
240+
241+ app .use (
242+ ' /api/copilotkit' ,
243+ createCopilotEndpointSingleRouteExpress ({ runtime , basePath: ' /' }),
244+ );
245+ ```
246+
247+ Notes:
248+
249+ - If you call ` app.setGlobalPrefix('api') ` , the effective paths become ` /api/copilotkit/... ` (or ` /api/copilotkit ` for single-route).
250+ - Endpoints stream Server‑Sent Events; ensure your proxy honors ` text/event-stream ` and keep‑alive.
251+ - The router enables permissive CORS; tighten via Nest’s ` enableCors ` if needed.
252+
195253## Runtime Metadata
196254
197255Calling ` GET /info ` (or the ` info ` single-route method) returns:
0 commit comments