Quick Start
Install
npm install @yourgpt/copilot-sdk @yourgpt/llm-sdk openai
Frontend (React)
import { CopilotProvider } from "@yourgpt/copilot-sdk/react";
import { CopilotChat } from "@yourgpt/copilot-sdk/ui";
import "@yourgpt/copilot-sdk/ui/styles.css";
function App() {
return (
<CopilotProvider runtimeUrl="/api/chat">
<YourApp />
<CopilotChat />
</CopilotProvider>
);
}
Backend (Next.js)
// app/api/chat/route.ts
import { streamText } from "@yourgpt/llm-sdk";
import { openai } from "@yourgpt/llm-sdk/openai";
export async function POST(req: Request) {
const { messages } = await req.json();
const result = await streamText({
model: openai("gpt-4o"),
system: "You are a helpful assistant.",
messages,
});
return result.toTextStreamResponse();
}
LLM SDK - Multi-Provider Support
Use any LLM provider with a unified API:
import { streamText } from "@yourgpt/llm-sdk";
import { openai } from "@yourgpt/llm-sdk/openai";
import { anthropic } from "@yourgpt/llm-sdk/anthropic";
import { google } from "@yourgpt/llm-sdk/google";
import { xai } from "@yourgpt/llm-sdk/xai";
// OpenAI
await streamText({ model: openai("gpt-4o"), messages });
// Anthropic
await streamText({ model: anthropic("claude-sonnet-4-20250514"), messages });
// Google Gemini (uses OpenAI-compatible API)
await streamText({ model: google("gemini-2.0-flash"), messages });
// xAI Grok (uses OpenAI-compatible API)
await streamText({ model: xai("grok-3-fast"), messages });
SDK Requirements
| Provider |
SDK Required |
| OpenAI, Google, xAI |
openai |
| Anthropic |
@anthropic-ai/sdk |
Add tools to let the AI call functions on your server:
import { streamText, tool } from "@yourgpt/llm-sdk";
import { openai } from "@yourgpt/llm-sdk/openai";
import { z } from "zod";
const result = await streamText({
model: openai("gpt-4o"),
messages,
tools: {
getWeather: tool({
description: "Get current weather for a city",
parameters: z.object({
city: z.string().describe("City name"),
}),
execute: async ({ city }) => {
const data = await fetchWeatherAPI(city);
return { temperature: data.temp, condition: data.condition };
},
}),
},
maxSteps: 5,
});
return result.toDataStreamResponse();
Packages
| Package |
Description |
@yourgpt/copilot-sdk/react |
React hooks and provider |
@yourgpt/copilot-sdk/ui |
Pre-built chat components |
@yourgpt/copilot-sdk/core |
Core utilities and context capture tools |
@yourgpt/llm-sdk |
Multi-provider LLM SDK with streaming |
Documentation
Visit copilot-sdk.yourgpt.ai for full documentation.
Contributing
We welcome contributions! Whether it’s bug reports, feature requests, or code contributions.
Maintainers: @0fficialRohit · @rege_dev
License
MIT License
评论