8787 pytest .mark .skipif (not imports_successful (), reason = 'openai not installed' ),
8888 pytest .mark .anyio ,
8989 pytest .mark .vcr ,
90+ # TODO(Marcelo): genai-prices needs to include Cerebras prices: https://github.com/pydantic/genai-prices/issues/132
91+ pytest .mark .filterwarnings ('ignore:The costs with provider "cerebras" and model:UserWarning' ),
92+ # NOTE(Marcelo): The following model is old, so we are probably not including it on `genai-prices`.
93+ pytest .mark .filterwarnings (
94+ 'ignore:The costs with provider "openai" and model "gpt-4o-search-preview-2025-03-11":UserWarning'
95+ ),
9096]
9197
9298
@@ -120,15 +126,15 @@ async def test_request_simple_success(allow_model_requests: None):
120126 ModelRequest (parts = [UserPromptPart (content = 'hello' , timestamp = IsNow (tz = timezone .utc ))]),
121127 ModelResponse (
122128 parts = [TextPart (content = 'world' )],
123- model_name = 'gpt-4o-123 ' ,
129+ model_name = 'gpt-4o' ,
124130 timestamp = datetime (2024 , 1 , 1 , 0 , 0 , tzinfo = timezone .utc ),
125131 provider_name = 'openai' ,
126132 provider_request_id = '123' ,
127133 ),
128134 ModelRequest (parts = [UserPromptPart (content = 'hello' , timestamp = IsNow (tz = timezone .utc ))]),
129135 ModelResponse (
130136 parts = [TextPart (content = 'world' )],
131- model_name = 'gpt-4o-123 ' ,
137+ model_name = 'gpt-4o' ,
132138 timestamp = datetime (2024 , 1 , 1 , 0 , 0 , tzinfo = timezone .utc ),
133139 provider_name = 'openai' ,
134140 provider_request_id = '123' ,
@@ -155,18 +161,28 @@ async def test_request_simple_success(allow_model_requests: None):
155161 ]
156162
157163
158- async def test_request_simple_usage (allow_model_requests : None ):
159- c = completion_message (
160- ChatCompletionMessage (content = 'world' , role = 'assistant' ),
161- usage = CompletionUsage (completion_tokens = 1 , prompt_tokens = 2 , total_tokens = 3 ),
162- )
163- mock_client = MockOpenAI .create_mock (c )
164- m = OpenAIChatModel ('gpt-4o' , provider = OpenAIProvider (openai_client = mock_client ))
164+ async def test_request_simple_usage (allow_model_requests : None , openai_api_key : str ):
165+ m = OpenAIChatModel ('gpt-4o' , provider = OpenAIProvider (api_key = openai_api_key ))
165166 agent = Agent (m )
166167
167- result = await agent .run ('Hello' )
168- assert result .output == 'world'
169- assert result .usage () == snapshot (RunUsage (requests = 1 , input_tokens = 2 , output_tokens = 1 ))
168+ result = await agent .run ('Hello! How are you doing?' )
169+ assert result .output == snapshot (
170+ "Hello! I'm just a computer program, so I don't have feelings, but I'm here and ready to help you. How can I assist you today?"
171+ )
172+ assert result .usage () == snapshot (
173+ RunUsage (
174+ requests = 1 ,
175+ input_tokens = 14 ,
176+ details = {
177+ 'accepted_prediction_tokens' : 0 ,
178+ 'audio_tokens' : 0 ,
179+ 'reasoning_tokens' : 0 ,
180+ 'rejected_prediction_tokens' : 0 ,
181+ },
182+ output_tokens = 30 ,
183+ cost = Decimal ('0.000335' ),
184+ )
185+ )
170186
171187
172188async def test_request_structured_response (allow_model_requests : None ):
@@ -200,7 +216,7 @@ async def test_request_structured_response(allow_model_requests: None):
200216 tool_call_id = '123' ,
201217 )
202218 ],
203- model_name = 'gpt-4o-123 ' ,
219+ model_name = 'gpt-4o' ,
204220 timestamp = datetime (2024 , 1 , 1 , tzinfo = timezone .utc ),
205221 provider_name = 'openai' ,
206222 provider_request_id = '123' ,
@@ -295,7 +311,7 @@ async def get_location(loc_name: str) -> str:
295311 cache_read_tokens = 1 ,
296312 output_tokens = 1 ,
297313 ),
298- model_name = 'gpt-4o-123 ' ,
314+ model_name = 'gpt-4o' ,
299315 timestamp = datetime (2024 , 1 , 1 , tzinfo = timezone .utc ),
300316 provider_name = 'openai' ,
301317 provider_request_id = '123' ,
@@ -323,7 +339,7 @@ async def get_location(loc_name: str) -> str:
323339 cache_read_tokens = 2 ,
324340 output_tokens = 2 ,
325341 ),
326- model_name = 'gpt-4o-123 ' ,
342+ model_name = 'gpt-4o' ,
327343 timestamp = datetime (2024 , 1 , 1 , tzinfo = timezone .utc ),
328344 provider_name = 'openai' ,
329345 provider_request_id = '123' ,
@@ -340,14 +356,16 @@ async def get_location(loc_name: str) -> str:
340356 ),
341357 ModelResponse (
342358 parts = [TextPart (content = 'final response' )],
343- model_name = 'gpt-4o-123 ' ,
359+ model_name = 'gpt-4o' ,
344360 timestamp = datetime (2024 , 1 , 1 , tzinfo = timezone .utc ),
345361 provider_name = 'openai' ,
346362 provider_request_id = '123' ,
347363 ),
348364 ]
349365 )
350- assert result .usage () == snapshot (RunUsage (requests = 3 , cache_read_tokens = 3 , input_tokens = 5 , output_tokens = 3 ))
366+ assert result .usage () == snapshot (
367+ RunUsage (requests = 3 , cache_read_tokens = 3 , input_tokens = 5 , output_tokens = 3 , cost = Decimal ('0.00004625' ))
368+ )
351369
352370
353371FinishReason = Literal ['stop' , 'length' , 'tool_calls' , 'content_filter' , 'function_call' ]
@@ -2273,6 +2291,8 @@ def test_model_profile_strict_not_supported():
22732291 )
22742292
22752293
2294+ # NOTE(Marcelo): You wouldn't do this because you'd use the GoogleModel. I'm unsure if this test brings any value.
2295+ @pytest .mark .filterwarnings ('ignore:The costs with provider "openai" and model "gemini-2.5-pro:UserWarning' )
22762296async def test_compatible_api_with_tool_calls_without_id (allow_model_requests : None , gemini_api_key : str ):
22772297 provider = OpenAIProvider (
22782298 openai_client = AsyncOpenAI (
0 commit comments