Skip to content

Python: [Bug]: OpenAIEmbeddingClient does not work with /openai/v1 endpoint #5068

@cecheta

Description

@cecheta

Description

An error occurs when trying to use OpenAIEmbeddingClient when setting base_url to the /openai/v1 endpoint. The /openai/v1 endpoint works correctly for OpenAIChatClient.

Code Sample

from agent_framework.openai import OpenAIEmbeddingClient
from azure.identity import AzureCliCredential


async def main() -> None:
    client = OpenAIEmbeddingClient(
        base_url="https://<project>.openai.azure.com/openai/v1/",
        model="text-embedding-3-large",
        credential=AzureCliCredential(),
    )
    await client.get_embeddings(["Hello world!"])


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

Error Messages / Stack Traces

Traceback (most recent call last):
  File "/workspaces/agent-framework/python/main.py", line 17, in <module>
    asyncio.run(main())
    ~~~~~~~~~~~^^^^^^^^
  File "/home/vscode/.local/share/uv/python/cpython-3.13.11-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py", line 195, in run
    return runner.run(main)
           ~~~~~~~~~~^^^^^^
  File "/home/vscode/.local/share/uv/python/cpython-3.13.11-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/home/vscode/.local/share/uv/python/cpython-3.13.11-linux-x86_64-gnu/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "/workspaces/agent-framework/python/main.py", line 11, in main
    await client.get_embeddings(["Hello world!"])
  File "/workspaces/agent-framework/python/packages/core/agent_framework/observability.py", line 1446, in get_embeddings
    return await super_get_embeddings(values, options=options)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/agent-framework/python/packages/openai/agent_framework_openai/_embedding_client.py", line 286, in get_embeddings
    response = await self.client.embeddings.create(**kwargs)  # type: ignore[union-attr]
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/agent-framework/python/.venv/lib/python3.13/site-packages/openai/resources/embeddings.py", line 259, in create
    return await self._post(
           ^^^^^^^^^^^^^^^^^
    ...<10 lines>...
    )
    ^
  File "/workspaces/agent-framework/python/.venv/lib/python3.13/site-packages/openai/_base_client.py", line 1884, in post
    return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/agent-framework/python/.venv/lib/python3.13/site-packages/openai/_base_client.py", line 1669, in request
    raise self._make_status_error_from_response(err.response) from None
openai.NotFoundError: Error code: 404 - {'error': {'code': '404', 'message': 'Resource not found'}}

Package Versions

1.0.0

Python Version

3.13.11

Additional Context

Adding logging shows that the request is made to /openai/v1/deployments/text-embedding-3-large/embeddings?api-version=2024-10-21.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions