Python SDK for CrowdStrike AIDR.
pip install crowdstrike-aidrPython v3.12 or greater.
from crowdstrike_aidr import AIGuard
client = AIGuard(
base_url_template="https://api.crowdstrike.com/aidr/{SERVICE_NAME}",
token="my API token"
)
response = client.guard_chat_completions(
guard_input={
"messages": [
{"role": "user", "content": "Hello, world!"}
]
}
)The SDK uses httpx.Timeout for timeout configuration. By default, requests
have a timeout of 60 seconds with a 5 second connection timeout.
You can configure timeouts in two ways:
Set a default timeout for all requests made by the client:
import httpx
from crowdstrike_aidr import AIGuard
# Using a float (total timeout in seconds).
client = AIGuard(
base_url_template="https://api.crowdstrike.com/aidr/{SERVICE_NAME}",
token="my API token",
timeout=30.0,
)
# Using httpx.Timeout for more granular control.
client = AIGuard(
base_url_template="https://api.crowdstrike.com/aidr/{SERVICE_NAME}",
token="my API token",
timeout=httpx.Timeout(timeout=60.0, connect=10.0),
)Override the timeout for a specific request:
# Using a float (total timeout in seconds).
response = client.guard_chat_completions(
guard_input={"messages": [...]},
timeout=120.0
)
# Using httpx.Timeout for more granular control.
response = client.guard_chat_completions(
guard_input={"messages": [...]},
timeout=httpx.Timeout(timeout=120.0, connect=15.0)
)The SDK automatically retries failed requests with exponential backoff. By
default, the client will retry up to 2 times. Set max_retries during client
creation to change this.
from crowdstrike_aidr import AIGuard
client = AIGuard(
base_url_template="https://api.crowdstrike.com/aidr/{SERVICE_NAME}",
max_retries=5 # Retry up to 5 times.
)