Repository: mlflow/mlflow

Issue:
[BUG] anthropic-version header is missing in AnthropicProvider
### Issues Policy acknowledgement

- [X] I have read and agree to submit bug reports in accordance with the [issues policy](https://www.github.com/mlflow/mlflow/blob/master/ISSUE_POLICY.md)

### Where did you encounter this bug?

Local machine

### Willingness to contribute

Yes. I would be willing to contribute a fix for this bug with guidance from the MLflow community.

### MLflow version

- Client: 2.10.0
- Tracking server: 2.10.0


### System information

- **OS Platform and Distribution (e.g., Linux Ubuntu 16.04)**: Ubuntu 20.04.6 LTS
- **Python version**: Python 3.8.10
- **yarn version, if running the dev UI**:


### Describe the problem

It seems anthropic-version header is missing in AnthropicProvider [here](https://github.com/mlflow/mlflow/blob/5d13d6ec620a02de9a5e31201bf1becdb9722ea5/mlflow/gateway/providers/anthropic.py#L107), which caused this error:

![Screenshot 2024-01-26 at 1 43 33 PM](https://github.com/mlflow/mlflow/assets/157841226/eb357e4e-28c6-441e-9be0-e4390fa6bdf9)


### Tracking information

<!-- PLEASE KEEP BACKTICKS AND CHECK PREVIEW -->
```shell
REPLACE_ME
```


### Code to reproduce issue

<!-- PLEASE KEEP BACKTICKS AND CHECK PREVIEW -->
```
REPLACE_ME
```


### Stack trace

<!-- PLEASE KEEP BACKTICKS AND CHECK PREVIEW -->
```
REPLACE_ME
```


### Other info / logs

<!-- PLEASE KEEP BACKTICKS AND CHECK PREVIEW -->
```
REPLACE_ME
```


### What component(s) does this bug affect?

- [ ] `area/artifacts`: Artifact stores and artifact logging
- [ ] `area/build`: Build and test infrastructure for MLflow
- [X] `area/deployments`: MLflow Deployments client APIs, server, and third-party Deployments integrations
- [ ] `area/docs`: MLflow documentation pages
- [ ] `area/examples`: Example code
- [ ] `area/model-registry`: Model Registry service, APIs, and the fluent client calls for Model Registry
- [ ] `area/models`: MLmodel format, model serialization/deserialization, flavors
- [ ] `area/recipes`: Recipes, Recipe APIs, Recipe configs, Recipe Templates
- [ ] `area/projects`: MLproject format, project running backends
- [ ] `area/scoring`: MLflow Model server, model deployment tools, Spark UDFs
- [ ] `area/server-infra`: MLflow Tracking server backend
- [ ] `area/tracking`: Tracking Service, tracking client APIs, autologging

### What interface(s) does this bug affect?

- [X] `area/uiux`: Front-end, user experience, plotting, JavaScript, JavaScript dev server
- [ ] `area/docker`: Docker use across MLflow's components, such as MLflow Projects and MLflow Models
- [ ] `area/sqlalchemy`: Use of SQLAlchemy in the Tracking Service or Model Registry
- [ ] `area/windows`: Windows support

### What language(s) does this bug affect?

- [ ] `language/r`: R APIs and clients
- [ ] `language/java`: Java APIs and clients
- [ ] `language/new`: Proposals for new client languages

### What integration(s) does this bug affect?

- [ ] `integrations/azure`: Azure and Azure ML integrations
- [ ] `integrations/sagemaker`: SageMaker integrations
- [ ] `integrations/databricks`: Databricks integrations


Discussion:
Hi @xwangotter Thanks for raising the issue, please feel free to file a PR to fix it! BTW is this a newly introduced header for newer anthropic version?
https://docs.anthropic.com/claude/reference/complete_post shows `--header "anthropic-version: 2023-06-01"` @hubertzub-db @dbczumar We might need to fix this on databricks side as well
I can contribute to fix this bug if anyone can show me how to recompile source of mlflow that has been modified. Currently, mlflow source appears inside of site-packages in my project. 

I have already modified some py files to test and then make a 'python -m compileall' from the parent directory but nothing changes.
@ngo-minh-thang-nguyen You could follow https://github.com/mlflow/mlflow/blob/master/CONTRIBUTING.md to get started, you need to clone the github repo and raise a PR
@serena-ruan @ngo-minh-thang-nguyen Hi, I have the fix ready and was able to compile it. I can create a PR today.
Hello @xhw1, have you created the PR to fix this problem?

Thank you for your reply
<!-- assign-maintainer -->
@mlflow/mlflow-team Please assign a maintainer and start triaging this issue.
Hi @serena-ruan , can you please review the PR? Thank you!

Resolving patch:
diff --git a/mlflow/gateway/config.py b/mlflow/gateway/config.py
--- a/mlflow/gateway/config.py
+++ b/mlflow/gateway/config.py
@@ -167,6 +167,7 @@ def validate_field_compatibility(cls, config: Dict[str, Any]):
 
 class AnthropicConfig(ConfigModel):
     anthropic_api_key: str
+    anthropic_version: str = "2023-06-01"
 
     # pylint: disable=no-self-argument
     @validator("anthropic_api_key", pre=True)
diff --git a/mlflow/gateway/providers/anthropic.py b/mlflow/gateway/providers/anthropic.py
--- a/mlflow/gateway/providers/anthropic.py
+++ b/mlflow/gateway/providers/anthropic.py
@@ -104,7 +104,10 @@ def __init__(self, config: RouteConfig) -> None:
         if config.model.config is None or not isinstance(config.model.config, AnthropicConfig):
             raise TypeError(f"Invalid config type {config.model.config}")
         self.anthropic_config: AnthropicConfig = config.model.config
-        self.headers = {"x-api-key": self.anthropic_config.anthropic_api_key}
+        self.headers = {
+            "x-api-key": self.anthropic_config.anthropic_api_key,
+            "anthropic-version": self.anthropic_config.anthropic_version,
+        }
         self.base_url = "https://api.anthropic.com/v1/"
 
     async def completions(self, payload: completions.RequestPayload) -> completions.ResponsePayload:


Test patch: