Skip to content

OpenAI fallback uses active provider default model #38

Closed

Description

@keshprad

Summary

When only OPENAI_API_KEY is configured, get_chat_model() can fall back to constructing a ChatOpenAI client while still using the active/default provider's model label. In the NVIDIA-provider default path this can produce a ChatOpenAI configured with an NVIDIA/Anthropic model such as azure/anthropic/claude-opus-4-6.

The fallback should keep the client/provider and default model coupled: if construction falls back to OpenAI because the active provider is not configured, the default model should come from the OpenAI provider unless the caller explicitly supplied a model.

Reproduction

Run with only OPENAI_API_KEY set and no explicit model:

import os

for key in (
    "ANTHROPIC_API_KEY",
    "NVIDIA_INFERENCE_KEY",
    "NVIDIA_INFERENCE_METADATA_KEY",
    "OPENAI_BASE_URL",
    "SKILLSPECTOR_MODEL",
    "SKILLSPECTOR_PROVIDER",
):
    os.environ.pop(key, None)
os.environ["OPENAI_API_KEY"] = "sk-test-openai-only"

from skillspector.llm_utils import get_chat_model
from skillspector.constants import MODEL_CONFIG

llm = get_chat_model()
print("MODEL_CONFIG default:", MODEL_CONFIG["default"])
print("constructed class:", type(llm).__name__)
print("constructed model:", getattr(llm, "model_name", None) or getattr(llm, "model", None))
print("default params:", getattr(llm, "_default_params", None))

Observed output while reviewing the provider-owned chat model factory work:

MODEL_CONFIG default: azure/anthropic/claude-opus-4-6
constructed class: ChatOpenAI
constructed model: azure/anthropic/claude-opus-4-6
default params: {'model': 'azure/anthropic/claude-opus-4-6', 'stream': False, 'max_completion_tokens': 128000}

Actual behavior

get_chat_model() resolves the default model before provider fallback, so OpenAI fallback can be paired with a non-OpenAI model label.

Expected behavior

If no model is explicitly provided and the active provider is unconfigured, OpenAI fallback should construct ChatOpenAI with the OpenAI provider's default model. Explicit caller-provided model labels should still be honored.

Impact

Users who only configure OPENAI_API_KEY can get runtime API failures or confusing model errors even though the code successfully constructs a ChatOpenAI client.

Notes

I did not find an existing issue for this using searches for OPENAI_API_KEY, get_chat_model, OpenAI fallback, and model fallback.

Activity

  1. gifmaster commented on Jun 14, 2026

    @gifmaster

    I hit the same issue on SDK 0.109.1 and Python 3.13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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