fix: forward base_url to instructor client for OpenAI-compatible endpoints#5264
Open
shivam2407 wants to merge 1 commit intocrewAIInc:mainfrom
Open
fix: forward base_url to instructor client for OpenAI-compatible endpoints#5264shivam2407 wants to merge 1 commit intocrewAIInc:mainfrom
shivam2407 wants to merge 1 commit intocrewAIInc:mainfrom
Conversation
…oints (crewAIInc#5204) When using an OpenAI-compatible provider with a custom base_url (e.g. self-hosted vLLM, Ollama), InternalInstructor silently discarded the base_url and sent requests to api.openai.com instead. Add _get_llm_client_kwargs() to extract base_url, api_base, and api_key from the LLM object. When base_url is present, construct an explicit SDK client instead of using instructor.from_provider() which doesn't forward it: - OpenAI: OpenAI(base_url=...) - Azure: AzureOpenAI(azure_endpoint=..., api_version=...) - Anthropic: Anthropic(base_url=...) Also normalizes api_base to base_url (base_url takes precedence when both are set). Includes 8 tests covering OpenAI/Anthropic/Azure forwarding, api_base normalization, collision precedence, string LLM fallback, and the default no-base_url path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #5204
When using an OpenAI-compatible provider with a custom
base_url(e.g. self-hosted vLLM, Ollama, or any non-OpenAI endpoint),InternalInstructorsilently discards thebase_urland sends structured output requests toapi.openai.cominstead of the configured endpoint.Root cause
_create_instructor_client()extracts onlymodelandproviderfrom the LLM, then callsinstructor.from_provider(f"{provider}/{model_string}"). Thebase_urlis never forwarded, andinstructor.from_provider()creates a default client pointing atapi.openai.com/v1/.Fix
Added
_get_llm_client_kwargs()to extractbase_url,api_base, andapi_keyfrom the LLM object. Whenbase_urlis present, constructs an explicit SDK client instead of usingfrom_provider():openaiOpenAI(base_url=...)base_urlazure/azure_openaiAzureOpenAI(azure_endpoint=..., api_version=...)azure_endpointanthropicAnthropic(base_url=...)base_urlfrom_provider()fallbackapi_keyonlyAdditional behaviors:
api_baseis normalized tobase_url; when both are set,base_urltakes precedenceis not None(not truthiness) so empty strings are handled correctlybase_urlis set, behavior is unchanged (from_provider()path)Changes
internal_instructor.py_get_llm_client_kwargs(),_create_instructor_client_with_base_url()with per-provider client construction. Updated_create_instructor_client()to route through the new path whenbase_urlis present.test_converter.pyTest plan
output_pydantictask