CopilotKit: 🐛 Bug: Google GoogleGenerativeAIAdapter is not working

♻️ Reproduction Steps

We need to be able to use Google Gemini model with CopilotKit in the nextjs application. For now this will be used only to generate suggestions, but later on we might implement another use cases. I’m fallowing your example, which by the way is not very clear: https://docs.copilotkit.ai/reference/classes/llm-adapters/GoogleGenerativeAIAdapter

In the /copilotkit route handler initializing gemini model by using GoogleGenerativeAIAdapter from @copilotkit/runtime

const llmAdapter = new GoogleGenerativeAIAdapter({
  model: "gemini-2.0-flash",
}); 

And then i’m simply passing it in copilotRuntimeNextJSAppRouterEndpoint.

const { handleRequest } = copilotRuntimeNextJSAppRouterEndpoint({
    runtime,
    serviceAdapter: llmAdapter,
    endpoint: "/api/copilotkit",
  });

  return handleRequest(c.req.raw);

✅ Expected Behavior

We should be able to see suggestions generated by Gemini model, the same way like using OpenAI.

❌ Actual Behavior

Getting the error saying that there are some issues with validation.

Image

𝌚 CopilotKit Version

@copilotkit/react-core@1.6.0
@copilotkit/react-ui@1.6.0
@copilotkit/runtime@1.6.0
@google/generative-ai@0.24.0
@langchain/google-genai@0.1.10

📄 Logs (Optional)


About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 19 (1 by maintainers)

Most upvoted comments

@NathanTarbert Fyi, documentation initializes genAI as a constant but never uses it inside the adapter. here

And i second this, passing the argument doesn’t work, your linter didn’t complain but under the hood it ignored it and used the gemini api key to initialize its internal instance 😃

Edit: You can make it work using langchain adapters

import { ChatGoogle } from '@langchain/google-webauth';
const genai = new ChatGoogle({
  model: 'gemini-2.5-flash-preview-04-17',
  maxReasoningTokens: 10,
  apiVersion: 'v1beta',
  platformType: 'gai',
});

const langchainAdapter = new LangChainAdapter({
  chainFn: async ({ messages, tools }) => {
    return genai.bindTools(tools).stream(messages);
  },
});

Note: make sure @langchain/core (0.3.55) and @langchain/google-webauth(0.2.9) are updated to the latest version otherwise won’t work.

@venkatb-zelar @martynaswg @Plytas

Just an update here, we’ve taken action items from the call and will prioritize getting this to work.

Hey @martynaswg, thanks for flagging this. A ticket has been created and we will look into this and let you know what we find out.

Hello @venkatb-zelar I created a project using Google Generative AI self-hosted runtime if you can please take a look and see if it works for you.

import {
  CopilotRuntime,
  GoogleGenerativeAIAdapter,
  copilotRuntimeNextJSAppRouterEndpoint,
} from '@copilotkit/runtime';

import { NextRequest } from 'next/server';

const serviceAdapter = new GoogleGenerativeAIAdapter({
  apiKey: process.env["GOOGLE_API_KEY"] || "",
  model: "gemini-2.5-pro",
});

const runtime = new CopilotRuntime();

export const POST = async (req: NextRequest) => {
  const { handleRequest } = copilotRuntimeNextJSAppRouterEndpoint({
    runtime,
    serviceAdapter,
    endpoint: '/api/copilotkit',
  });

  return handleRequest(req);
};
Image

Hey @martynaswg, I’d be happy to schedule a call with one of our CoAgents engineers to see if we can get this sorted out.

I can DM you the calendar link on Discord.

@NathanTarbert any update on this please?