Skip to content

OpenAI Agents SDK unable to contact local endpoint hosted by Ollama / LM Studio #625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
samDobsonDev opened this issue Apr 29, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@samDobsonDev
Copy link

samDobsonDev commented Apr 29, 2025

When using this model and providing it to my Agents:

model = OpenAIChatCompletionsModel(
    model="cogito-v1-preview-llama-8b",
    openai_client=AsyncOpenAI(
        base_url="http://localhost:1234/v1"
    )
)

The Agent.run() produces this error:

2025-04-29 15:21:17,826 - INFO - Retrying request to /chat/completions in 0.403615 seconds
2025-04-29 15:21:18,231 - INFO - Retrying request to /chat/completions in 0.819511 seconds
INFO:     127.0.0.1:34818 - "POST / HTTP/1.1" 500 Internal Server Error
2025-04-29 15:21:19,070 - ERROR - An unexpected error occurred:
Traceback (most recent call last):
  File "/home/sam/anaconda3/lib/python3.12/site-packages/anyio/_core/_sockets.py", line 175, in try_connect
    stream = await asynclib.connect_tcp(remote_host, remote_port, local_address)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sam/anaconda3/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 2590, in connect_tcp
    await get_running_loop().create_connection(
  File "/home/sam/anaconda3/lib/python3.12/asyncio/base_events.py", line 1121, in create_connection
    raise exceptions[0]
  File "/home/sam/anaconda3/lib/python3.12/asyncio/base_events.py", line 1103, in create_connection
    sock = await self._connect_sock(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sam/anaconda3/lib/python3.12/asyncio/base_events.py", line 1006, in _connect_sock
    await self.sock_connect(sock, address)
  File "/home/sam/anaconda3/lib/python3.12/asyncio/selector_events.py", line 651, in sock_connect
    return await fut
           ^^^^^^^^^
  File "/home/sam/anaconda3/lib/python3.12/asyncio/selector_events.py", line 691, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('127.0.0.1', 1234)

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

Traceback (most recent call last):
  File "/home/sam/anaconda3/lib/python3.12/site-packages/httpcore/_exceptions.py", line 10, in map_exceptions
    yield
  File "/home/sam/anaconda3/lib/python3.12/site-packages/httpcore/_backends/anyio.py", line 114, in connect_tcp
    stream: anyio.abc.ByteStream = await anyio.connect_tcp(
                                   ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sam/anaconda3/lib/python3.12/site-packages/anyio/_core/_sockets.py", line 241, in connect_tcp
    raise OSError("All connection attempts failed") from cause
OSError: All connection attempts failed

The endpoint at http://localhost:1234/v1 works when I cURL it, for example:

curl http://localhost:1234/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "cogito-v1-preview-llama-8b",
    "messages": [
      { "role": "system", "content": "Always answer in rhymes. Today is Thursday" },
      { "role": "user", "content": "What day is it today?" }
    ],
    "temperature": 0.7,
    "max_tokens": -1,
    "stream": false
}'

But for some reason I can't get it to work with the Agents SDK

@samDobsonDev samDobsonDev added the bug Something isn't working label Apr 29, 2025
@samDobsonDev samDobsonDev changed the title Issue with LM Studio OpenAI Agents SDK unable to contact local endpoint hosted by Ollama / LM Studio Apr 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant