From 336d4b22064fbeb1ddb96b0b3ea23aedacee9b41 Mon Sep 17 00:00:00 2001 From: Tanzim Hossain Romel Date: Thu, 4 Dec 2025 15:57:56 +0600 Subject: [PATCH] fix(api): align ChatCompletionCustomToolParam structure with API spec The Chat Completions API custom tool type had incorrect nesting that didn't match the actual API structure. The type expected `name`, `description`, and `format` to be nested inside a `custom` object, and `syntax`/`definition` to be nested inside `format.grammar`. The correct structure (matching the Responses API and documentation) has these fields at the top level and reuses the shared CustomToolInputFormat type. Fixes #2667 --- .../chat/chat_completion_custom_tool_param.py | 51 +++---------------- 1 file changed, 8 insertions(+), 43 deletions(-) diff --git a/src/openai/types/chat/chat_completion_custom_tool_param.py b/src/openai/types/chat/chat_completion_custom_tool_param.py index 14959ee449..1dc2c41aef 100644 --- a/src/openai/types/chat/chat_completion_custom_tool_param.py +++ b/src/openai/types/chat/chat_completion_custom_tool_param.py @@ -2,57 +2,22 @@ from __future__ import annotations -from typing import Union -from typing_extensions import Literal, Required, TypeAlias, TypedDict +from typing_extensions import Literal, Required, TypedDict -__all__ = [ - "ChatCompletionCustomToolParam", - "Custom", - "CustomFormat", - "CustomFormatText", - "CustomFormatGrammar", - "CustomFormatGrammarGrammar", -] +from ..shared_params.custom_tool_input_format import CustomToolInputFormat +__all__ = ["ChatCompletionCustomToolParam"] -class CustomFormatText(TypedDict, total=False): - type: Required[Literal["text"]] - """Unconstrained text format. Always `text`.""" - -class CustomFormatGrammarGrammar(TypedDict, total=False): - definition: Required[str] - """The grammar definition.""" - - syntax: Required[Literal["lark", "regex"]] - """The syntax of the grammar definition. One of `lark` or `regex`.""" - - -class CustomFormatGrammar(TypedDict, total=False): - grammar: Required[CustomFormatGrammarGrammar] - """Your chosen grammar.""" - - type: Required[Literal["grammar"]] - """Grammar format. Always `grammar`.""" - - -CustomFormat: TypeAlias = Union[CustomFormatText, CustomFormatGrammar] - - -class Custom(TypedDict, total=False): +class ChatCompletionCustomToolParam(TypedDict, total=False): name: Required[str] """The name of the custom tool, used to identify it in tool calls.""" + type: Required[Literal["custom"]] + """The type of the custom tool. Always `custom`.""" + description: str """Optional description of the custom tool, used to provide more context.""" - format: CustomFormat + format: CustomToolInputFormat """The input format for the custom tool. Default is unconstrained text.""" - - -class ChatCompletionCustomToolParam(TypedDict, total=False): - custom: Required[Custom] - """Properties of the custom tool.""" - - type: Required[Literal["custom"]] - """The type of the custom tool. Always `custom`."""