Skip to content

feat: support preserving reasoning content in OpenAI format conversion#5055

Merged
kevinvandijk merged 7 commits intoKilo-Org:mainfrom
Leoyzen:fix/openai_preserved_reasoning
Feb 12, 2026
Merged

feat: support preserving reasoning content in OpenAI format conversion#5055
kevinvandijk merged 7 commits intoKilo-Org:mainfrom
Leoyzen:fix/openai_preserved_reasoning

Conversation

@Leoyzen
Copy link
Contributor

@Leoyzen Leoyzen commented Jan 15, 2026

Add support for handling custom reasoning type content blocks when converting Anthropic messages to OpenAI format. This enables OpenAI provider to preserve reasoning/thinking content from models that use custom reasoning blocks.

Release Notes:

  • Handle thinking type with part.thinking property
  • Handle reasoning type with part.text/thinking property for compatibility
  • Use type assertion to avoid TypeScript errors for custom types

Context

Some AI models (like DeepSeek, Gemini, and others) use custom reasoning type content blocks to represent their internal thinking process during response generation. The existing convertToOpenAiMessages function only supported the standard Anthropic thinking type, which caused these custom reasoning blocks to be lost during message format conversion. This prevented the OpenAI provider from preserving and displaying the reasoning content from these models.

Implementation

The fix modifies the convertToOpenAiMessages function in src/api/transform/openai-format.ts to:

  1. Extended type handling: Updated the reduce function to accept both standard thinking type and custom reasoning type by using any type union and type assertions
  2. Dual content extraction: Added conditional logic to handle both types:
    • For thinking blocks: extracts content from part.thinking (Anthropic standard)
    • For reasoning blocks: extracts content from part.text or part.thinking (custom provider format)
  3. Type safety: Used (part as any).type assertion to avoid TypeScript errors when checking for the non-standard reasoning type

The reasoning content is wrapped with <thinking>...</thinking> tags to maintain the same format as standard thinking blocks, ensuring consistent display in the UI.

Screenshots

before after

How to Test

  1. Use a model that supports reasoning content (e.g., DeepSeek R1 with preserveReasoning: true)
  2. Ask a complex question that would trigger the model's reasoning process
  3. Verify that the reasoning content is preserved and displayed in the chat UI
  4. Check that no TypeScript errors occur during the message conversion

Get in Touch

Add support for handling custom reasoning type content blocks when converting Anthropic messages to OpenAI format. This enables OpenAI provider to preserve reasoning/thinking content from models that use custom reasoning blocks.

- Handle thinking type with part.thinking property
- Handle reasoning type with part.text/thinking property for compatibility
- Use type assertion to avoid TypeScript errors for custom types
@changeset-bot
Copy link

changeset-bot bot commented Jan 15, 2026

🦋 Changeset detected

Latest commit: 74d904e

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

This PR includes changesets to release 1 package
Name Type
kilo-code 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
Collaborator

@kevinvandijk kevinvandijk left a comment

Choose a reason for hiding this comment

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

Thank you @Leoyzen!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants