OpenResponses Types

2.3.0.post1 · active · verified Fri Apr 17

The `openresponses-types` library provides a Python SDK for the OpenResponses specification, offering standardized data types and models for structured interactions, particularly for AI agents. It leverages Pydantic for robust data validation, serialization, and deserialization of response and prompt structures. The current version is 2.3.0.post1, with releases aligning with updates to the underlying OpenResponses specification.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create an `AgentResponse` containing a `ChatMLMessage`, embed it within an `OpenResponse`, and then serialize and deserialize the entire structure using Pydantic's V2 methods.

from openresponses.types import AgentResponse, OpenResponse
from openresponses.types.model import ChatMLMessage

# Create an AgentResponse
agent_msg = ChatMLMessage(role="assistant", content="Hello, how can I help you?")
agent_response = AgentResponse(
    model_name="gpt-4",
    messages=[agent_msg]
)

# Create an OpenResponse containing the agent's response
open_response = OpenResponse(
    response=agent_response,
    prompt_hash="example_hash_123"
)

# Print the OpenResponse object (serialized to JSON)
print("OpenResponse object created:")
print(open_response.model_dump_json(indent=2))

# Example of deserialization from JSON string
json_data = open_response.model_dump_json()
reconstructed_response = OpenResponse.model_validate_json(json_data)
print("\nOpenResponse object deserialized:")
print(reconstructed_response.model_dump_json(indent=2))

view raw JSON →