|
| 1 | +import Tabs from '@theme/Tabs'; |
| 2 | +import TabItem from '@theme/TabItem'; |
| 3 | + |
| 4 | +# SAP Generative AI Hub |
| 5 | + |
| 6 | +LiteLLM supports SAP Generative AI Hub's Orchestration Service. |
| 7 | + |
| 8 | +| Property | Details | |
| 9 | +|-------|-------| |
| 10 | +| Description | SAP's Generative AI Hub provides access to foundation models through the AI Core orchestration service. | |
| 11 | +| Provider Route on LiteLLM | `sap/` | |
| 12 | +| Supported Endpoints | `/chat/completions` | |
| 13 | +| API Reference | [SAP AI Core Documentation](https://help.sap.com/docs/sap-ai-core) | |
| 14 | + |
| 15 | +## Authentication |
| 16 | + |
| 17 | +SAP Generative AI Hub uses service key authentication. You can provide credentials via: |
| 18 | + |
| 19 | +1. **Environment variable** - Set `AICORE_SERVICE_KEY` with your service key JSON |
| 20 | +2. **Direct parameter** - Pass `api_key` with the service key JSON string |
| 21 | + |
| 22 | +```python showLineNumbers title="Environment Variable" |
| 23 | +import os |
| 24 | +os.environ["AICORE_SERVICE_KEY"] = '{"clientid": "...", "clientsecret": "...", ...}' |
| 25 | +``` |
| 26 | + |
| 27 | +## Usage - LiteLLM Python SDK |
| 28 | + |
| 29 | +```python showLineNumbers title="SAP Chat Completion" |
| 30 | +from litellm import completion |
| 31 | +import os |
| 32 | + |
| 33 | +os.environ["AICORE_SERVICE_KEY"] = '{"clientid": "...", "clientsecret": "...", ...}' |
| 34 | + |
| 35 | +response = completion( |
| 36 | + model="sap/gpt-4", |
| 37 | + messages=[{"role": "user", "content": "Hello from LiteLLM"}] |
| 38 | +) |
| 39 | +print(response) |
| 40 | +``` |
| 41 | + |
| 42 | +```python showLineNumbers title="SAP Chat Completion - Streaming" |
| 43 | +from litellm import completion |
| 44 | +import os |
| 45 | + |
| 46 | +os.environ["AICORE_SERVICE_KEY"] = '{"clientid": "...", "clientsecret": "...", ...}' |
| 47 | + |
| 48 | +response = completion( |
| 49 | + model="sap/gpt-4", |
| 50 | + messages=[{"role": "user", "content": "Hello from LiteLLM"}], |
| 51 | + stream=True |
| 52 | +) |
| 53 | + |
| 54 | +for chunk in response: |
| 55 | + print(chunk.choices[0].delta.content or "", end="") |
| 56 | +``` |
| 57 | + |
| 58 | +## Usage - LiteLLM Proxy |
| 59 | + |
| 60 | +Add to your LiteLLM Proxy config: |
| 61 | + |
| 62 | +```yaml showLineNumbers title="config.yaml" |
| 63 | +model_list: |
| 64 | + - model_name: sap-gpt4 |
| 65 | + litellm_params: |
| 66 | + model: sap/gpt-4 |
| 67 | + api_key: os.environ/AICORE_SERVICE_KEY |
| 68 | +``` |
| 69 | +
|
| 70 | +Start the proxy: |
| 71 | +
|
| 72 | +```bash showLineNumbers title="Start Proxy" |
| 73 | +litellm --config config.yaml |
| 74 | +``` |
| 75 | + |
| 76 | +<Tabs> |
| 77 | +<TabItem value="curl" label="cURL"> |
| 78 | + |
| 79 | +```bash showLineNumbers title="Test Request" |
| 80 | +curl http://localhost:4000/v1/chat/completions \ |
| 81 | + -H "Content-Type: application/json" \ |
| 82 | + -H "Authorization: Bearer your-proxy-api-key" \ |
| 83 | + -d '{ |
| 84 | + "model": "sap-gpt4", |
| 85 | + "messages": [{"role": "user", "content": "Hello"}] |
| 86 | + }' |
| 87 | +``` |
| 88 | + |
| 89 | +</TabItem> |
| 90 | +<TabItem value="openai-sdk" label="OpenAI SDK"> |
| 91 | + |
| 92 | +```python showLineNumbers title="OpenAI SDK" |
| 93 | +from openai import OpenAI |
| 94 | + |
| 95 | +client = OpenAI( |
| 96 | + base_url="http://localhost:4000", |
| 97 | + api_key="your-proxy-api-key" |
| 98 | +) |
| 99 | + |
| 100 | +response = client.chat.completions.create( |
| 101 | + model="sap-gpt4", |
| 102 | + messages=[{"role": "user", "content": "Hello"}] |
| 103 | +) |
| 104 | +print(response.choices[0].message.content) |
| 105 | +``` |
| 106 | + |
| 107 | +</TabItem> |
| 108 | +</Tabs> |
| 109 | + |
| 110 | +## Supported Parameters |
| 111 | + |
| 112 | +| Parameter | Description | |
| 113 | +|-----------|-------------| |
| 114 | +| `temperature` | Controls randomness | |
| 115 | +| `max_tokens` | Maximum tokens in response | |
| 116 | +| `top_p` | Nucleus sampling | |
| 117 | +| `tools` | Function calling tools | |
| 118 | +| `tool_choice` | Tool selection behavior | |
| 119 | +| `response_format` | Output format (json_object, json_schema) | |
| 120 | +| `stream` | Enable streaming | |
| 121 | + |
0 commit comments