Draft
Conversation
This adds proper Databricks model support by capping max_output_tokens at 25000, which is the API limit enforced by Databricks. The fix is implemented in the LLM class _coerce_inputs model_validator, which runs before model instantiation. This ensures that all Databricks models (model names starting with 'databricks/') automatically get the correct max_output_tokens value. If max_output_tokens is not set or exceeds 25000, it will be capped at 25000. This prevents API rejections from Databricks while still allowing users to set lower values if desired. This is the proper fix location compared to the OpenHands workaround, as it handles the limitation at the SDK level where all model-specific configurations should be centralized. Related PR: OpenHands/OpenHands#12925 Co-authored-by: openhands <openhands@all-hands.dev>
Databricks API requires max_tokens parameter (not max_completion_tokens) and has a hard limit of 25000 tokens. This fix: 1. Converts max_completion_tokens to max_tokens for Databricks models 2. Caps the value at 25000 to comply with API limits This is similar to the existing Azure handling and ensures Databricks models work correctly with the SDK. Related: OpenHands/OpenHands#12925 Signed-off-by: Juan Michelini <juan@juan.com.uy>
- Fix line length issue in comment - Improve logic to match working OpenHands PR #12925 - Handle both max_tokens and max_completion_tokens correctly - Cap at 25000 with proper precedence
Databricks API doesn't support the metadata parameter that LiteLLM can pass. This causes BadRequestError: json: unknown field "metadata" Added metadata removal for Databricks models, similar to how we handle max_completion_tokens -> max_tokens conversion.
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
This PR adds proper Databricks model support to the SDK by ensuring that:
max_completion_tokensparameter is converted tomax_tokens(which Databricks requires)Problem
Databricks models were failing because:
max_completion_tokensbut Databricks expectsmax_tokensSolution
Added Databricks-specific handling in
chat_options.py(similar to existing Azure handling):max_completion_tokens→max_tokensThis is the minimal and elegant fix that ensures compatibility.
Testing
✅ Verified with test script in OpenHands:
Related
Agent Server images for this PR
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdknikolaik/python-nodejs:python3.12-nodejs22golang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:9272ad3-pythonRun
All tags pushed for this build
About Multi-Architecture Support
9272ad3-python) is a multi-arch manifest supporting both amd64 and arm649272ad3-python-amd64) are also available if needed