Skip to content

Conversation

@subtleGradient
Copy link
Contributor

Problem

Google Gemini models (gemini-2.0-flash-exp, gemini-pro-preview, etc.) fail with schema validation errors when used through @effect/ai-openrouter:

MalformedOutput: Expected "unknown" | "openai-responses-v1" | "anthropic-claude-v1", actual "google-gemini-v1" 

The error occurs because Gemini models return reasoning_details with format: "google-gemini-v1", which is not recognized by the schema.

Solution

Add "google-gemini-v1" to the three reasoning format schemas:

  • ReasoningDetailSummaryFormat
  • ReasoningDetailEncryptedFormat
  • ReasoningDetailTextFormat

This is a backward-compatible change (union type extension). Existing models continue to work unchanged.

Minimal Reproduction

import * as OpenRouterClient from "@effect/ai-openrouter/OpenRouterClient"; import * as OpenRouterLanguageModel from "@effect/ai-openrouter/OpenRouterLanguageModel"; import * as LanguageModel from "@effect/ai/LanguageModel"; import * as Prompt from "@effect/ai/Prompt"; import { FetchHttpClient } from "@effect/platform"; import * as Layer from "effect/Layer"; import * as Effect from "effect/Effect"; import * as Redacted from "effect/Redacted"; const program = Effect.gen(function* () { const prompt = Prompt.make([ { role: "user" as const, content: "Say hello" } ]); const response = yield* LanguageModel.generateText({ prompt }); return response.text; }); const OpenRouterClientLayer = OpenRouterClient.layer({ apiKey: Redacted.make(process.env.OPENROUTER_API_KEY!), }).pipe(Layer.provide(FetchHttpClient.layer)); const OpenRouterModelLayer = OpenRouterLanguageModel.layer({ model: "google/gemini-2.0-flash-exp", }).pipe(Layer.provide(OpenRouterClientLayer)); // Before fix: MalformedOutput error // After fix: Works correctly await Effect.runPromise( program.pipe(Effect.provide(OpenRouterModelLayer)) );

Error before fix:

MalformedOutput: Expected "unknown" | "openai-responses-v1" | "anthropic-claude-v1", actual "google-gemini-v1" 

Testing

  • ✅ Package builds successfully
  • ✅ Schema now accepts google-gemini-v1 format
  • ✅ Existing formats (OpenAI, Anthropic) still work
  • ✅ No breaking changes

Changes

Modified:

  • packages/ai/openrouter/src/Generated.ts - Added "google-gemini-v1" to format schemas

Added:

  • .changeset/google-gemini-reasoning-format.md - Patch-level changeset
Google Gemini models return reasoning_details with format 'google-gemini-v1' which was not recognized by the schema, causing validation errors. Changes: - Add 'google-gemini-v1' to ReasoningDetailSummaryFormat - Add 'google-gemini-v1' to ReasoningDetailEncryptedFormat - Add 'google-gemini-v1' to ReasoningDetailTextFormat Fixes schema validation errors when using Google Gemini models (gemini-2.0-flash-exp, gemini-pro-preview, etc.) through OpenRouter. The error was: Expected 'unknown' | 'openai-responses-v1' | 'anthropic-claude-v1', actual 'google-gemini-v1' This is a backward-compatible change (union type extension).
@github-project-automation github-project-automation bot moved this to Discussion Ongoing in PR Backlog Nov 26, 2025
@changeset-bot
Copy link

changeset-bot bot commented Nov 26, 2025

🦋 Changeset detected

Latest commit: 071989e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@effect/ai-openrouter Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes schema validation errors that occurred when using Google Gemini models (e.g., gemini-2.0-flash-exp) through OpenRouter. The issue was caused by Gemini models returning reasoning_details with format: "google-gemini-v1", which wasn't recognized by the existing schema.

Key Changes:

  • Extended three reasoning format schemas to include "google-gemini-v1" as a valid literal value
  • Added appropriate changeset documentation for the patch-level change

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/ai/openrouter/src/Generated.ts Added "google-gemini-v1" to all three reasoning format schemas (ReasoningDetailSummaryFormat, ReasoningDetailEncryptedFormat, ReasoningDetailTextFormat)
.changeset/google-gemini-reasoning-format.md Added patch-level changeset documenting the support for Google Gemini v1 reasoning format

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@IMax153
Copy link
Member

IMax153 commented Nov 26, 2025

@subtleGradient - getting a CI error due to linting.

I think running a simple pnpm lint-fix should solve the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants