diff --git a/README.md b/README.md index e7ba39f5d1..117aa0b342 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ client = OpenAI( ) response = client.responses.create( - model="gpt-5.5", + model="gpt-6.2-sol", instructions="You are a coding assistant that talks like a pirate.", input="How do I check if a Python object is an instance of a class?", ) @@ -44,27 +44,6 @@ response = client.responses.create( print(response.output_text) ``` -The previous standard (supported indefinitely) for generating text is the [Chat Completions API](https://platform.openai.com/docs/api-reference/chat). You can use that API to generate text from the model with the code below. - -```python -from openai import OpenAI - -client = OpenAI() - -completion = client.chat.completions.create( - model="gpt-5.5", - messages=[ - {"role": "developer", "content": "Talk like a pirate."}, - { - "role": "user", - "content": "How do I check if a Python object is an instance of a class?", - }, - ], -) - -print(completion.choices[0].message.content) -``` - While you can provide an `api_key` keyword argument, we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/) to add `OPENAI_API_KEY="My API Key"` to your `.env` file @@ -89,9 +68,9 @@ client = OpenAI( }, ) -response = client.chat.completions.create( - model="gpt-5.5", - messages=[{"role": "user", "content": "Hello!"}], +response = client.responses.create( + model="gpt-6.2-sol", + input="Hello!", ) ``` @@ -233,7 +212,7 @@ prompt = "What is in this image?" img_url = "https://api.nga.gov/iiif/a2e6da57-3cd1-4235-b20e-95dcaefed6c8/full/!800,800/0/default.jpg" response = client.responses.create( - model="gpt-5.5", + model="gpt-6.2-sol", input=[ { "role": "user", @@ -259,7 +238,7 @@ with open("path/to/image.png", "rb") as image_file: b64_image = base64.b64encode(image_file.read()).decode("utf-8") response = client.responses.create( - model="gpt-5.5", + model="gpt-6.2-sol", input=[ { "role": "user", @@ -289,7 +268,7 @@ client = AsyncOpenAI( async def main() -> None: response = await client.responses.create( - model="gpt-5.5", input="Explain disestablishmentarianism to a smart five year old." + model="gpt-6.2-sol", input="Explain disestablishmentarianism to a smart five year old." ) print(response.output_text) @@ -324,15 +303,11 @@ async def main() -> None: api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted http_client=DefaultAioHttpClient(), ) as client: - chat_completion = await client.chat.completions.create( - messages=[ - { - "role": "user", - "content": "Say this is a test", - } - ], - model="gpt-5.5", + response = await client.responses.create( + model="gpt-6.2-sol", + input="Say this is a test", ) + print(response.output_text) asyncio.run(main()) @@ -352,7 +327,7 @@ from openai import OpenAI client = OpenAI() stream = client.responses.create( - model="gpt-5.5", + model="gpt-6.2-sol", input="Write a one-sentence bedtime story about a unicorn.", stream=True, ) @@ -372,7 +347,7 @@ client = AsyncOpenAI() async def main(): stream = await client.responses.create( - model="gpt-5.5", + model="gpt-6.2-sol", input="Write a one-sentence bedtime story about a unicorn.", stream=True, ) @@ -552,10 +527,10 @@ response = client.responses.create( input=[ { "role": "user", - "content": "How much ?", + "content": "Return the price of a $12 item after a 25% discount as a JSON object.", } ], - model="gpt-5.5", + model="gpt-6.2-sol", text={"format": {"type": "json_object"}}, ) ``` @@ -734,7 +709,7 @@ All object responses in the SDK provide a `_request_id` property which is added ```python response = await client.responses.create( - model="gpt-5.5", + model="gpt-6.2-sol", input="Say 'this is a test'.", ) print(response._request_id) # req_123 @@ -751,8 +726,9 @@ methods and modules are _private_. import openai try: - completion = await client.chat.completions.create( - messages=[{"role": "user", "content": "Say this is a test"}], model="gpt-5.5" + response = await client.responses.create( + model="gpt-6.2-sol", + input="Say this is a test", ) except openai.APIStatusError as exc: print(exc.request_id) # req_123 @@ -779,14 +755,9 @@ client = OpenAI( ) # Or, configure per-request: -client.with_options(max_retries=5).chat.completions.create( - messages=[ - { - "role": "user", - "content": "How can I get the name of the current day in JavaScript?", - } - ], - model="gpt-5.5", +client.with_options(max_retries=5).responses.create( + model="gpt-6.2-sol", + input="How can I get the name of the current day in JavaScript?", ) ``` @@ -818,14 +789,9 @@ client = OpenAI( ) # Override per-request: -client.with_options(timeout=5.0).chat.completions.create( - messages=[ - { - "role": "user", - "content": "How can I list all files in a directory using Python?", - } - ], - model="gpt-5.5", +client.with_options(timeout=5.0).responses.create( + model="gpt-6.2-sol", + input="How can I list all files in a directory using Python?", ) ``` @@ -869,19 +835,14 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to from openai import OpenAI client = OpenAI() -response = client.chat.completions.with_raw_response.create( - messages=[ - { - "role": "user", - "content": "Say this is a test", - } - ], - model="gpt-5.5", +raw_response = client.responses.with_raw_response.create( + model="gpt-6.2-sol", + input="Say this is a test", ) -print(response.headers.get("X-My-Header")) +print(raw_response.headers.get("X-My-Header")) -completion = response.parse() # get the object that `chat.completions.create()` would have returned -print(completion) +response = raw_response.parse() # get the object that `responses.create()` would have returned +print(response.output_text) ``` These methods return a [`LegacyAPIResponse`](https://github.com/openai/openai-python/tree/main/src/openai/_legacy_response.py) object. This is a legacy class as we're changing it slightly in the next major version. @@ -902,14 +863,9 @@ To stream the response body, use `.with_streaming_response` instead, which requi As such, `.with_streaming_response` methods return a different [`APIResponse`](https://github.com/openai/openai-python/tree/main/src/openai/_response.py) object, and the async client returns an [`AsyncAPIResponse`](https://github.com/openai/openai-python/tree/main/src/openai/_response.py) object. ```python -with client.chat.completions.with_streaming_response.create( - messages=[ - { - "role": "user", - "content": "Say this is a test", - } - ], - model="gpt-5.5", +with client.responses.with_streaming_response.create( + model="gpt-6.2-sol", + input="Say this is a test", ) as response: print(response.headers.get("X-My-Header")) @@ -1105,7 +1061,7 @@ from openai import AsyncOpenAI async def main() -> None: async with AsyncOpenAI() as client: - response = await client.responses.create(model="gpt-5.5", input="Say this is a test") + response = await client.responses.create(model="gpt-6.2-sol", input="Say this is a test") print(response.output_text) @@ -1114,37 +1070,26 @@ asyncio.run(main()) ## Microsoft Azure OpenAI -To use this library with [Azure OpenAI](https://learn.microsoft.com/azure/ai-services/openai/overview), use the `AzureOpenAI` -class instead of the `OpenAI` class. - -> [!IMPORTANT] -> The Azure API shape differs from the core API shape which means that the static types for responses / params -> won't always be correct. +To use the [Azure OpenAI Responses API](https://learn.microsoft.com/azure/ai-foundry/openai/how-to/responses), +configure the `OpenAI` client with your Azure v1 endpoint and pass your deployment name as `model`. ```py -from openai import AzureOpenAI - -# gets the API Key from environment variable AZURE_OPENAI_API_KEY -client = AzureOpenAI( - # https://learn.microsoft.com/azure/ai-services/openai/reference#rest-api-versioning - api_version="2023-07-01-preview", - # https://learn.microsoft.com/azure/cognitive-services/openai/how-to/create-resource?pivots=web-portal#create-a-resource - azure_endpoint="https://example-endpoint.openai.azure.com", +import os +from openai import OpenAI + +client = OpenAI( + api_key=os.environ["AZURE_OPENAI_API_KEY"], + base_url="https://example-endpoint.openai.azure.com/openai/v1/", ) -completion = client.chat.completions.create( - model="deployment-name", # e.g. gpt-35-instant - messages=[ - { - "role": "user", - "content": "How do I output all files in a directory using Python?", - }, - ], +response = client.responses.create( + model="deployment-name", + input="How do I output all files in a directory using Python?", ) -print(completion.to_json()) +print(response.output_text) ``` -In addition to the options provided in the base `OpenAI` client, the following options are provided: +For versioned Azure endpoints, the `AzureOpenAI` client supports these additional options: - `azure_endpoint` (or the `AZURE_OPENAI_ENDPOINT` environment variable) - `azure_deployment` @@ -1152,8 +1097,6 @@ In addition to the options provided in the base `OpenAI` client, the following o - `azure_ad_token` (or the `AZURE_OPENAI_AD_TOKEN` environment variable) - `azure_ad_token_provider` -An example of using the client with Microsoft Entra ID (formerly known as Azure Active Directory) can be found [here](https://github.com/openai/openai-python/blob/main/examples/azure_ad.py). - ## Amazon Bedrock To use this library with [Amazon Bedrock's OpenAI-compatible API](https://docs.aws.amazon.com/bedrock/latest/userguide/models-api-compatibility.html), configure the standard `OpenAI` client with the Bedrock provider. diff --git a/examples/async_demo.py b/examples/async_demo.py index 1ee18c3d4b..c4f0de228f 100755 --- a/examples/async_demo.py +++ b/examples/async_demo.py @@ -10,7 +10,7 @@ async def main() -> None: stream = await client.chat.completions.create( - model="gpt-5.5", + model="gpt-6.2-sol", messages=[ { "role": "user", diff --git a/examples/demo.py b/examples/demo.py index 8cd45653a3..068a9da114 100755 --- a/examples/demo.py +++ b/examples/demo.py @@ -9,7 +9,7 @@ # Non-streaming: print("----- standard request -----") completion = client.chat.completions.create( - model="gpt-5.5", + model="gpt-6.2-sol", messages=[ { "role": "user", @@ -22,7 +22,7 @@ # Streaming: print("----- streaming request -----") stream = client.chat.completions.create( - model="gpt-5.5", + model="gpt-6.2-sol", messages=[ { "role": "user", @@ -41,7 +41,7 @@ # Response headers: print("----- custom response headers test -----") response = client.chat.completions.with_raw_response.create( - model="gpt-5.5", + model="gpt-6.2-sol", messages=[ { "role": "user", diff --git a/examples/httpx2_client.py b/examples/httpx2_client.py index eb4ab08f87..2126bf0354 100644 --- a/examples/httpx2_client.py +++ b/examples/httpx2_client.py @@ -3,7 +3,7 @@ client = OpenAI(http_client=DefaultHttpx2Client()) response = client.responses.create( - model="gpt-5.2", + model="gpt-6.2-sol", input="Say this is a test", ) diff --git a/examples/module_client.py b/examples/module_client.py index aac0701bf9..57e9983fd2 100755 --- a/examples/module_client.py +++ b/examples/module_client.py @@ -9,7 +9,7 @@ # all API calls work in the exact same fashion as well stream = openai.chat.completions.create( - model="gpt-5.6", + model="gpt-6.2-sol", messages=[ { "role": "user", diff --git a/examples/parsing.py b/examples/parsing.py index 906ce974c1..322ebda65a 100644 --- a/examples/parsing.py +++ b/examples/parsing.py @@ -19,7 +19,7 @@ class MathResponse(BaseModel): client = OpenAI() completion = client.chat.completions.parse( - model="gpt-4o-2024-08-06", + model="gpt-6.2-sol", messages=[ {"role": "system", "content": "You are a helpful math tutor."}, {"role": "user", "content": "solve 8x + 31 = 2"}, diff --git a/examples/parsing_stream.py b/examples/parsing_stream.py index 1be7853098..9b0cb576e5 100644 --- a/examples/parsing_stream.py +++ b/examples/parsing_stream.py @@ -19,7 +19,7 @@ class MathResponse(BaseModel): client = OpenAI() with client.chat.completions.stream( - model="gpt-4o-2024-08-06", + model="gpt-6.2-sol", messages=[ {"role": "system", "content": "You are a helpful math tutor."}, {"role": "user", "content": "solve 8x + 31 = 2"}, diff --git a/examples/responses/background.py b/examples/responses/background.py index 37b00f19be..3760515d6f 100644 --- a/examples/responses/background.py +++ b/examples/responses/background.py @@ -21,7 +21,7 @@ class MathResponse(BaseModel): with client.responses.create( input="solve 8x + 31 = 2", - model="gpt-4o-2024-08-06", + model="gpt-6.2-sol", background=True, stream=True, ) as stream: diff --git a/examples/responses/background_async.py b/examples/responses/background_async.py index 9dbc78b784..e439fc1b0e 100644 --- a/examples/responses/background_async.py +++ b/examples/responses/background_async.py @@ -23,7 +23,7 @@ async def main() -> None: async with await client.responses.create( input="solve 8x + 31 = 2", - model="gpt-4o-2024-08-06", + model="gpt-6.2-sol", background=True, stream=True, ) as stream: diff --git a/examples/responses/background_streaming.py b/examples/responses/background_streaming.py index 483803bbd4..284a365cbe 100755 --- a/examples/responses/background_streaming.py +++ b/examples/responses/background_streaming.py @@ -21,7 +21,7 @@ class MathResponse(BaseModel): id = None with client.responses.stream( input="solve 8x + 31 = 2", - model="gpt-4o-2024-08-06", + model="gpt-6.2-sol", text_format=MathResponse, background=True, ) as stream: diff --git a/examples/responses/background_streaming_async.py b/examples/responses/background_streaming_async.py index 178150dc15..8bcd0427a4 100644 --- a/examples/responses/background_streaming_async.py +++ b/examples/responses/background_streaming_async.py @@ -22,7 +22,7 @@ async def main() -> None: id = None async with client.responses.stream( input="solve 8x + 31 = 2", - model="gpt-4o-2024-08-06", + model="gpt-6.2-sol", text_format=MathResponse, background=True, ) as stream: diff --git a/examples/responses/multi_agent_streaming.py b/examples/responses/multi_agent_streaming.py index 5933e75357..ff10d2093b 100644 --- a/examples/responses/multi_agent_streaming.py +++ b/examples/responses/multi_agent_streaming.py @@ -16,7 +16,7 @@ def agent_name(item: BetaResponseOutputItem) -> str: client = OpenAI() stream = client.beta.responses.create( - model="gpt-5.6-sol", + model="gpt-6.2-sol", input=PROMPT, multi_agent={"enabled": True}, stream=True, diff --git a/examples/responses/multi_agent_websocket.py b/examples/responses/multi_agent_websocket.py index cb7d990fbd..a33aeac174 100644 --- a/examples/responses/multi_agent_websocket.py +++ b/examples/responses/multi_agent_websocket.py @@ -21,7 +21,7 @@ def agent_name(item: BetaResponseOutputItem) -> str: connection.send( { "type": "response.create", - "model": "gpt-5.6-sol", + "model": "gpt-6.2-sol", "input": PROMPT, "multi_agent": {"enabled": True}, } diff --git a/examples/responses/streaming.py b/examples/responses/streaming.py index 39787968d6..047a0ad7fa 100644 --- a/examples/responses/streaming.py +++ b/examples/responses/streaming.py @@ -20,7 +20,7 @@ class MathResponse(BaseModel): with client.responses.stream( input="solve 8x + 31 = 2", - model="gpt-4o-2024-08-06", + model="gpt-6.2-sol", text_format=MathResponse, ) as stream: for event in stream: diff --git a/examples/responses/streaming_tools.py b/examples/responses/streaming_tools.py index f40cd9356d..21ce753a78 100644 --- a/examples/responses/streaming_tools.py +++ b/examples/responses/streaming_tools.py @@ -58,7 +58,7 @@ class Query(BaseModel): client = OpenAI() with client.responses.stream( - model="gpt-4o-2024-08-06", + model="gpt-6.2-sol", input="look up all my orders in november of last year that were fulfilled but not delivered on time", tools=[ openai.pydantic_function_tool(Query), diff --git a/examples/responses/structured_outputs.py b/examples/responses/structured_outputs.py index 0b146bc0bc..441941eca8 100644 --- a/examples/responses/structured_outputs.py +++ b/examples/responses/structured_outputs.py @@ -20,13 +20,13 @@ class MathResponse(BaseModel): rsp = client.responses.parse( input="solve 8x + 31 = 2", - model="gpt-4o-2024-08-06", + model="gpt-6.2-sol", text_format=MathResponse, ) for output in rsp.output: if output.type != "message": - raise Exception("Unexpected non message") + continue for item in output.content: if item.type != "output_text": @@ -41,8 +41,7 @@ class MathResponse(BaseModel): # or -message = rsp.output[0] -assert message.type == "message" +message = next(output for output in rsp.output if output.type == "message") text = message.content[0] assert text.type == "output_text" diff --git a/examples/responses/structured_outputs_tools.py b/examples/responses/structured_outputs_tools.py index 918348207d..6717da05fe 100644 --- a/examples/responses/structured_outputs_tools.py +++ b/examples/responses/structured_outputs_tools.py @@ -58,7 +58,7 @@ class Query(BaseModel): client = OpenAI() response = client.responses.parse( - model="gpt-4o-2024-08-06", + model="gpt-6.2-sol", input="look up all my orders in november of last year that were fulfilled but not delivered on time", tools=[ openai.pydantic_function_tool(Query), @@ -67,7 +67,6 @@ class Query(BaseModel): rich.print(response) -function_call = response.output[0] -assert function_call.type == "function_call" +function_call = next(output for output in response.output if output.type == "function_call") assert isinstance(function_call.parsed_arguments, Query) print("table name:", function_call.parsed_arguments.table_name) diff --git a/examples/responses/websocket.py b/examples/responses/websocket.py index 8765762f02..8227b61e3f 100644 --- a/examples/responses/websocket.py +++ b/examples/responses/websocket.py @@ -166,7 +166,7 @@ def parse_args() -> argparse.Namespace: parser = argparse.ArgumentParser( description=("Run a 3-turn Responses WebSocket demo with function calling and chained previous_response_id.") ) - parser.add_argument("--model", default="gpt-5.2", help="Model used in the `response.create` payload.") + parser.add_argument("--model", default="gpt-6.2-sol", help="Model used in the `response.create` payload.") parser.add_argument( "--use-beta-header", action="store_true", diff --git a/examples/responses_input_tokens.py b/examples/responses_input_tokens.py index 39809b928f..0a696ec102 100644 --- a/examples/responses_input_tokens.py +++ b/examples/responses_input_tokens.py @@ -41,7 +41,7 @@ def main() -> None: ] response = client.responses.input_tokens.count( - model="gpt-5", + model="gpt-6.2-sol", instructions="You are a concise assistant.", input=input_items, tools=tools, diff --git a/examples/responses_websocket.py b/examples/responses_websocket.py index 1016eb36a2..f487f556ee 100644 --- a/examples/responses_websocket.py +++ b/examples/responses_websocket.py @@ -22,13 +22,13 @@ def main() -> None: ResponsesWebSocketSession(connection, limits=limits) as session, ): lane = session.lane("example") - lane.send({"type": "response.create", "model": "gpt-4o-mini", "input": "Say hello."}) + lane.send({"type": "response.create", "model": "gpt-6.2-sol", "input": "Say hello."}) response = lane.get_final_response(timeout=60) print(response.id, response.status) lane.send( { "type": "response.create", - "model": "gpt-4o-mini", + "model": "gpt-6.2-sol", "previous_response_id": response.id, "input": "Now say goodbye.", } diff --git a/examples/streaming.py b/examples/streaming.py index 30ea11a49d..936416818f 100755 --- a/examples/streaming.py +++ b/examples/streaming.py @@ -13,7 +13,7 @@ def sync_main() -> None: client = OpenAI() response = client.chat.completions.create( - model="gpt-5.5", + model="gpt-6.2-sol", messages=[ { "role": "user", @@ -36,7 +36,7 @@ def sync_main() -> None: async def async_main() -> None: client = AsyncOpenAI() response = await client.chat.completions.create( - model="gpt-5.5", + model="gpt-6.2-sol", messages=[ { "role": "user", diff --git a/examples/x509_workload_identity.py b/examples/x509_workload_identity.py index abf2d38697..04127b8599 100644 --- a/examples/x509_workload_identity.py +++ b/examples/x509_workload_identity.py @@ -33,7 +33,7 @@ def create_client() -> OpenAI: def main() -> None: with create_client() as client: - response = client.responses.create(model="gpt-5.5", input="Hello!") + response = client.responses.create(model="gpt-6.2-sol", input="Hello!") print(response.output_text) diff --git a/examples/x509_workload_identity_async.py b/examples/x509_workload_identity_async.py index da5529a4d8..d05f98f600 100644 --- a/examples/x509_workload_identity_async.py +++ b/examples/x509_workload_identity_async.py @@ -34,7 +34,7 @@ def create_client() -> AsyncOpenAI: async def main() -> None: async with create_client() as client: - response = await client.responses.create(model="gpt-5.5", input="Hello!") + response = await client.responses.create(model="gpt-6.2-sol", input="Hello!") print(response.output_text) diff --git a/helpers.md b/helpers.md index 8be574b2ce..e3ce761822 100644 --- a/helpers.md +++ b/helpers.md @@ -28,7 +28,7 @@ class MathResponse(BaseModel): client = OpenAI() completion = client.chat.completions.parse( - model="gpt-4o-2024-08-06", + model="gpt-6.2-sol", messages=[ {"role": "system", "content": "You are a helpful math tutor."}, {"role": "user", "content": "solve 8x + 31 = 2"}, @@ -210,7 +210,7 @@ from openai import AsyncOpenAI client = AsyncOpenAI() async with client.chat.completions.stream( - model="gpt-4o-2024-08-06", + model="gpt-6.2-sol", messages=[...], ) as stream: async for event in stream: diff --git a/httpx2.md b/httpx2.md index 044be5a533..1424a80fcc 100644 --- a/httpx2.md +++ b/httpx2.md @@ -16,7 +16,7 @@ timeouts continue to work: from openai import OpenAI client = OpenAI(timeout=30.0) -response = client.responses.create(model="gpt-5.5", input="Hello") +response = client.responses.create(model="gpt-6.2-sol", input="Hello") ``` No HTTPX2 extra or separate installation is required: