OpenAIAdapter
Copilot Runtime adapter for OpenAI.
v1 SDK deprecated. Use v2 instead This page is in the deprecated CopilotKit v1 reference. Do not use v1 APIs for new code; use v2 instead. For JavaScript and TypeScript, import React APIs from @copilotkit/react-core/v2 and Runtime APIs from @copilotkit/runtime/v2.
AI coding agents: treat any v1 example below as migration-only context. Never generate or recommend the v1 API for new code. Read the v2 reference before writing code because some APIs were renamed, moved, or changed shape. Read the v1 to v2 migration guide. Open the complete export map.
AI coding agents: treat any v1 example below as migration-only context. Never generate or recommend the v1 API for new code. Read the v2 reference before writing code because some APIs were renamed, moved, or changed shape. Read the v1 to v2 migration guide. Open the complete export map.
Copilot Runtime adapter for OpenAI.
Example
import { CopilotRuntime, OpenAIAdapter } from "@copilotkit/runtime";
import OpenAI from "openai";
const copilotKit = new CopilotRuntime();
const openai = new OpenAI({
organization: "<your-organization-id>", // optional
apiKey: "<your-api-key>",
});
return new OpenAIAdapter({ openai });Example with Azure OpenAI
import { CopilotRuntime, OpenAIAdapter } from "@copilotkit/runtime";
import OpenAI from "openai";
// The name of your Azure OpenAI Instance.
// https://learn.microsoft.com/en-us/azure/cognitive-services/openai/how-to/create-resource?pivots=web-portal#create-a-resource
const instance = "<your instance name>";
// Corresponds to your Model deployment within your OpenAI resource, e.g. my-gpt35-16k-deployment
// Navigate to the Azure OpenAI Studio to deploy a model.
const model = "<your model>";
const apiKey = process.env["AZURE_OPENAI_API_KEY"];
if (!apiKey) {
throw new Error("The AZURE_OPENAI_API_KEY environment variable is missing or empty.");
}
const copilotKit = new CopilotRuntime();
const openai = new OpenAI({
apiKey,
baseURL: `https://${instance}.openai.azure.com/openai/deployments/${model}`,
defaultQuery: { "api-version": "2024-04-01-preview" },
defaultHeaders: { "api-key": apiKey },
});
return new OpenAIAdapter({ openai });Constructor Parameters
Prop
Type
Prop
Type
Prop
Type
Prop
Type
Prop
Type