instructor icon indicating copy to clipboard operation
instructor copied to clipboard

Perplexity crash: Completions.create() got an unexpected keyword argument 'base_url'

Open fancellu opened this issue 5 months ago • 0 comments

  • [x] This is actually a bug report.

What Model are you using?

  • [x] Perplexity sonar

Describe the bug

Completions.create() got an unexpected keyword argument 'base_url'

To Reproduce

import os

import instructor
from pydantic import BaseModel

client = instructor.from_provider(
    "perplexity/sonar-small-online",
    api_key=os.getenv("PERPLEXITY_API_KEY"),
    base_url="https://api.perplexity.ai",
)

class User(BaseModel):
    name: str
    age: int


user = client.chat.completions.create(
    messages=[{"role": "user", "content": "Extract: Jason is 25 years old"}],
    response_model=User,
)

print(user)

Stack trace:

C:\Users\dinof\anaconda3\envs\g1\python.exe C:\git\mine\python\pf_demo1\perplexity\instructor1.py 
Traceback (most recent call last):
  File "C:\Users\dinof\anaconda3\envs\g1\Lib\site-packages\instructor\retry.py", line 186, in retry_sync
    response = func(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\dinof\anaconda3\envs\g1\Lib\site-packages\openai\_utils\_utils.py", line 287, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
TypeError: Completions.create() got an unexpected keyword argument 'base_url'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\dinof\anaconda3\envs\g1\Lib\site-packages\instructor\retry.py", line 181, in retry_sync
    for attempt in max_retries:
  File "C:\Users\dinof\AppData\Roaming\Python\Python312\site-packages\tenacity\__init__.py", line 443, in __iter__
    do = self.iter(retry_state=retry_state)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\dinof\AppData\Roaming\Python\Python312\site-packages\tenacity\__init__.py", line 376, in iter
    result = action(retry_state)
             ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\dinof\AppData\Roaming\Python\Python312\site-packages\tenacity\__init__.py", line 419, in exc_check
    raise retry_exc from fut.exception()
tenacity.RetryError: RetryError[<Future at 0x1d0ed799af0 state=finished raised TypeError>]

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\git\mine\python\pf_demo1\perplexity\instructor1.py", line 20, in <module>
    user = client.chat.completions.create(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\dinof\anaconda3\envs\g1\Lib\site-packages\instructor\client.py", line 366, in create
    return self.create_fn(
           ^^^^^^^^^^^^^^^
  File "C:\Users\dinof\anaconda3\envs\g1\Lib\site-packages\instructor\patch.py", line 258, in new_create_sync
    response = retry_sync(
               ^^^^^^^^^^^
  File "C:\Users\dinof\anaconda3\envs\g1\Lib\site-packages\instructor\retry.py", line 212, in retry_sync
    raise InstructorRetryException(
instructor.exceptions.InstructorRetryException: Completions.create() got an unexpected keyword argument 'base_url'

If I try similar for Gemini, all is fine

fancellu avatar Jul 26 '25 10:07 fancellu