跳至主要內容

Aim Security

快速入門​

1. 建立新的 Aim Guard​

前往 Aim Application 並建立新的 guard。

在提示時,選擇 API 選項,並為您的 guard 命名。

備註

如果您想在內部部署環境中託管您的 guard,可以在建立 guard 之前先 安裝 Aim Outpost,即可啟用此選項。

2. 設定您的 Aim Guard policies​

在新建立的 guard 頁面中,您可以找到此 guard 的 prompt policy center 參考資訊。

您可以決定要啟用哪些 detections,並為每個 detection 設定 threshold。

資訊

當使用 LiteLLM 搭配 virtual keys 時,可以在 Aim 的 guards 頁面中直接設定特定 key 的 policies,只要在建立 guard 時指定 virtual key alias 即可。

傳送給 Aim 的只會是您 virtual keys 的 aliases(而不是實際的 key secrets)。

3. 在您的 LiteLLM config.yaml 中加入 Aim Guardrail​

在 guardrails 區段下定義您的 guardrails

model_list:
- model_name: gpt-5.6-luna
litellm_params:
model: openai/gpt-5.6-luna
api_key: os.environ/OPENAI_API_KEY

guardrails:
- guardrail_name: aim-protected-app
litellm_params:
guardrail: aim
mode: [pre_call, post_call] # "During_call" is also available
api_key: os.environ/AIM_API_KEY
api_base: os.environ/AIM_API_BASE # Optional, use only when using a self-hosted Aim Outpost
ssl_verify: False # Optional, set to False to disable SSL verification or a string path to a custom CA bundle
inspect_embeddings: false # Optional, set to true to inspect /embeddings input

在 api_key 下,填入您獲發的 API key。該 key 可在 guard 的頁面中找到。 您也可以將 AIM_API_KEY 設為環境變數。

預設情況下,api_base 設為 https://api.aim.security。如果您使用的是自架的 Aim Outpost,可以將 api_base 設為您 Outpost 的 URL。

4. 啟動 LiteLLM Gateway​

litellm --config config.yaml

5. 發出您的第一個請求​

備註

以下範例依賴於在您的 guard 中啟用 PII detection。 您可以調整請求內容,以符合不同 guard 的 policies。

備註

當使用 LiteLLM 搭配 virtual keys 時,需要帶有 virtual key 的 Authorization header。

curl -i http://localhost:4000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.6-luna",
"messages": [
{"role": "user", "content": "hi my email is ishaan@berri.ai"}
],
"guardrails": ["aim-protected-app"]
}'

如果設定正確,由於 ishaan@berri.ai 會被 Aim Guard 偵測為 PII,您將會收到類似下方的回應,並帶有 400 Bad Request 狀態碼:

{
"error": {
"message": "\"ishaan@berri.ai\" detected as email",
"type": "None",
"param": "None",
"code": "400"
}
}

進階​

Aim Guard 提供使用者專屬的 Guardrail 政策,讓您能將量身打造的政策套用到個別使用者。 若要使用此功能,請在請求酬載中加入終端使用者的電子郵件,方法是設定您的請求中 x-aim-user-email 標頭。

curl -i http://localhost:4000/v1/chat/completions \
-H "Content-Type: application/json" \
-H "x-aim-user-email: ishaan@berri.ai" \
-d '{
"model": "gpt-5.6-luna",
"messages": [
{"role": "user", "content": "hi what is the weather"}
],
"guardrails": ["aim-protected-app"]
}'