Skip to main content

Installation

Requires Python 3.8+. The SDK uses httpx for HTTP communication.

Quick Start

Context Manager

The client supports Python’s with statement for automatic resource cleanup:

Authentication

The SDK requires an API key. You can provide it in two ways:
If no API key is found, an 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.
Returns: DetectionResult

client.close()

Closes the client and releases all HTTP connections. The instance cannot be used after calling this method.

DetectionResult

The detect() method returns a frozen dataclass with these attributes:

Error Handling

All exceptions inherit from PromptInspectorError:

Full Example

View on GitHub

Find the SDK source code, report issues, and contribute.