Skip to content

404 when connecting to Ollama using ChatOpenAI and output_version="responses/v1" #32783

@jaxonister

Description

@jaxonister

Checked other resources

  • This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/).
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
  • I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example).
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Example Code

self.llm = ChatOpenAI(model="qwen3:14b",
                              base_url="http://xxxxxx/v1/",
                              output_version="responses/v1")
response = self.llm.invoke(["Hello, how are you?"])
        print(response.content)

Error Message and Stack Trace (if applicable)

cast_to = <class 'openai.types.responses.response.Response'>
options = FinalRequestOptions(method='post', url='/responses', params={}, headers={'X-Stainless-Raw-Response': 'true'}, max_retr...'input': [{'content': 'Hello, how are you?', 'role': 'user'}], 'model': 'qwen3:14b', 'stream': False}, extra_json=None)

def request(
    self,
    cast_to: Type[ResponseT],
    options: FinalRequestOptions,
    *,
    stream: bool = False,
    stream_cls: type[_StreamT] | None = None,
) -> ResponseT | _StreamT:
    cast_to = self._maybe_override_cast_to(cast_to, options)

    # create a copy of the options we were given so that if the
    # options are mutated later & we then retry, the retries are
    # given the original options
    input_options = model_copy(options)
    if input_options.idempotency_key is None and input_options.method.lower() != "get":
        # ensure the idempotency key is reused between requests
        input_options.idempotency_key = self._idempotency_key()

    response: httpx.Response | None = None
    max_retries = input_options.get_max_retries(self.max_retries)

    retries_taken = 0
    for retries_taken in range(max_retries + 1):
        options = model_copy(input_options)
        options = self._prepare_options(options)

        remaining_retries = max_retries - retries_taken
        request = self._build_request(options, retries_taken=retries_taken)
        self._prepare_request(request)

        kwargs: HttpxSendArgs = {}
        if self.custom_auth is not None:
            kwargs["auth"] = self.custom_auth

        if options.follow_redirects is not None:
            kwargs["follow_redirects"] = options.follow_redirects

        log.debug("Sending HTTP Request: %s %s", request.method, request.url)

        response = None
        try:
            response = self._client.send(
                request,
                stream=stream or self._should_stream_response_body(request=request),
                **kwargs,
            )
        except httpx.TimeoutException as err:
            log.debug("Encountered httpx.TimeoutException", exc_info=True)

            if remaining_retries > 0:
                self._sleep_for_retry(
                    retries_taken=retries_taken,
                    max_retries=max_retries,
                    options=input_options,
                    response=None,
                )
                continue

            log.debug("Raising timeout error")
            raise APITimeoutError(request=request) from err
        except Exception as err:
            log.debug("Encountered Exception", exc_info=True)

            if remaining_retries > 0:
                self._sleep_for_retry(
                    retries_taken=retries_taken,
                    max_retries=max_retries,
                    options=input_options,
                    response=None,
                )
                continue

            log.debug("Raising connection error")
            raise APIConnectionError(request=request) from err

        log.debug(
            'HTTP Response: %s %s "%i %s" %s',
            request.method,
            request.url,
            response.status_code,
            response.reason_phrase,
            response.headers,
        )
        log.debug("request_id: %s", response.headers.get("x-request-id"))

        try:
            response.raise_for_status()
        except httpx.HTTPStatusError as err:  # thrown on 4xx and 5xx status code
            log.debug("Encountered httpx.HTTPStatusError", exc_info=True)

            if remaining_retries > 0 and self._should_retry(err.response):
                err.response.close()
                self._sleep_for_retry(
                    retries_taken=retries_taken,
                    max_retries=max_retries,
                    options=input_options,
                    response=response,
                )
                continue

            # If the response is streamed then we need to explicitly read the response
            # to completion before attempting to access the response text.
            if not err.response.is_closed:
                err.response.read()

            log.debug("Re-raising status error")
          raise self._make_status_error_from_response(err.response) from None

E openai.NotFoundError: 404 page not found

Description

When connecting to Ollama using ChatOpenAI, I set output_version="responses/v1" and received an error: openai.NotFoundError: 404 page not found

System Info

aiohttp<4.0.0,>=3.8.3: Installed. No version info available.
async-timeout<5.0.0,>=4.0.0;: Installed. No version info available.
dataclasses-json<0.7,>=0.5.7: Installed. No version info available.
httpx: 0.28.1
httpx-sse<1.0.0,>=0.4.0: Installed. No version info available.
httpx<1,>=0.23.0: Installed. No version info available.
jsonpatch<2.0,>=1.33: Installed. No version info available.
langchain-anthropic;: Installed. No version info available.
langchain-aws;: Installed. No version info available.
langchain-azure-ai;: Installed. No version info available.
langchain-cohere;: Installed. No version info available.
langchain-community;: Installed. No version info available.
langchain-core<1.0.0,>=0.3.41: Installed. No version info available.
langchain-core<1.0.0,>=0.3.51: Installed. No version info available.
langchain-core<1.0.0,>=0.3.52: Installed. No version info available.
langchain-core<1.0.0,>=0.3.55: Installed. No version info available.
langchain-core<1.0.0,>=0.3.74: Installed. No version info available.
langchain-deepseek;: Installed. No version info available.
langchain-fireworks;: Installed. No version info available.
langchain-google-genai;: Installed. No version info available.
langchain-google-vertexai;: Installed. No version info available.
langchain-groq;: Installed. No version info available.
langchain-huggingface;: Installed. No version info available.
langchain-mistralai;: Installed. No version info available.
langchain-ollama;: Installed. No version info available.
langchain-openai;: Installed. No version info available.
langchain-perplexity;: Installed. No version info available.
langchain-text-splitters<1.0.0,>=0.3.8: Installed. No version info available.
langchain-together;: Installed. No version info available.
langchain-xai;: Installed. No version info available.
langchain<1.0.0,>=0.3.20: Installed. No version info available.
langsmith-pyo3>=0.1.0rc2;: Installed. No version info available.
langsmith<0.4,>=0.1.125: Installed. No version info available.
langsmith<0.4,>=0.1.17: Installed. No version info available.
langsmith>=0.3.45: Installed. No version info available.
numpy<3,>=1.26.2: Installed. No version info available.
ollama<1,>=0.4.4: Installed. No version info available.
openai-agents>=0.0.3;: Installed. No version info available.
openai<2.0.0,>=1.99.9: Installed. No version info available.
opentelemetry-api>=1.30.0;: Installed. No version info available.
opentelemetry-exporter-otlp-proto-http>=1.30.0;: Installed. No version info available.
opentelemetry-sdk>=1.30.0;: Installed. No version info available.
orjson: 3.10.15
orjson>=3.9.14;: Installed. No version info available.
packaging>=23.2: Installed. No version info available.
pydantic-settings<3.0.0,>=2.4.0: Installed. No version info available.
pydantic<3,>=1: Installed. No version info available.
pydantic<3.0.0,>=2.7.4: Installed. No version info available.
pydantic>=2.7.4: Installed. No version info available.
pytest>=7.0.0;: Installed. No version info available.
PyYAML>=5.3: Installed. No version info available.
requests-toolbelt>=1.0.0: Installed. No version info available.
requests<3,>=2: Installed. No version info available.
requests>=2.0.0: Installed. No version info available.
rich>=13.9.4;: Installed. No version info available.
SQLAlchemy<3,>=1.4: Installed. No version info available.
tenacity!=8.4.0,<10,>=8.1.0: Installed. No version info available.
tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available.
tiktoken<1,>=0.7: Installed. No version info available.
typing-extensions>=4.7: Installed. No version info available.
vcrpy>=7.0.0;: Installed. No version info available.
zstandard>=0.23.0: Installed. No version info available.

Metadata

Metadata

Assignees

Labels

bugRelated to a bug, vulnerability, unexpected error with an existing featureinvestigateFlagged for investigation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions