Skip to content

OpenAI provider sends max_completion_tokens — breaks Mistral (and likely other) OpenAI-compatible endpoints #852

@philippop

Description

@philippop

Problem

When using HINDSIGHT_API_LLM_PROVIDER=openai with HINDSIGHT_API_LLM_BASE_URL pointed at Mistral's API (https://api.mistral.ai/v1), Hindsight crashes on startup during verify_connection.

The OpenAI-compatible provider sends max_completion_tokens in the chat completion request, but Mistral's API only accepts max_tokens and rejects the request with a 422:

openai.UnprocessableEntityError: Error code: 422 - {
  'object': 'error',
  'message': {'detail': [{'type': 'extra_forbidden', 'loc': ['body', 'max_completion_tokens'],
    'msg': 'Extra inputs are not permitted', 'input': 100}]},
  'type': 'invalid_request_error'
}

RuntimeError: Connection verification failed for openai/mistral-small-latest

This is a known incompatibility — Mistral (and several other providers) haven't adopted max_completion_tokens and expect max_tokens instead. See mistralai/platform-docs-public#7.

Expected behavior

The openai provider with a custom BASE_URL should work with any OpenAI-compatible API, including Mistral. Either:

  1. Use max_tokens instead of max_completion_tokens when a custom base URL is set, or
  2. Add mistral as a first-class provider (with correct parameter mapping), or
  3. Catch the 422 and fall back to max_tokens

Workaround

Using litellm as the provider works, since LiteLLM handles the parameter translation:

HINDSIGHT_API_LLM_PROVIDER=litellm
HINDSIGHT_API_LLM_MODEL=mistral/mistral-small-latest
HINDSIGHT_API_LLM_API_KEY=<key>
MISTRAL_API_KEY=<key>

Environment

  • Hindsight v0.4.22 (Docker, ghcr.io/vectorize-io/hindsight:latest)
  • Mistral model: mistral-small-latest
  • Base URL: https://api.mistral.ai/v1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions