Openai lm invoker
Defines a module to interact with OpenAI language models.
OpenAILMInvoker(model_name, api_key=None, base_url=OPENAI_DEFAULT_URL, model_kwargs=None, default_hyperparameters=None, tools=None, response_schema=None, output_analytics=False, retry_config=None, thinking=False, image_generation=False, data_stores=None, input_transformer=InputTransformerType.IDENTITY, output_transformer=OutputTransformerType.IDENTITY)
Bases: BaseLMInvoker
A language model invoker to interact with OpenAI language models.
This class provides support for OpenAI's Responses API schema, which is recommended by OpenAI as the preferred API
to use whenever possible. Use this class unless you have a specific reason to use the Chat Completions API instead.
The Chat Completions API schema is supported through the OpenAIChatCompletionsLMInvoker class.
Examples:
lm_invoker = OpenAILMInvoker(model_name="gpt-5-nano")
result = await lm_invoker.invoke("Hi there!")
Supported features
- Basic invocation
- Streaming output
- Message roles
- Multimodal input a. Text b. Document c. Image
- Structured output
- Tool calling
- Native tools a. Code interpreter b. Data store c. Image generation d. MCP connector e. MCP server f. Web search
- Thinking
- Output analytics
- Retry and timeout
- Extra capabilities a. Input transformer b. Output transformer c. Batch invocation d. File management e. Data store management
For full documentation and examples, please refer to the LM Invoker tutorial: https://gdplabs.gitbook.io/sdk/gen-ai-sdk/tutorials/inference/lm-invoker
OpenAI compatible endpoints
This class can interact with endpoints compatible with OpenAI's Responses API schema
(e.g. SGLang: https://github.com/sgl-project/sglang). To do this, simply set base_url to the endpoint URL.
Supported features may vary between endpoints. Unsupported features will result in an error.
Attributes:
| Name | Type | Description |
|---|---|---|
model_id |
str
|
The model ID of the language model. |
model_provider |
str
|
The provider of the language model. |
model_name |
str
|
The name of the language model. |
client_kwargs |
dict[str, Any]
|
The keyword arguments for the OpenAI client. |
default_config |
dict[str, Any]
|
Default config for invoking the model. |
tools |
list[Tool]
|
The list of tools provided to the model to enable tool calling. |
response_schema |
ResponseSchema | None
|
The schema of the response. If provided, the model will output a structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema dictionary. |
output_analytics |
bool
|
Whether to output the invocation analytics. |
retry_config |
RetryConfig
|
The retry configuration for the language model. |
thinking |
ThinkingConfig
|
The thinking configuration for the language model. |
image_generation |
bool
|
Whether to enable image generation. |
data_stores |
list[AttachmentStore]
|
The data stores to retrieve internal knowledge from. |
input_transformer |
InputTransformerType
|
The type of input transformer to use. |
output_transformer |
OutputTransformerType
|
The type of output transformer to use. |
Initializes a new instance of the OpenAILMInvoker class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
The name of the OpenAI model. |
required |
api_key
|
str | None
|
The API key for authenticating with OpenAI. Defaults to None, in which
case the |
None
|
base_url
|
str
|
The base URL of a custom endpoint that is compatible with OpenAI's Responses API schema. Defaults to OpenAI's default URL. |
OPENAI_DEFAULT_URL
|
model_kwargs
|
dict[str, Any] | None
|
Additional model parameters. Defaults to None. |
None
|
default_hyperparameters
|
dict[str, Any] | None
|
Default hyperparameters for invoking the model. Defaults to None. |
None
|
tools
|
list[LMTool] | None
|
Tools provided to the model to enable tool calling. Defaults to None, in which case an empty list is used. |
None
|
response_schema
|
ResponseSchema | None
|
The schema of the response. If provided, the model will output a structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema dictionary. Defaults to None. |
None
|
output_analytics
|
bool
|
Whether to output the invocation analytics. Defaults to False. |
False
|
retry_config
|
RetryConfig | None
|
The retry configuration for the language model. Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used. |
None
|
thinking
|
bool | ThinkingConfig
|
A boolean or ThinkingConfig object to configure thinking. Defaults to False. |
False
|
image_generation
|
bool
|
Whether to enable image generation. Defaults to False. |
False
|
data_stores
|
list[AttachmentStore] | None
|
The data stores to retrieve internal knowledge from. Defaults to None, in which case no data stores will be used. |
None
|
input_transformer
|
InputTransformerType
|
The type of input transformer to use. Defaults to InputTransformerType.IDENTITY, which returns the input without transformation. |
IDENTITY
|
output_transformer
|
OutputTransformerType
|
The type of output transformer to use. Defaults to OutputTransformerType.IDENTITY, which returns the output without transformation. |
IDENTITY
|
batch
cached
property
The batch operations for the language model.
Returns:
| Name | Type | Description |
|---|---|---|
OpenAIBatchOperations |
OpenAIBatchOperations
|
The batch operations for the language model. |
data_store
cached
property
The data store operations for the language model.
Returns:
| Name | Type | Description |
|---|---|---|
OpenAIDataStoreOperations |
OpenAIDataStoreOperations
|
The data store operations for the language model. |
file
cached
property
The file operations for the language model.
Returns:
| Name | Type | Description |
|---|---|---|
OpenAIFileOperations |
OpenAIFileOperations
|
The file operations for the language model. |
set_data_stores(data_stores)
Sets the data stores for the OpenAI language model.
This method sets the data stores for the OpenAI language model. Any existing data stores will be replaced.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_stores
|
list[AttachmentStore]
|
The list of data stores to be used. |
required |