From cd0411915a56ca83f0d52939e5652fe04594a88a Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Thu, 21 Nov 2024 21:35:50 -0800 Subject: [PATCH] add example with anthropic python SDK --- .../docs/pass_through/anthropic_completion.md | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/docs/my-website/docs/pass_through/anthropic_completion.md b/docs/my-website/docs/pass_through/anthropic_completion.md index 0c6a5f1b6..320527580 100644 --- a/docs/my-website/docs/pass_through/anthropic_completion.md +++ b/docs/my-website/docs/pass_through/anthropic_completion.md @@ -1,10 +1,18 @@ -# Anthropic `/v1/messages` +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +# Anthropic SDK Pass-through endpoints for Anthropic - call provider-specific endpoint, in native format (no translation). -Just replace `https://api.anthropic.com` with `LITELLM_PROXY_BASE_URL/anthropic` 🚀 +Just replace `https://api.anthropic.com` with `LITELLM_PROXY_BASE_URL/anthropic` #### **Example Usage** + + + + + ```bash curl --request POST \ --url http://0.0.0.0:4000/anthropic/v1/messages \ @@ -20,6 +28,33 @@ curl --request POST \ }' ``` + + + +```python +from anthropic import Anthropic + +# Initialize client with proxy base URL +client = Anthropic( + base_url="http://0.0.0.0:4000/anthropic", # /anthropic + api_key="sk-anything" # proxy virtual key +) + +# Make a completion request +response = client.messages.create( + model="claude-3-5-sonnet-20241022", + max_tokens=1024, + messages=[ + {"role": "user", "content": "Hello, world"} + ] +) + +print(response) +``` + + + + Supports **ALL** Anthropic Endpoints (including streaming). [**See All Anthropic Endpoints**](https://docs.anthropic.com/en/api/messages)