Installation
Requires Python 3.8+. The SDK uses httpx for HTTP communication.
Quick Start
Context Manager
The client supports Python’swith statement for automatic resource cleanup:
Authentication
The SDK requires an API key. You can provide it in two ways:- Direct Parameter
- Environment Variable
AuthenticationError is raised immediately.
Client Reference
PromptInspector(api_key, base_url, timeout)
Creates a new SDK client instance.
str | None
default:"None"
API key for authentication. Falls back to the
PMTINSP_API_KEY environment variable if not provided.str | None
default:"https://promptinspector.io"
Base URL of the Prompt Inspector API server.
int
default:"30"
Default request timeout in seconds.
client.detect(text, *, timeout=None)
Sends text to the detection API and returns a DetectionResult.
str
required
The text to analyze. Must be a non-empty string.
int | None
default:"None"
Per-request timeout override in seconds. Uses the client default if not specified.
DetectionResult
client.close()
Closes the client and releases all HTTP connections. The instance cannot be used after calling this method.
DetectionResult
Thedetect() method returns a frozen dataclass with these attributes:
Error Handling
All exceptions inherit fromPromptInspectorError:
Full Example
View on GitHub
Find the SDK source code, report issues, and contribute.

