Skip to content

Conversation

@KONRADS098
Copy link

@KONRADS098 KONRADS098 commented Jan 3, 2026

Summary

This PR adds support for tool-level provider options in the OpenAI-compatible provider. Tools can now include custom provider metadata through the providerOptions field, which gets properly merged into the prepared tools for API requests.

Changes Made

  • Extended prepareTools function to extract and merge tool-level metadata from providerOptions.openaiCompatible
  • Updated type definitions to allow tools to include arbitrary metadata fields from provider options

- Add getToolMetadata() helper function to extract providerOptions from tools
- Spread tool-level provider options into prepared tools for API requests
- Update return type to support additional metadata fields via Record<string, unknown>
- Add comprehensive tests for tool-level providerOptions support
- Tests follow the same pattern as message-level provider options in convert-to-openai-compatible-chat-messages.test.ts

Note: Currently uses the hardcoded 'openaiCompatible' key pattern to maintain
consistency with message-level conversion behavior. Dynamic provider names for
both message and tool options should be addressed in a future refactoring.
@KONRADS098 KONRADS098 force-pushed the feat/openai-compatible-tool-provider-options branch from 6080a26 to ad5241d Compare January 3, 2026 21:29
Comment on lines +8 to +10
function getToolMetadata(tool: { providerOptions?: SharedV3ProviderMetadata }) {
return tool?.providerOptions?.openaiCompatible ?? {};
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

instead of openaiCompatible, can you pass in the provider name so it matches how it is handled in packages/openai-compatible/src/chat/openai-compatible-chat-language-model.ts?

Image

(ideally that parsing would be extracted into a helper function)

Copy link
Author

Choose a reason for hiding this comment

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

I had this initially, but then I noticed that we already have some inconsistencies in this regard. I decided to stick to what we are doing in the packages/openai-compatible/src/chat/convert-to-openai-compatible-chat-messages.ts.

return message?.providerOptions?.openaiCompatible ?? {};

That being said it would be better to pass the provider name like you suggested.

  • Shall I update the packages/openai-compatible/src/chat/convert-to-openai-compatible-chat-messages.ts and packages/openai-compatible/src/chat/openai-compatible-prepare-tools.ts to use the provider name?
  • For the packages/openai-compatible/src/chat/convert-to-openai-compatible-chat-messages.ts, shall I use a fallback to the openaiCompatible, as consumers might have already integrated with this key?

Copy link
Collaborator

@lgrammel lgrammel Jan 9, 2026

Choose a reason for hiding this comment

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

It should be consistent. I would suggest a separate PR that cleans out the current behavior 1st and makes it consistent. That way we we can focus first on consistency and think about backwards compat, testing, etc. Once that lands we can continue with this PR. Would you be interested in taking this on?

Copy link
Author

Choose a reason for hiding this comment

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

Sounds good to me, will tag you once it's ready.

@lgrammel lgrammel self-assigned this Jan 9, 2026
@KONRADS098 KONRADS098 marked this pull request as draft January 9, 2026 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants