Zum Hauptinhalt springen

Modellzugriff steuern

Modelle nach virtuellem Schlüssel einschränken​

Erlaubte Modelle fĂźr einen SchlĂźssel mit dem Parameter models festlegen

curl 'http://0.0.0.0:4000/key/generate' \
--header 'Authorization: Bearer <your-master-key>' \
--header 'Content-Type: application/json' \
--data-raw '{"models": ["gpt-3.5-turbo", "gpt-4"]}'
Info

Dieser SchlĂźssel kann nur Anfragen an models stellen, die gpt-3.5-turbo oder gpt-4 sind

Verifizieren Sie, dass dies korrekt eingestellt ist durch

curl -i https://:4000/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-1234" \
-d '{
"model": "gpt-4",
"messages": [
{"role": "user", "content": "Hello"}
]
}'

API-Referenz​

Modelle nach team_id einschränken​

litellm-dev kann nur auf azure-gpt-3.5 zugreifen

1. Erstellen Sie ein Team Ăźber /team/new

curl --location 'https://:4000/team/new' \
--header 'Authorization: Bearer <your-master-key>' \
--header 'Content-Type: application/json' \
--data-raw '{
"team_alias": "litellm-dev",
"models": ["azure-gpt-3.5"]
}'

# returns {...,"team_id": "my-unique-id"}

2. Erstellen Sie einen SchlĂźssel fĂźr das Team

curl --location 'https://:4000/key/generate' \
--header 'Authorization: Bearer sk-1234' \
--header 'Content-Type: application/json' \
--data-raw '{"team_id": "my-unique-id"}'

3. Testen

curl --location 'http://0.0.0.0:4000/chat/completions' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer sk-qo992IjKOC2CHKZGRoJIGA' \
--data '{
"model": "BEDROCK_GROUP",
"messages": [
{
"role": "user",
"content": "hi"
}
]
}'
{"error":{"message":"Invalid model for team litellm-dev: BEDROCK_GROUP.  Valid models for team are: ['azure-gpt-3.5']\n\n\nTraceback (most recent call last):\n  File \"/Users/ishaanjaffer/Github/litellm/litellm/proxy/proxy_server.py\", line 2298, in chat_completion\n    _is_valid_team_configs(\n  File \"/Users/ishaanjaffer/Github/litellm/litellm/proxy/utils.py\", line 1296, in _is_valid_team_configs\n    raise Exception(\nException: Invalid model for team litellm-dev: BEDROCK_GROUP.  Valid models for team are: ['azure-gpt-3.5']\n\n","type":"None","param":"None","code":500}}%            

API-Referenz​

Modellzugriffsgruppen​

Verwenden Sie Modellzugriffsgruppen, um Benutzern Zugriff auf ausgewählte Modelle zu gewähren und im Laufe der Zeit neue hinzuzufßgen (z. B. mistral, llama-2 usw.)

Schritt 1. Modell, Zugriffsgruppe in config.yaml zuweisen

model_list:
- model_name: gpt-4
litellm_params:
model: openai/fake
api_key: fake-key
api_base: https://exampleopenaiendpoint-production.up.railway.app/
model_info:
access_groups: ["beta-models"] # 👈 Model Access Group
- model_name: fireworks-llama-v3-70b-instruct
litellm_params:
model: fireworks_ai/accounts/fireworks/models/llama-v3-70b-instruct
api_key: "os.environ/FIREWORKS"
model_info:
access_groups: ["beta-models"] # 👈 Model Access Group

SchlĂźssel mit Zugriffsgruppe erstellen

curl --location 'https://:4000/key/generate' \
-H 'Authorization: Bearer <your-master-key>' \
-H 'Content-Type: application/json' \
-d '{"models": ["beta-models"], # 👈 Model Access Group
"max_budget": 0,}'

Test Key

curl -i https://:4000/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-<key-from-previous-step>" \
-d '{
"model": "gpt-4",
"messages": [
{"role": "user", "content": "Hello"}
]
}'

✨ Zugriff auf Wildcard-Modelle steuern​

Steuern Sie den Zugriff auf alle Modelle mit einem bestimmten Präfix (z. B. openai/*).

Verwenden Sie dies, um Benutzern auch Zugriff auf alle Modelle zu gewähren, mit Ausnahme einiger, die sie nicht verwenden sollen (z. B. openai/o1-*).

Info

Das Festlegen von Modellzugriffsgruppen fĂźr Wildcard-Modelle ist eine Enterprise-Funktion.

Preise finden Sie hier

Erhalten Sie hier einen TestschlĂźssel hier

  1. Konfigurieren Sie config.yaml
model_list:
- model_name: openai/*
litellm_params:
model: openai/*
api_key: os.environ/OPENAI_API_KEY
model_info:
access_groups: ["default-models"]
- model_name: openai/o1-*
litellm_params:
model: openai/o1-*
api_key: os.environ/OPENAI_API_KEY
model_info:
access_groups: ["restricted-models"]
  1. SchlĂźssel mit Zugriff auf default-models generieren
curl -L -X POST 'http://0.0.0.0:4000/key/generate' \
-H 'Authorization: Bearer sk-1234' \
-H 'Content-Type: application/json' \
-d '{
"models": ["default-models"],
}'
  1. Testen Sie den SchlĂźssel
curl -i https://:4000/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-<key-from-previous-step>" \
-d '{
"model": "openai/gpt-4",
"messages": [
{"role": "user", "content": "Hello"}
]
}'

Rollenbasierte Zugriffskontrolle (RBAC)​