Skip to content

openai.error.InvalidRequestError: Invalid URL (POST /v1/chat/completions) when calling the chat completions endpoints multiple times #281

@adeolaemmanuelmorren

Description

@adeolaemmanuelmorren

Describe the bug

when calling

openai.ChatCompletion.create( model="gpt-3.5-turbo-0301", messages=[ { "role": "user", "content" : prompt } ], temperature=0.7, max_tokens=MAX_OUTPUT_BASE, n=1)

multiple times in a loop I noticed that the first few attempts run perfectly fine I believe the first 3-5, however after that it fails with the error code openai.error.InvalidRequestError: Invalid URL (POST /v1/chat/completions)

which is very odd as the prior ones are running smoothly within the same exact function call...

I can verify that I'm running on openai==0.27.0 with python 3.9

To Reproduce

  1. create an array of texts
    2 run the following for text in texts:

     MAX_TOKENS = 3500
     # used for testing to see how the token limit progrsses over time
    
    
     response = openai.ChatCompletion.create(
       model="gpt-3.5-turbo-0301",
       messages=[
         {
             "role": "user",
             "content" : "text"
         }
       ],            
       temperature=0.7, 
       max_tokens=MAX_TOKENS, n=1)
    

Code snippets

No response

OS

macos

Python version

python 3.9

Library version

openai-python v0.27.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions