Skip to content

LiteLLM inline completions don't work with chat-only models like Anthropic #129

@NiklasPhabian

Description

@NiklasPhabian

Problem

The inline completions (autocomplete) in the LiteLLM provider fail when using chat-only models like Anthropic Claude because the code only uses the prompt/suffix parameters (fill-in-the-middle format):

litellm_resp = litellm.completion(
    model=model_id,
    prompt=prefix,
    suffix=suffix,
    ...
)

This results in errors: litellm.BadRequestError: Anthropic requires at least one non-system message.

Root Cause

  • Some models (OpenAI Codex, etc.) support FIM with prompt/suffix parameters
  • Chat-only models (Anthropic, most modern LLMs) only support messages format
  • The current implementation only tries FIM format

Proposed Solution

Implement a fallback mechanism:

  1. Try FIM format first (prompt/suffix) for models that support it
  2. If that fails, fall back to messages format with proper prompt construction
  3. Strip markdown code blocks from responses (chat models often return formatted code)

This maintains backward compatibility with FIM-capable models while adding support for chat-only models.

Impact

Users can now use Anthropic Claude and other chat-only models for inline completions through the LiteLLM provider.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions