-
Notifications
You must be signed in to change notification settings - Fork 102
Open
Description
I get:
Exception has occurred: KeyError
'num_tokens_from_messages() is not implemented for model gpt-5-nano.
See https://github.com/openai/openai-python/blob/main/chatml.md for how messages are converted to tokens.'
File "/mnt/c/Github/NLP/sketch_cost_5.py", line 55, in <module>
prompt_cost = calculate_prompt_cost(prompt, model)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'num_tokens_from_messages() is not implemented for model gpt-5-nano.
See https://github.com/openai/openai-python/blob/main/chatml.md for how messages are converted to tokens.'
With:
from openai import OpenAI
client = OpenAI()
model = "gpt-5-nano"
prompt = [{ "role": "user", "content": "Say this is a test"}]
chat_completion = client.chat.completions.create(messages=prompt, model=model)
completion = chat_completion.choices[0].message.content
# "This is a test."
prompt_cost = calculate_prompt_cost(prompt, model)
completion_cost = calculate_completion_cost(completion, model)
print(f"{prompt_cost} + {completion_cost} = {prompt_cost + completion_cost}")
# 0.0000180 + 0.000010 = 0.0000280Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels