You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm getting the error even though I set the api_key to keys with the same format as openai
Python 3.13.1
pydantic-ai==0.0.24
openai==1.63.2
Error
File "C:\Users\xxxx\AppData\Roaming\Python\Python313\site-packages\openai\_base_client.py", line 1623, in _request
raise APIConnectionError(request=request) from err
openai.APIConnectionError: Connection error.
My Code
from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIModel
name_model = 'llama3.2:3b'
ollama_url = 'http://localhost:11434/v1'
openai_key = 'SkllQ4R6e2vL9K3Gg5z2B'
model_ollama = OpenAIModel(
model_name = name_model,
base_url = ollama_url,
api_key = openai_key
)
agent = Agent(
model=model_ollama,
system_prompt=['Reply in one sentence']
)
response = agent.run_sync('What is the capital of japan?')
print(response.data)
Opening a new issue because the problem is different
Yes, my ollama server is working, when I use the ollama library everything works normally, only when I use Pydantic it doesn't. note that the error is different from the mentioned issue, before the error was due to the api_key property being empty and now it is an error when trying to execute the request with an invalid api_key.
Other Error
openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable
My error:
openai.APIConnectionError: Connection error
The text was updated successfully, but these errors were encountered:
I'm also having that error. I manage to make pydantic-ai work with release 0.0.19 and with the latest realease of ollama locally but not using the OpenAiModel import, just only using the Agent import like this:
I went back until 0.0.17 and using the OpenAIModel still does have either one of the errors mentioned before. If I'm not wrong the error changes in release 0.0.20 to
Originally posted by @This-Is-NPC in #812
Opening a new issue because the problem is different
Yes, my ollama server is working, when I use the ollama library everything works normally, only when I use Pydantic it doesn't. note that the error is different from the mentioned issue, before the error was due to the api_key property being empty and now it is an error when trying to execute the request with an invalid api_key.
Other Error
My error:
The text was updated successfully, but these errors were encountered: