Implementation:Openai Openai python Custom Tool Model
| Knowledge Sources | |
|---|---|
| Domains | API_Types, Python |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Concrete type for representing a custom tool response model provided by the openai-python SDK.
Description
CustomTool is a Pydantic model class that represents a custom tool that processes input using a specified format. It extends BaseModel and includes a name field identifying the tool in tool calls, a type field fixed to "custom", an optional description providing additional context about the tool, and an optional format field of type CustomToolInputFormat that specifies the input format (defaulting to unconstrained text when not provided).
Usage
Import this type when you need to deserialize or inspect custom tool definitions returned in API responses. This is the response model counterpart to CustomToolParam which is used for request construction.
Code Reference
Source Location
- Repository: openai-python
- File: src/openai/types/responses/custom_tool.py
Signature
class CustomTool(BaseModel):
"""A custom tool that processes input using a specified format."""
name: str
type: Literal["custom"]
description: Optional[str] = None
format: Optional[CustomToolInputFormat] = None
Import
from openai.types.responses import CustomTool
I/O Contract
Fields
| Name | Type | Required | Description |
|---|---|---|---|
| name | str | Yes | The name of the custom tool, used to identify it in tool calls. |
| type | Literal["custom"] | Yes | The type of the custom tool. Always "custom". |
| description | Optional[str] | No | Optional description of the custom tool, used to provide more context. |
| format | Optional[CustomToolInputFormat] | No | The input format for the custom tool. Default is unconstrained text. |
Usage Examples
from openai.types.responses import CustomTool
# Inspect a custom tool from a response
response = client.responses.create(
model="gpt-4o",
tools=[{"type": "custom", "name": "my_tool"}],
input="Use my_tool to process data",
)
for tool in response.tools:
if isinstance(tool, CustomTool):
print(f"Tool: {tool.name}, Type: {tool.type}")
if tool.description:
print(f"Description: {tool.description}")