API error BadRequestError: Error code: 400 Unable to parse and estimate tokens from incoming request

Hi,
I run the following code (it work many times before)

prompt = """some_prompt with json format
"""
prompt1 = 'json'
response = client.chat.completions.create(
    model='gpt-4o-2024-05-13',
    messages=[
       # {'role':'system','content':'You are a helpful assistant'},
        {'role':'user','content':[
            {"type":'text','text':prompt},
            {"type":'image_url',"image_url": {
                "url":f"data:image/jpeg;base64,{base64_image}",
                "detail": 'low'}}
    ]}],
    max_tokens=300,seed=123, response_format={"type": "json_object"}
                
)

and i got an error

BadRequestError: Error code: 400 - {'statusCode': 400, 'message': "Unable to parse and estimate tokens from incoming request. Please ensure incoming request is of one of the following types: 'Chat Completion', 'Completion', 'Embeddings' and works with current prompt estimation mode of 'Auto'."}

the client object worked with the prompt (only) and I excuted this code yesterday successfully but the it’s the second time I got this error and I don’t know why.

1 Like