Skip to navigation

nemo_gym.openai_utils

View as Markdown

Module Contents

Classes

NameDescription
ChatCompletionModerationChat moderation shape omitted by some OpenAI SDK artifacts.
NeMoGymAdditionalToolsAdditional tool definitions accepted in request input.
NeMoGymAsyncOpenAIThis is just a stub class that wraps around aiohttp
NeMoGymChatCompletion-
NeMoGymChatCompletionAllowedToolChoiceParam-
NeMoGymChatCompletionAllowedToolsParam-
NeMoGymChatCompletionAssistantMessageForTrainingParam-
NeMoGymChatCompletionAssistantMessageParam-
NeMoGymChatCompletionContentPartFileParam-
NeMoGymChatCompletionContentPartImageParam-
NeMoGymChatCompletionContentPartInputAudioParam-
NeMoGymChatCompletionContentPartTextParam-
NeMoGymChatCompletionContentPartVideoUrlParam-
NeMoGymChatCompletionCreateParamsNonStreaming-
NeMoGymChatCompletionCustomToolParam-
NeMoGymChatCompletionDeveloperMessageParam-
NeMoGymChatCompletionMessage-
NeMoGymChatCompletionMessageCustomToolCall-
NeMoGymChatCompletionMessageCustomToolCallParam-
NeMoGymChatCompletionMessageForTraining-
NeMoGymChatCompletionMessageToolCall-
NeMoGymChatCompletionMessageToolCallFunctionParam-
NeMoGymChatCompletionMessageToolCallParam-
NeMoGymChatCompletionPredictionContentParam-
NeMoGymChatCompletionSystemMessageParam-
NeMoGymChatCompletionToolMessageParam-
NeMoGymChatCompletionToolParam-
NeMoGymChatCompletionUserMessageParam-
NeMoGymChoice-
NeMoGymCodeInterpreterContainerAutoParam-
NeMoGymCodeInterpreterToolParam-
NeMoGymCompactionTriggerA request for the provider to compact the context (compaction_trigger item).
NeMoGymCompoundFilter-
NeMoGymComputerCallOutputA computer-use result accepted in request input (computer_call_output item).
NeMoGymContainerAutoParam-
NeMoGymContainerNetworkPolicyAllowlistParam-
NeMoGymEasyInputMessage-
NeMoGymEasyInputMessageForTraining-
NeMoGymFileSearchToolParam-
NeMoGymFunction-
NeMoGymFunctionCallOutputWe copy openai.types.responses.response_input_param.FunctionCallOutput, originally a TypedDict, as a BaseModel here
NeMoGymFunctionDefinition-
NeMoGymFunctionShellToolParam-
NeMoGymFunctionToolParam-
NeMoGymImageGenerationCallA hosted image-generation call (OpenAI Responses image_generation_call output item).
NeMoGymInputAudioinput_audio payload of a chat content part, with an open format token.
NeMoGymInputVideoPartVideo content accepted by the Responses-compatible Gym API.
NeMoGymLocalEnvironmentParam-
NeMoGymLocalShellCallA local-shell command for the client to execute (local_shell_call output item).
NeMoGymLocalShellCallOutputThe client’s result of a local shell command (local_shell_call_output item).
NeMoGymLogprobCopy of openai.types.responses.response_output_text_param.Logprob with List in place of Iterable.
NeMoGymLogprobTopLogprobCopy of openai.types.responses.response_output_text_param.LogprobTopLogprob with List in place of Iterable.
NeMoGymMcpApprovalResponseThe client’s answer to a hosted-MCP approval request (mcp_approval_response item).
NeMoGymMessage-
NeMoGymMessageForTraining-
NeMoGymNamespaceToolParam-
NeMoGymResponse-
NeMoGymResponseAdditionalToolsAdditional tool definitions returned by the provider.
NeMoGymResponseApplyPatchToolCallA patch the model wants applied (apply_patch_call output item).
NeMoGymResponseApplyPatchToolCallOutputThe client’s result of applying a patch (apply_patch_call_output item).
NeMoGymResponseCodeInterpreterToolCallA hosted code-interpreter call (OpenAI Responses code_interpreter_call output item).
NeMoGymResponseCompactionItemAn opaque context-compaction record the provider emits (compaction item).
NeMoGymResponseComputerCallOutputProvider output for a computer-use action, including status="failed".
NeMoGymResponseComputerToolCallA computer-use action for the client to execute (computer_call output item).
NeMoGymResponseCreateParamsNonStreamingThis class is a copy of openai.types.responses.response_create_params.ResponseCreateParamsNonStreaming
NeMoGymResponseCustomToolCallA client-executed custom tool call (OpenAI Responses custom_tool_call output item).
NeMoGymResponseCustomToolCallOutputThe client’s result of a custom tool call (custom_tool_call_output item).
NeMoGymResponseCustomToolCallOutputItemProvider output for a custom tool call.
NeMoGymResponseFileSearchToolCallA hosted file-search call (OpenAI Responses file_search_call output item).
NeMoGymResponseFunctionCallOutputProvider output for a function call result.
NeMoGymResponseFunctionShellToolCallA shell command the model wants run (shell_call output item).
NeMoGymResponseFunctionShellToolCallOutputThe client’s result of running a shell command (shell_call_output item).
NeMoGymResponseFunctionToolCall-
NeMoGymResponseFunctionToolCallForTraining-
NeMoGymResponseFunctionWebSearchA hosted web-search output item returned by the OpenAI Responses API.
NeMoGymResponseInputText-
NeMoGymResponseInputTokensDetails-
NeMoGymResponseLocalShellCallOutputProvider output for a local shell command.
NeMoGymResponseMcpApprovalRequestA hosted-MCP approval request (OpenAI Responses mcp_approval_request item).
NeMoGymResponseMcpApprovalResponseProvider output carrying an answer to a hosted-MCP approval request.
NeMoGymResponseMcpCallA hosted-MCP tool call (OpenAI Responses mcp_call output item).
NeMoGymResponseMcpListToolsA hosted-MCP tool listing (OpenAI Responses mcp_list_tools output item).
NeMoGymResponseOutputMessage-
NeMoGymResponseOutputMessageForTraining-
NeMoGymResponseOutputRefusal-
NeMoGymResponseOutputText-
NeMoGymResponseOutputTokensDetails-
NeMoGymResponseReasoningItem-
NeMoGymResponseReasoningItemForTraining-
NeMoGymResponseToolSearchCallA tool-search call (tool_search_call output item).
NeMoGymResponseToolSearchOutputItemThe result of a tool search (tool_search_output item).
NeMoGymResponseUsage-
NeMoGymSummary-
NeMoGymToolChoiceAllowedParam-
PermanentEndpointErrorThe upstream key is spent or unauthorized; further calls on this client skip the wire.
TokenIDLogProbMixin-
TokenIDLogProbTypedDictMixin-

Functions

NameDescription
_add_optional_token_countsAdd reported token counts without turning an unknown count into a measurement.
_decode_error_text-
_discriminate_message_itemChoose a message model from its role, content, and status.
_discriminate_response_input_itemPick the input union tag for a request item.
_discriminate_response_output_itemPick the output union tag for a response item.
_discriminate_untyped_input_itemInfer a typeless input model or use the permissive fallback.
_error_body_is_permanent_authTrue when a 401/403 body is a revoked or invalid key, not a one-off denial.
_error_body_is_permanent_quotaTrue when a 429 body is a spent key, not a transient rate limit.
_first_content_part_typeReturn the type of the first content part, or None for empty or non-list content.
_normalize_output_item_for_replayConvert a provider output item for request replay.
_normalize_tool_for_replayConvert a provider response tool for request replay.
_parsed_error_codeserror.code / error.type tokens from an OpenAI-style error body.
_register_item_tagsIndex each union member class by its Tag, so instances discriminate by class.
_require_response_output_item_typePrevent an untagged output item from being coerced into the wrong union member.
_strip_outer_tool_call_namesCopy tool calls carrying a redundant outer name and remove only that field.
_tag_for_item_instanceMap an item instance to its nearest registered class tag.
_training_variant_tagRoute to the ForTraining member when the item carries complete token metadata.
_validate_atomic_token_metadataRequire complete token metadata when any token field is present.
_validate_input_video_partRequire one non-empty source without changing the TypedDict representation.
accumulate_response_usageAccumulate top-level and detailed response token counts.
training_variant_ofReturn the ForTraining subclass that carries token IDs for item_cls.

Data

CHAT_REQUEST_IGNORED_CLIENT_FIELDS

CHAT_REQUEST_PROVIDER_EXTENSION_FIELDS

NeMoGymChatCompletionContentPartParam

NeMoGymChatCompletionMessageParam

NeMoGymChatCompletionMessageToolCallUnion

NeMoGymChatCompletionMessageToolCallUnionParam

NeMoGymChatCompletionMessageToolCallsParam

NeMoGymChatCompletionOutputMessage

NeMoGymChatCompletionToolChoiceOptionParam

NeMoGymChatCompletionToolUnionParam

NeMoGymContainerNetworkPolicyParam

NeMoGymContent

NeMoGymResponseInput

NeMoGymResponseInputContentList

NeMoGymResponseInputContentPart

NeMoGymResponseInputItem

NeMoGymResponseOutputItem

NeMoGymToolChoice

NeMoGymToolParam

PERMANENT_AUTH_CODES

PERMANENT_QUOTA_CODES

RATE_LIMIT_ERROR_CODES

REQUIRED_TOKEN_METADATA_FIELDS

RESPONSES_TO_TRAIN

RETRY_ERROR_CODES

RoutedExperts

TOKEN_METADATA_FIELDS

_ITEM_STATUSES

_MESSAGE_ROLES

_OUTPUT_CONTENT_PART_TYPES

_RESPONSE_INPUT_ITEM_TAG_BY_CLASS

_RESPONSE_OUTPUT_ITEM_TAG_BY_CLASS

_SIMPLE_MESSAGE_ROLES

_TRAINABLE_ITEM_TAGS

_TRAINING_TAG_SUFFIX

API

class nemo_gym.openai_utils.ChatCompletionModeration

Bases: typing.TypedDict

Chat moderation shape omitted by some OpenAI SDK artifacts.

model
Required[str]
class nemo_gym.openai_utils.NeMoGymAdditionalTools()

Bases: InputAdditionalTools

Additional tool definitions accepted in request input.

class nemo_gym.openai_utils.NeMoGymAsyncOpenAI()

Bases: BaseModel

This is just a stub class that wraps around aiohttp

_permanent_trip
Optional[tuple[int, bytes, str]] = PrivateAttr(default=None)
api_key
str
base_url
str
connect_timeout_seconds
Optional[float]
default_headers
Dict[str, str]
internal
bool
max_connection_retries
Optional[int]
max_http_attempts
int = Field(default=MAX_NUM_TRIES, ge=1)
max_num_tries
Optional[Literal[1]]
request_timeout_seconds
Optional[float]
nemo_gym.openai_utils.NeMoGymAsyncOpenAI._raise_for_status(
response: nemo_gym.server_utils.ClientResponse,
request_kwargs: typing.Dict[str, typing.Any]
) -> None
async
nemo_gym.openai_utils.NeMoGymAsyncOpenAI._raise_permanent_error() -> None
nemo_gym.openai_utils.NeMoGymAsyncOpenAI._request(
request_kwargs: typing.Dict = {}
) -> nemo_gym.server_utils.ClientResponse
async
nemo_gym.openai_utils.NeMoGymAsyncOpenAI._request_with_retry(
request_kwargs: typing.Dict = {}
) -> nemo_gym.server_utils.ClientResponse
async
nemo_gym.openai_utils.NeMoGymAsyncOpenAI._trip_permanent_error(
status: int,
content: bytes | str,
url: typing.Any
) -> None
nemo_gym.openai_utils.NeMoGymAsyncOpenAI.create_chat_completion(
kwargs = {}
)
async
nemo_gym.openai_utils.NeMoGymAsyncOpenAI.create_completion(
kwargs = {}
)
async
nemo_gym.openai_utils.NeMoGymAsyncOpenAI.create_models()
async
nemo_gym.openai_utils.NeMoGymAsyncOpenAI.create_response(
kwargs = {}
)
async
nemo_gym.openai_utils.NeMoGymAsyncOpenAI.create_tokenize(
kwargs = {}
)
async
class nemo_gym.openai_utils.NeMoGymChatCompletion()

Bases: ChatCompletion

choices
List[NeMoGymChoice]
service_tier
Optional[str] = None
class nemo_gym.openai_utils.NeMoGymChatCompletionAllowedToolChoiceParam()

Bases: ChatCompletionAllowedToolChoiceParam

allowed_tools
Required[NeMoGymChatCompletionAllowedToolsParam]
class nemo_gym.openai_utils.NeMoGymChatCompletionAllowedToolsParam()

Bases: ChatCompletionAllowedToolsParam

tools
Required[List[Dict[str, object]]]
class nemo_gym.openai_utils.NeMoGymChatCompletionAssistantMessageForTrainingParam

Bases: typing.TypedDict

class nemo_gym.openai_utils.NeMoGymChatCompletionAssistantMessageParam()

Bases: ChatCompletionAssistantMessageParam

content
Union[str, List[ContentArrayOfContentPart], None]
reasoning_content
str | None
tool_calls
Optional[NeMoGymChatCompletionMessageToolCallsParam] = None
class nemo_gym.openai_utils.NeMoGymChatCompletionContentPartFileParam()

Bases: ChatCompletionContentPartFileParam

class nemo_gym.openai_utils.NeMoGymChatCompletionContentPartImageParam()

Bases: ChatCompletionContentPartImageParam

class nemo_gym.openai_utils.NeMoGymChatCompletionContentPartInputAudioParam

Bases: typing.TypedDict

input_audio
Required[NeMoGymInputAudio]
type
Required[Literal['input_audio']]
class nemo_gym.openai_utils.NeMoGymChatCompletionContentPartTextParam()

Bases: ChatCompletionContentPartTextParam

class nemo_gym.openai_utils.NeMoGymChatCompletionContentPartVideoUrlParam

Bases: typing.TypedDict

type
Required[Literal['video_url']]
video_url
Required[Union[str, Dict[str, Any]]]
class nemo_gym.openai_utils.NeMoGymChatCompletionCreateParamsNonStreaming()

Bases: BaseModel

audio
Optional[ChatCompletionAudioParam] = None
aws_region_name
object = Field(default=None, exclude=True)
chat_template_kwargs
Optional[Dict[str, Any]] = None
frequency_penalty
Optional[float] = None
logit_bias
Optional[Dict[str, int]] = None
logprobs
Optional[bool] = None
max_completion_tokens
Optional[int] = None
max_tokens
Optional[int] = None
messages
List[NeMoGymChatCompletionMessageParam]
metadata
Optional[Metadata] = None
modalities
Optional[List[Literal['text', 'audio']]] = None
model
Optional[Union[str, ChatModel]] = None
model_config
= ConfigDict(extra='forbid')
moderation
Optional[ChatCompletionModeration] = None
n
Optional[int] = None
output_config
Optional[Dict[str, Any]] = None
parallel_tool_calls
bool = True
prediction
Optional[NeMoGymChatCompletionPredictionContentParam] = None
presence_penalty
Optional[float] = None
prompt_cache_key
Optional[str] = None
prompt_cache_retention
Optional[Literal['in_memory', '24h']] = None
reasoning_effort
Optional[ReasoningEffort] = None
response_format
Optional[ResponseFormat] = None
safety_identifier
Optional[str] = None
seed
Optional[int] = None
service_tier
Optional[Literal['auto', 'default', 'flex', 'scale', 'priority']] = None
stop
Union[Optional[str], List[str], None] = None
store
Optional[bool] = None
stream
Optional[Literal[False]] = None
stream_options
Optional[ChatCompletionStreamOptionsParam] = None
temperature
Optional[float] = None
thinking
Optional[Dict[str, Any]] = None
tool_choice
Optional[NeMoGymChatCompletionToolChoiceOptionParam] = None
tools
Optional[List[NeMoGymChatCompletionToolUnionParam]] = None
top_logprobs
Optional[int] = None
top_p
Optional[float] = None
user
Optional[str] = None
verbosity
Optional[Literal['low', 'medium', 'high']] = None
web_search_options
Optional[WebSearchOptions] = None
nemo_gym.openai_utils.NeMoGymChatCompletionCreateParamsNonStreaming.drop_litellm_provider_specific_fields(
value: typing.Any
) -> typing.Any
classmethod

Drop provider_specific_fields from replayed assistant history.

litellm’s Message.model_dump() emits that key on every assistant turn (holding response fields it does not model, such as refusal), and harnesses built on litellm replay the dump verbatim. It carries nothing a model server needs, and the strict message schema would reject it.

class nemo_gym.openai_utils.NeMoGymChatCompletionCustomToolParam()

Bases: ChatCompletionCustomToolParam

class nemo_gym.openai_utils.NeMoGymChatCompletionDeveloperMessageParam()

Bases: ChatCompletionDeveloperMessageParam

content
Required[Union[str, List[NeMoGymChatCompletionContentPartTextParam]]]
class nemo_gym.openai_utils.NeMoGymChatCompletionMessage()

Bases: ChatCompletionMessage

tool_calls
Optional[List[NeMoGymChatCompletionMessageToolCallUnion]] = None
class nemo_gym.openai_utils.NeMoGymChatCompletionMessageCustomToolCall()

Bases: ChatCompletionMessageCustomToolCall

class nemo_gym.openai_utils.NeMoGymChatCompletionMessageCustomToolCallParam()

Bases: ChatCompletionMessageCustomToolCallParam

class nemo_gym.openai_utils.NeMoGymChatCompletionMessageForTraining()
class nemo_gym.openai_utils.NeMoGymChatCompletionMessageToolCall()

Bases: ChatCompletionMessageToolCall

function
NeMoGymFunction
class nemo_gym.openai_utils.NeMoGymChatCompletionMessageToolCallFunctionParam

Bases: typing.TypedDict

arguments
Required[str]
name
Required[str]
class nemo_gym.openai_utils.NeMoGymChatCompletionMessageToolCallParam()

Bases: ChatCompletionMessageToolCallParam

function
NeMoGymChatCompletionMessageToolCallFunctionParam
class nemo_gym.openai_utils.NeMoGymChatCompletionPredictionContentParam()

Bases: ChatCompletionPredictionContentParam

content
Required[Union[str, List[NeMoGymChatCompletionContentPartTextParam]]]
class nemo_gym.openai_utils.NeMoGymChatCompletionSystemMessageParam()

Bases: ChatCompletionSystemMessageParam

content
Required[Union[str, List[NeMoGymChatCompletionContentPartTextParam]]]
class nemo_gym.openai_utils.NeMoGymChatCompletionToolMessageParam()

Bases: ChatCompletionToolMessageParam

content
Required[Union[str, List[NeMoGymChatCompletionContentPartTextParam]]]
name
NotRequired[str]
class nemo_gym.openai_utils.NeMoGymChatCompletionToolParam()

Bases: ChatCompletionToolParam

function
Required[NeMoGymFunctionDefinition]
class nemo_gym.openai_utils.NeMoGymChatCompletionUserMessageParam()

Bases: ChatCompletionUserMessageParam

content
Required[Union[str, List[NeMoGymChatCompletionContentPartParam]]]
class nemo_gym.openai_utils.NeMoGymChoice()

Bases: Choice

message
NeMoGymChatCompletionOutputMessage
class nemo_gym.openai_utils.NeMoGymCodeInterpreterContainerAutoParam()

Bases: CodeInterpreterContainerCodeInterpreterToolAuto

network_policy
NeMoGymContainerNetworkPolicyParam
class nemo_gym.openai_utils.NeMoGymCodeInterpreterToolParam()

Bases: CodeInterpreter

container
Required[Union[str, NeMoGymCodeInterpreterContainerAutoParam]]
class nemo_gym.openai_utils.NeMoGymCompactionTrigger()

Bases: CompactionTrigger

A request for the provider to compact the context (compaction_trigger item).

Gym preserves this input item when replaying the transcript.

class nemo_gym.openai_utils.NeMoGymCompoundFilter()

Bases: CompoundFilter

filters
Required[List[Union[ComparisonFilter, object]]]
class nemo_gym.openai_utils.NeMoGymComputerCallOutput()

Bases: ComputerCallOutput

A computer-use result accepted in request input (computer_call_output item).

class nemo_gym.openai_utils.NeMoGymContainerAutoParam()

Bases: ContainerAutoParam

network_policy
NeMoGymContainerNetworkPolicyParam
skills
List[Union[SkillReferenceParam, InlineSkillParam]]
class nemo_gym.openai_utils.NeMoGymContainerNetworkPolicyAllowlistParam()

Bases: ContainerNetworkPolicyAllowlistParam

domain_secrets
List[ContainerNetworkPolicyDomainSecretParam]
class nemo_gym.openai_utils.NeMoGymEasyInputMessage()

Bases: BaseModel

content
Union[str, NeMoGymResponseInputContentList]
phase
Optional[Literal['commentary', 'final_answer']] = None
role
Literal['user', 'assistant', 'system', 'developer']
type
Literal['message'] = 'message'
class nemo_gym.openai_utils.NeMoGymEasyInputMessageForTraining()
class nemo_gym.openai_utils.NeMoGymFileSearchToolParam()

Bases: FileSearchToolParam

filters
Optional[Union[ComparisonFilter, NeMoGymCompoundFilter]]
class nemo_gym.openai_utils.NeMoGymFunction()

Bases: BaseModel

arguments
str
name
str
class nemo_gym.openai_utils.NeMoGymFunctionCallOutput()

Bases: BaseModel

We copy openai.types.responses.response_input_param.FunctionCallOutput, originally a TypedDict, as a BaseModel here so that we can use it in the NeMoGymResponseOutputItem below and be consistent with the other ResponseOutputItem types.

call_id
str
id
Optional[str] = None
output
Union[str, ResponseFunctionCallOutputItemListParam]
status
Optional[Literal['in_progress', 'completed', 'incomplete']] = None
type
Literal['function_call_output'] = 'function_call_output'
class nemo_gym.openai_utils.NeMoGymFunctionDefinition()

Bases: FunctionDefinition

class nemo_gym.openai_utils.NeMoGymFunctionShellToolParam()

Bases: FunctionShellToolParam

environment
Optional[Union[NeMoGymContainerAutoParam, NeMoGymLocalEnvironmentParam, ContainerReferenceParam]]
class nemo_gym.openai_utils.NeMoGymFunctionToolParam()

Bases: FunctionToolParam

class nemo_gym.openai_utils.NeMoGymImageGenerationCall()

Bases: ImageGenerationCall

A hosted image-generation call (OpenAI Responses image_generation_call output item).

class nemo_gym.openai_utils.NeMoGymInputAudio

Bases: typing.TypedDict

input_audio payload of a chat content part, with an open format token.

Declared on its own rather than subclassing the SDK’s InputAudio (and the content part likewise rather than ChatCompletionContentPartInputAudioParam): the SDK types format as Literal["wav", "mp3"], and a TypedDict subclass may not change the type of an inherited field (PEP 589). A widened subclass would fail type checking and would claim to be an SDK InputAudio while carrying formats that contract forbids. vLLM and OpenAI-compatible gateways build a data:audio/<format> URL and decode by content, so callers may send m4a/flac/ogg/aac/aiff to self-hosted audio models.

data
Required[str]
format
Required[str]
class nemo_gym.openai_utils.NeMoGymInputVideoPart

Bases: typing.TypedDict

Video content accepted by the Responses-compatible Gym API.

type
Required[Literal['input_video']]
video
Union[str, Dict[str, Any]]
video_url
Union[str, Dict[str, Any]]
class nemo_gym.openai_utils.NeMoGymLocalEnvironmentParam()

Bases: LocalEnvironmentParam

skills
List[LocalSkillParam]
class nemo_gym.openai_utils.NeMoGymLocalShellCall()

Bases: LocalShellCall

A local-shell command for the client to execute (local_shell_call output item).

class nemo_gym.openai_utils.NeMoGymLocalShellCallOutput()

Bases: LocalShellCallOutput

The client’s result of a local shell command (local_shell_call_output item).

class nemo_gym.openai_utils.NeMoGymLogprob

Bases: typing.TypedDict

Copy of openai.types.responses.response_output_text_param.Logprob with List in place of Iterable.

Pydantic validates an Iterable field into a lazy iterator that can be read only once. The model server fills these logprobs, and the agent sends the output message back as input on the next turn. With the lazy form, orjson cannot encode that next request, and a second serialization returns empty lists.

bytes
Required[List[int]]
logprob
Required[float]
token
Required[str]
top_logprobs
Required[List[NeMoGymLogprobTopLogprob]]
class nemo_gym.openai_utils.NeMoGymLogprobTopLogprob

Bases: typing.TypedDict

Copy of openai.types.responses.response_output_text_param.LogprobTopLogprob with List in place of Iterable.

bytes
Required[List[int]]
logprob
Required[float]
token
Required[str]
class nemo_gym.openai_utils.NeMoGymMcpApprovalResponse()

Bases: McpApprovalResponse

The client’s answer to a hosted-MCP approval request (mcp_approval_response item).

class nemo_gym.openai_utils.NeMoGymMessage()

Bases: BaseModel

content
NeMoGymResponseInputContentList
role
Literal['user', 'system', 'developer']
status
Literal['in_progress', 'completed', 'incomplete'] = 'completed'
type
Literal['message'] = 'message'
class nemo_gym.openai_utils.NeMoGymMessageForTraining()
class nemo_gym.openai_utils.NeMoGymNamespaceToolParam()

Bases: NamespaceToolParam

tools
Required[List[NamespaceToolParamTool]]
class nemo_gym.openai_utils.NeMoGymResponse()

Bases: Response

output
List[NeMoGymResponseOutputItem]
service_tier
Optional[str] = None
usage
Optional[NeMoGymResponseUsage] = None
class nemo_gym.openai_utils.NeMoGymResponseAdditionalTools()

Bases: OutputAdditionalTools

Additional tool definitions returned by the provider.

class nemo_gym.openai_utils.NeMoGymResponseApplyPatchToolCall()

Bases: ResponseApplyPatchToolCall

A patch the model wants applied (apply_patch_call output item).

class nemo_gym.openai_utils.NeMoGymResponseApplyPatchToolCallOutput()

Bases: ResponseApplyPatchToolCallOutput

The client’s result of applying a patch (apply_patch_call_output item).

class nemo_gym.openai_utils.NeMoGymResponseCodeInterpreterToolCall()

Bases: ResponseCodeInterpreterToolCall

A hosted code-interpreter call (OpenAI Responses code_interpreter_call output item).

class nemo_gym.openai_utils.NeMoGymResponseCompactionItem()

Bases: ResponseCompactionItem

An opaque context-compaction record the provider emits (compaction item).

class nemo_gym.openai_utils.NeMoGymResponseComputerCallOutput()

Bases: ResponseComputerToolCallOutputItem

Provider output for a computer-use action, including status="failed".

class nemo_gym.openai_utils.NeMoGymResponseComputerToolCall()

Bases: ResponseComputerToolCall

A computer-use action for the client to execute (computer_call output item).

class nemo_gym.openai_utils.NeMoGymResponseCreateParamsNonStreaming()

Bases: BaseModel

This class is a copy of openai.types.responses.response_create_params.ResponseCreateParamsNonStreaming We make a copy of it here since ResponseCreateParamsNonStreaming is a TypedDict with no strict validation. We need to do server side validation here.

background
Optional[bool] = None
context_management
Optional[List[ContextManagement]] = None
conversation
Union[str, ResponseConversationParamParam, None] = None
include
Optional[List[ResponseIncludable]] = None
input
Union[str, NeMoGymResponseInput]
instructions
Optional[str] = None
max_output_tokens
Optional[int] = None
max_tool_calls
Optional[int] = None
metadata
Optional[Metadata] = None
model
Optional[ResponsesModel] = None
model_config
= ConfigDict(extra='forbid')
moderation
Optional[Moderation] = None
parallel_tool_calls
bool = True
previous_response_id
Optional[str] = None
prompt
Optional[ResponsePromptParam] = None
prompt_cache_key
Optional[str] = None
prompt_cache_retention
Optional[Literal['in_memory', '24h']] = None
reasoning
Optional[Reasoning] = None
safety_identifier
Optional[str] = None
service_tier
Optional[Literal['auto', 'default', 'flex', 'scale', 'priority']] = None
store
Optional[bool] = None
stream
Optional[Literal[False]] = None
stream_options
Optional[StreamOptions] = None
temperature
Optional[float] = None
text
Optional[ResponseTextConfigParam] = None
tool_choice
NeMoGymToolChoice = 'auto'
tools
List[NeMoGymToolParam] = Field(default_factory=list)
top_logprobs
Optional[int] = None
top_p
Optional[float] = None
truncation
Optional[Literal['auto', 'disabled']] = None
user
Optional[str] = None
nemo_gym.openai_utils.NeMoGymResponseCreateParamsNonStreaming.normalize_output_items_for_replay(
value: typing.Any
) -> typing.Any
classmethod

Normalize response-derived fields before request validation.

The method name is retained for compatibility; replayed tools are normalized too.

class nemo_gym.openai_utils.NeMoGymResponseCustomToolCall()

Bases: ResponseCustomToolCall

A client-executed custom tool call (OpenAI Responses custom_tool_call output item).

class nemo_gym.openai_utils.NeMoGymResponseCustomToolCallOutput()

Bases: ResponseCustomToolCallOutput

The client’s result of a custom tool call (custom_tool_call_output item).

class nemo_gym.openai_utils.NeMoGymResponseCustomToolCallOutputItem()

Bases: ResponseCustomToolCallOutputItem

Provider output for a custom tool call.

class nemo_gym.openai_utils.NeMoGymResponseFileSearchToolCall()

Bases: ResponseFileSearchToolCall

A hosted file-search call (OpenAI Responses file_search_call output item).

The provider executes the search and returns the call in response.output. Inherits the upstream typing unchanged.

class nemo_gym.openai_utils.NeMoGymResponseFunctionCallOutput()

Bases: ResponseFunctionToolCallOutputItem

Provider output for a function call result.

class nemo_gym.openai_utils.NeMoGymResponseFunctionShellToolCall()

Bases: ResponseFunctionShellToolCall

A shell command the model wants run (shell_call output item).

class nemo_gym.openai_utils.NeMoGymResponseFunctionShellToolCallOutput()

Bases: ResponseFunctionShellToolCallOutput

The client’s result of running a shell command (shell_call_output item).

class nemo_gym.openai_utils.NeMoGymResponseFunctionToolCall()

Bases: BaseModel

arguments
str
call_id
str
id
Optional[str] = None
name
str
namespace
Optional[str] = None
status
Optional[Literal['in_progress', 'completed', 'incomplete']] = None
type
Literal['function_call'] = 'function_call'
class nemo_gym.openai_utils.NeMoGymResponseFunctionToolCallForTraining()
class nemo_gym.openai_utils.NeMoGymResponseFunctionWebSearch()

Bases: ResponseFunctionWebSearch

A hosted web-search output item returned by the OpenAI Responses API.

action
Optional[Union[ActionSearch, ActionOpenPage, ActionFind, Dict[str, Any]]] = Field(default=None, union_mode='left_to_right')
model_config
= ConfigDict(extra='allow')
nemo_gym.openai_utils.NeMoGymResponseFunctionWebSearch._serialize_action_as_received(
action: typing.Any,
handler: typing.Any,
info: typing.Any
) -> typing.Any
nemo_gym.openai_utils.NeMoGymResponseFunctionWebSearch._serialize_without_inventing_action(
handler: typing.Any
) -> dict[str, typing.Any]
class nemo_gym.openai_utils.NeMoGymResponseInputText()

Bases: ResponseInputTextParam

class nemo_gym.openai_utils.NeMoGymResponseInputTokensDetails()

Bases: ResponseInputTokensDetails

cached_tokens
Optional[int]
class nemo_gym.openai_utils.NeMoGymResponseLocalShellCallOutput()

Bases: OutputLocalShellCallOutput

Provider output for a local shell command.

class nemo_gym.openai_utils.NeMoGymResponseMcpApprovalRequest()

Bases: McpApprovalRequest

A hosted-MCP approval request (OpenAI Responses mcp_approval_request item).

Inherits the upstream McpApprovalRequest typing; id/server_label are relaxed to optional to tolerate endpoints that omit them.

id
Optional[str] = None
server_label
Optional[str] = None
type
Literal['mcp_approval_request'] = 'mcp_approval_request'
class nemo_gym.openai_utils.NeMoGymResponseMcpApprovalResponse()

Bases: OutputMcpApprovalResponse

Provider output carrying an answer to a hosted-MCP approval request.

class nemo_gym.openai_utils.NeMoGymResponseMcpCall()

Bases: McpCall

A hosted-MCP tool call (OpenAI Responses mcp_call output item).

Emitted when the upstream endpoint executes a tool server-side (e.g. NVIDIA-hosted gpt-oss surfacing its built-in python tool as MCP) instead of returning a client-executed function_call. The output/error fields are already populated by the server, so the agent parses and passes it through; there is no client-side execution and hence no training variant.

Inherits the upstream McpCall typing and only relaxes the fields NVIDIA-hosted endpoints may omit or widen: id/server_label are made optional and status accepts any string (upstream pins it to a Literal).

id
Optional[str] = None
server_label
Optional[str] = None
status
Optional[str] = None
type
Literal['mcp_call'] = 'mcp_call'
class nemo_gym.openai_utils.NeMoGymResponseMcpListTools()

Bases: McpListTools

A hosted-MCP tool listing (OpenAI Responses mcp_list_tools output item).

Inherits the upstream McpListTools typing; only id/server_label are relaxed to optional (NVIDIA-hosted endpoints may omit them) and tools is widened to List[Any] so raw tool entries pass through without being coerced into the upstream McpListToolsTool schema.

id
Optional[str] = None
server_label
Optional[str] = None
tools
List[Any] = Field(default_factory=list)
type
Literal['mcp_list_tools'] = 'mcp_list_tools'
class nemo_gym.openai_utils.NeMoGymResponseOutputMessage()

Bases: BaseModel

content
List[NeMoGymContent]
id
str
phase
Optional[Literal['commentary', 'final_answer']] = None
role
Literal['assistant'] = 'assistant'
status
Literal['in_progress', 'completed', 'incomplete'] = 'completed'
type
Literal['message'] = 'message'
class nemo_gym.openai_utils.NeMoGymResponseOutputMessageForTraining()
class nemo_gym.openai_utils.NeMoGymResponseOutputRefusal()

Bases: BaseModel

refusal
str
type
Literal['refusal'] = 'refusal'
class nemo_gym.openai_utils.NeMoGymResponseOutputText()

Bases: BaseModel

annotations
List[Annotation] = Field(default_factory=list)
logprobs
Optional[List[NeMoGymLogprob]] = None
text
str
type
Literal['output_text'] = 'output_text'
class nemo_gym.openai_utils.NeMoGymResponseOutputTokensDetails()

Bases: ResponseOutputTokensDetails

reasoning_tokens
Optional[int]
class nemo_gym.openai_utils.NeMoGymResponseReasoningItem()

Bases: BaseModel

content
Optional[List[ReasoningContent]] = None
encrypted_content
Optional[str] = None
id
str
summary
List[NeMoGymSummary]
type
Literal['reasoning'] = 'reasoning'
class nemo_gym.openai_utils.NeMoGymResponseReasoningItemForTraining()
class nemo_gym.openai_utils.NeMoGymResponseToolSearchCall()

Bases: ResponseToolSearchCall

A tool-search call (tool_search_call output item).

class nemo_gym.openai_utils.NeMoGymResponseToolSearchOutputItem()

Bases: ResponseToolSearchOutputItem

The result of a tool search (tool_search_output item).

class nemo_gym.openai_utils.NeMoGymResponseUsage()

Bases: ResponseUsage

input_tokens_details
NeMoGymResponseInputTokensDetails
output_tokens_details
NeMoGymResponseOutputTokensDetails
classmethod
class nemo_gym.openai_utils.NeMoGymSummary()

Bases: Summary

class nemo_gym.openai_utils.NeMoGymToolChoiceAllowedParam()

Bases: ToolChoiceAllowedParam

tools
Required[List[Dict[str, object]]]
class nemo_gym.openai_utils.PermanentEndpointError()

Bases: ClientResponseError

The upstream key is spent or unauthorized; further calls on this client skip the wire.

class nemo_gym.openai_utils.TokenIDLogProbMixin()

Bases: BaseModel

generation_log_probs
List[float]
generation_token_ids
List[int]
prompt_token_ids
List[int]
routed_experts
Optional[RoutedExperts] = None
class nemo_gym.openai_utils.TokenIDLogProbTypedDictMixin

Bases: typing.TypedDict

generation_log_probs
List[float]
generation_token_ids
List[int]
prompt_token_ids
List[int]
routed_experts
NotRequired[RoutedExperts]
nemo_gym.openai_utils._add_optional_token_counts(
left: typing.Optional[int],
right: typing.Optional[int]
) -> typing.Optional[int]

Add reported token counts without turning an unknown count into a measurement.

nemo_gym.openai_utils._decode_error_text(
content: bytes | str
) -> str
nemo_gym.openai_utils._discriminate_message_item(
value: typing.Dict[str, typing.Any]
) -> str

Choose a message model from its role, content, and status.

nemo_gym.openai_utils._discriminate_response_input_item(
value: typing.Any
) -> typing.Optional[str]

Pick the input union tag for a request item.

nemo_gym.openai_utils._discriminate_response_output_item(
value: typing.Any
) -> typing.Optional[str]

Pick the output union tag for a response item.

nemo_gym.openai_utils._discriminate_untyped_input_item(
value: typing.Dict[str, typing.Any]
) -> str

Infer a typeless input model or use the permissive fallback.

nemo_gym.openai_utils._error_body_is_permanent_auth(
content: bytes | str
) -> bool

True when a 401/403 body is a revoked or invalid key, not a one-off denial.

nemo_gym.openai_utils._error_body_is_permanent_quota(
content: bytes | str
) -> bool

True when a 429 body is a spent key, not a transient rate limit.

nemo_gym.openai_utils._first_content_part_type(
content: typing.Any
) -> typing.Optional[str]

Return the type of the first content part, or None for empty or non-list content.

nemo_gym.openai_utils._normalize_output_item_for_replay(
item: typing.Any
) -> typing.Any

Convert a provider output item for request replay.

nemo_gym.openai_utils._normalize_tool_for_replay(
tool: typing.Any
) -> typing.Any

Convert a provider response tool for request replay.

nemo_gym.openai_utils._parsed_error_codes(
content: bytes | str
) -> list[str]

error.code / error.type tokens from an OpenAI-style error body.

nemo_gym.openai_utils._register_item_tags(
item_union: typing.Any,
tag_by_class: typing.Dict[type, str]
) -> None

Index each union member class by its Tag, so instances discriminate by class.

nemo_gym.openai_utils._require_response_output_item_type(
value: typing.Any
) -> typing.Any

Prevent an untagged output item from being coerced into the wrong union member.

nemo_gym.openai_utils._strip_outer_tool_call_names(
value: typing.Any
) -> typing.Any

Copy tool calls carrying a redundant outer name and remove only that field.

nemo_gym.openai_utils._tag_for_item_instance(
value: typing.Any,
tag_by_class: typing.Dict[type, str]
) -> typing.Optional[str]

Map an item instance to its nearest registered class tag.

nemo_gym.openai_utils._training_variant_tag(
tag: str,
value: typing.Dict[str, typing.Any]
) -> str

Route to the ForTraining member when the item carries complete token metadata.

nemo_gym.openai_utils._validate_atomic_token_metadata(
value: typing.Any
) -> typing.Any

Require complete token metadata when any token field is present.

nemo_gym.openai_utils._validate_input_video_part(
value: typing.Any
) -> typing.Any

Require one non-empty source without changing the TypedDict representation.

nemo_gym.openai_utils.accumulate_response_usage(
additional: typing.Optional[nemo_gym.openai_utils.NeMoGymResponseUsage]

Accumulate top-level and detailed response token counts.

nemo_gym.openai_utils.training_variant_of(
item_cls: type
) -> type

Return the ForTraining subclass that carries token IDs for item_cls.

Raises NotImplementedError rather than KeyError, so the message can name the class and the fix. Either register the pair in RESPONSES_TO_TRAIN, or stop attaching token IDs to that item.

nemo_gym.openai_utils.CHAT_REQUEST_IGNORED_CLIENT_FIELDS = frozenset({'aws_region_name'})
nemo_gym.openai_utils.CHAT_REQUEST_PROVIDER_EXTENSION_FIELDS = frozenset({'chat_template_kwargs', 'thinking', 'output_config'})
nemo_gym.openai_utils.NeMoGymChatCompletionContentPartParam = Union[NeMoGymChatCompletionContentPartTextParam, NeMoGymChatCompletionContentPar...
nemo_gym.openai_utils.NeMoGymChatCompletionMessageParam: TypeAlias = Annotated[Union[NeMoGymChatCompletionDeveloperMessageParam, NeMoGymChatCompletio...
nemo_gym.openai_utils.NeMoGymChatCompletionMessageToolCallUnion = Annotated[Union[NeMoGymChatCompletionMessageToolCall, NeMoGymChatCompletionMessa...
nemo_gym.openai_utils.NeMoGymChatCompletionMessageToolCallUnionParam = Annotated[Union[NeMoGymChatCompletionMessageToolCallParam, NeMoGymChatCompletion...
nemo_gym.openai_utils.NeMoGymChatCompletionMessageToolCallsParam: TypeAlias = Annotated[List[NeMoGymChatCompletionMessageToolCallUnionParam], BeforeValidator(...
nemo_gym.openai_utils.NeMoGymChatCompletionOutputMessage: TypeAlias = Annotated[Union[NeMoGymChatCompletionMessage, NeMoGymChatCompletionMessageForTra...
nemo_gym.openai_utils.NeMoGymChatCompletionToolChoiceOptionParam: TypeAlias = Union[Literal['none', 'auto', 'required'], NeMoGymChatCompletionAllowedToolChoic...
nemo_gym.openai_utils.NeMoGymChatCompletionToolUnionParam = Annotated[Union[NeMoGymChatCompletionToolParam, NeMoGymChatCompletionCustomToolP...
nemo_gym.openai_utils.NeMoGymContainerNetworkPolicyParam: TypeAlias = Union[ContainerNetworkPolicyDisabledParam, NeMoGymContainerNetworkPolicyAllowlis...
nemo_gym.openai_utils.NeMoGymContent: TypeAlias = Union[NeMoGymResponseOutputText, NeMoGymResponseOutputRefusal]
nemo_gym.openai_utils.NeMoGymResponseInput: TypeAlias = List[NeMoGymResponseInputItem]
nemo_gym.openai_utils.NeMoGymResponseInputContentList: TypeAlias = List[NeMoGymResponseInputContentPart]
nemo_gym.openai_utils.NeMoGymResponseInputContentPart: TypeAlias = Annotated[Union[ResponseInputContentParam, NeMoGymInputVideoPart], BeforeValidat...
nemo_gym.openai_utils.NeMoGymResponseInputItem = Annotated[Union[Annotated[NeMoGymEasyInputMessage, Tag('easy_message')], Annotat...
nemo_gym.openai_utils.NeMoGymResponseOutputItem = Annotated[Union[Annotated[NeMoGymResponseOutputMessage, Tag('output_message')], ...
nemo_gym.openai_utils.NeMoGymToolChoice: TypeAlias = Union[ToolChoiceOptions, NeMoGymToolChoiceAllowedParam, ToolChoiceTypesParam, To...
nemo_gym.openai_utils.NeMoGymToolParam: TypeAlias = Union[FunctionToolParam, NeMoGymFileSearchToolParam, ComputerToolParam, Computer...
nemo_gym.openai_utils.PERMANENT_AUTH_CODES = ('invalid_api_key', 'invalid_api_token', 'authentication_error')
nemo_gym.openai_utils.PERMANENT_QUOTA_CODES = ('budget_exceeded', 'insufficient_quota')
nemo_gym.openai_utils.RATE_LIMIT_ERROR_CODES = [429, 502, 503, 504, 520]
nemo_gym.openai_utils.REQUIRED_TOKEN_METADATA_FIELDS = frozenset({'prompt_token_ids', 'generation_token_ids', 'generation_log_probs'})
nemo_gym.openai_utils.RESPONSES_TO_TRAIN = {NeMoGymEasyInputMessage: NeMoGymEasyInputMessageForTraining, NeMoGymMessage: Ne...
nemo_gym.openai_utils.RETRY_ERROR_CODES = RATE_LIMIT_ERROR_CODES + [404, 408, 500]
nemo_gym.openai_utils.RoutedExperts: TypeAlias = Union[str, List[List[List[int]]]]
nemo_gym.openai_utils.TOKEN_METADATA_FIELDS = REQUIRED_TOKEN_METADATA_FIELDS | {'routed_experts'}
nemo_gym.openai_utils._ITEM_STATUSES = frozenset({'in_progress', 'completed', 'incomplete'})
nemo_gym.openai_utils._MESSAGE_ROLES = _SIMPLE_MESSAGE_ROLES | {'assistant'}
nemo_gym.openai_utils._OUTPUT_CONTENT_PART_TYPES = frozenset({'output_text', 'refusal'})
nemo_gym.openai_utils._RESPONSE_INPUT_ITEM_TAG_BY_CLASS: Dict[type, str] = {}
nemo_gym.openai_utils._RESPONSE_OUTPUT_ITEM_TAG_BY_CLASS: Dict[type, str] = {}
nemo_gym.openai_utils._SIMPLE_MESSAGE_ROLES = frozenset({'user', 'system', 'developer'})
nemo_gym.openai_utils._TRAINABLE_ITEM_TAGS = frozenset({'easy_message', 'input_message', 'output_message', 'function_call', '...
nemo_gym.openai_utils._TRAINING_TAG_SUFFIX = '__training'