Skip to main content

Installation

SDK 1.1.0 adds native image and video methods alongside text, document extraction, bulk, and plagiarism. Upgrade the SDK to use the media methods below.

Pangram

The main client class for interacting with the Pangram Labs API. PangramText remains available for legacy imports, but Pangram is the recommended client name.

Constructor

string
Your API key for Pangram Labs. If not provided, the PANGRAM_API_KEY environment variable will be used.
Raises ValueError if the API key is not provided and not set in the environment.
pangram-4 selects the Pangram 4 text series, and pangram-image-1 selects the Image 1 series. Minor versions can change within the selected series without changing the selector. Read the result’s version field to identify the model version used; image results determined solely by validated provenance have version=None.

Account APIs

Requires pangram-sdk 1.2.0 or later.

Account read errors

Each method accepts a positive finite keyword-only timeout, defaulting to 10 seconds for connection establishment and read inactivity. This is not a total request deadline. Requests disable redirects and do not automatically retry. Invalid input raises ValueError. HTTP, transport, and malformed-response failures raise PangramRequestError, a ValueError subclass exported from pangram. Its status_code identifies HTTP errors and may be None for transport or response-format failures. Its retry_after preserves a numeric Retry-After delay in seconds; wait for that delay before retrying a read after HTTP 429.

Native SDK methods

predict_image()

Submit one image and wait for its analysis.
Parameters
str | PathLike | bytes | bytearray | BinaryIO
required
Image path, raw bytes, or an open binary file, up to 32 MiB. Strings are paths. The SDK handles base64 encoding. Caller-owned files remain open and are read from their current position.
string
required
Required keyword-only selector: pangram-image-1, pangram-image-flash-1, pangram-image-0.2, or default.
float
default:"300"
Keyword-only timeout in seconds for submission and polling combined. Must be positive and finite.
float
default:"0.5"
Keyword-only delay in seconds between status requests. Must be positive and finite; values below 0.1 are clamped to 0.1.
Returns An ImageResult dictionary after successful analysis:
string
The accepted task ID.
string
STAGE_SUCCESS.
string
One of AI Detected, Likely AI, Unsure, Likely No AI, No AI, or Partially AI.
float | None
Model score from 0 to 1; None for a provenance-only result.
string | None
Low, Medium, or High; None for a provenance-only result.
string
model for model inference or c2pa when validated content provenance determines the result.
string | None
Image model display version, such as Pangram Image 1.0; None for a provenance-only result.
dict | None
Patch scores in grid and their input-pixel spacing in patch_stride; None for a provenance-only result.
dict
Content provenance (C2PA), software, and camera metadata when available.
dict | None
Metadata-stripped JPEG data_url, width, and height, or None.

submit_image()

Submit one image and receive a task ID.
Parameters
str | PathLike | bytes | bytearray | BinaryIO
required
Image path, raw bytes, or an open binary file, up to 32 MiB. Strings are paths. The SDK handles base64 encoding. Caller-owned files remain open and are read from their current position.
string
required
Required keyword-only selector: pangram-image-1, pangram-image-flash-1, pangram-image-0.2, or default.
float
default:"60"
Keyword-only timeout in seconds for the submission request. Must be positive and finite.
Returns A MediaTaskSubmission dictionary without polling:
string
The accepted task UUID. Save it to retrieve status or wait for the result. Submission is sent once, with no automatic retry.

get_image_status()

Retrieve the current task status with one request.
Parameters
string
required
The UUID returned by submit_image().
float
default:"10"
Keyword-only timeout in seconds for the status request. Must be positive and finite.
Returns An ImageTaskStatus dictionary containing task_id and stage. Processing stages are STAGE_IMAGE_INFERENCE and STAGE_IMAGE_FINALIZING. A successful task includes the ImageResult fields described under predict_image(); a failed task has stage="STAGE_FAILED" and an error object with error, error_code, and retryable. This method returns failed task statuses without raising MediaTaskError.

wait_for_image()

Poll an existing task until analysis completes.
Parameters
string
required
The UUID returned by submit_image().
float
default:"300"
Keyword-only timeout in seconds for polling. Must be positive and finite.
float
default:"0.5"
Keyword-only delay in seconds between status requests. Must be positive and finite; values below 0.1 are clamped to 0.1.
Returns An ImageResult dictionary with the same fields as predict_image(). A failed task raises MediaTaskError, with task_id and error attributes. A timeout raises MediaTaskTimeout, with the accepted task_id available for resuming.

predict_video()

Upload one video and wait for its analysis.
Parameters
str | PathLike | bytes | bytearray | BinaryIO
required
MP4, MOV, or WebM path, raw bytes, or a seekable binary file, up to 500 MiB. Paths stream from disk. Caller-owned files remain open and are read from their current position.
string | None
default:"None"
Keyword-only upload filename, including its .mp4, .mov, or .webm extension. Required for bytes or an unnamed stream; otherwise inferred from the file.
float
default:"600"
Keyword-only timeout in seconds for submission and polling combined. Must be positive and finite.
float
default:"1"
Keyword-only delay in seconds between status requests. Must be positive and finite; values below 0.1 are clamped to 0.1.
Returns A VideoResult dictionary using response schema 1.1:
string
The accepted task ID.
string
STAGE_SUCCESS.
string
1.1.
string
Task creation time in ISO 8601 format.
string
Overall verdict: no_ai, mixed, ai, or unsure.
string
Display headline: No AI detected, AI Detected, or Unsure.
string
Supporting explanation for display.
string | None
Low, Medium, or High when supplied; otherwise None or omitted.
string
model for frame analysis or c2pa when validated content provenance determines the result.
string | None
Frame model ID image-flash-1, or None for a provenance-only result.
dict
file_name, content_type, size_bytes, duration_ms, width, height, and optional native fps. The uploaded video is not returned.
dict
Content provenance (C2PA), software, and camera metadata when available.
dict | None
Effective frame sampling rate in fps, or None when frame analysis was not used.
list[dict]
Sampled frames with frame_id, timestamp_ms, and an image result. Frame predictions use Human, AI Detected, Mixed, or Unsure.
list[dict]
Timeline segments with id, range.start_ms, range.end_ms, prediction_short, prediction, and frame_ids. Segment labels are human, likely_human, unsure, likely_ai, ai, or mixed.
float
Duration shares from 0 to 1. Additional fraction_unsure, fraction_likely_ai, and fraction_likely_human fields are included when nonzero. All applicable shares sum to one.
integer
On success, both equal the number of returned frames.
See the video response example for frame and segment entries.

submit_video()

Upload one video and receive a task ID.
Parameters
str | PathLike | bytes | bytearray | BinaryIO
required
MP4, MOV, or WebM path, raw bytes, or a seekable binary file, up to 500 MiB. Paths stream from disk. Caller-owned files remain open and are read from their current position.
string | None
default:"None"
Keyword-only upload filename, including its .mp4, .mov, or .webm extension. Required for bytes or an unnamed stream; otherwise inferred from the file.
float
default:"300"
Keyword-only timeout in seconds for the upload request. Must be positive and finite.
Returns A MediaTaskSubmission dictionary without polling:
string
The accepted task UUID. Save it to retrieve status or wait for the result. Submission is sent once, with no automatic retry.

get_video_status()

Retrieve the current task status with one request.
Parameters
string
required
The UUID returned by submit_video().
float
default:"10"
Keyword-only timeout in seconds for the status request. Must be positive and finite.
Returns A VideoTaskStatus dictionary using response schema 1.1, containing task_id and stage. Processing stages are STAGE_VIDEO_EXTRACTION, STAGE_VIDEO_INFERENCE, and STAGE_VIDEO_FINALIZING. Progress responses include frames_processed and total_frames when available. A successful task includes the VideoResult fields described under predict_video(); a failed task has stage="STAGE_FAILED" and an error object with error, error_code, and retryable. This method returns failed task statuses without raising MediaTaskError.

wait_for_video()

Poll an existing task until analysis completes.
Parameters
string
required
The UUID returned by submit_video().
float
default:"600"
Keyword-only timeout in seconds for polling. Must be positive and finite.
float
default:"1"
Keyword-only delay in seconds between status requests. Must be positive and finite; values below 0.1 are clamped to 0.1.
Returns A VideoResult dictionary with the same fields as predict_video(). A failed task raises MediaTaskError, with task_id and error attributes. A timeout raises MediaTaskTimeout, with the accepted task_id available for resuming.

Media timeouts and errors

Prediction timeouts budget submission and polling. Polling intervals below 0.1 seconds are clamped to 0.1; values must be positive and finite. The SDK retries polling on temporary transport errors and HTTP 429/5xx responses, honoring numeric Retry-After delays. MediaRequestError exposes the HTTP status_code when available. File-opening errors use Python’s normal exceptions. Keep the accepted task ID after a timeout. Media submission does not support idempotency keys, and another submission can create another billable task. The SDK never automatically retries a submission.

list_models()

List the detection models available to this API key.
The returned list[str] preserves server order and reflects both the account’s entitlements and current model availability. Do not hard-code the catalog or assume every API key sees the same values. Use one returned selector as the keyword-only model argument on text and bulk requests.
The model argument is temporarily optional for backward compatibility. Omitting it preserves the existing wire payload, selects Pangram’s server default, and emits a DeprecationWarning. Pass model="default" or another value from list_models() in new code.

predict()

Classify text as AI-generated, AI-assisted, or human-written. predict() submits an async inference task, polls until the task completes, and returns the completed task payload.
Parameters
string
required
The text to be classified.
string
Keyword-only model selector returned by list_models(). Pass "default" to follow Pangram’s current default model.
Whether to include a public dashboard link in the completed response.
float
default:"300"
Maximum number of seconds to wait for the async task to complete.
float
default:"0.5"
Number of seconds to wait between polling attempts. Values below 0.1 are clamped to 0.1.
Returns A dictionary with the following fields after the task reaches STAGE_SUCCESS:
string
Terminal async task stage. Successful responses return "STAGE_SUCCESS".
string
The analyzed text returned by the model. Pangram 4 may normalize the submitted text before inference; window offsets refer to this value.
string
The model version used for this result (e.g., "4.1" or "4.0"). Minor versions can change within the selected model series.
string
Classification headline summarizing the result.
string
Long-form prediction string describing the classification.
string
Short-form prediction string. Pangram 4 returns "AI", "Human", or "Mixed".
float
Fraction of text classified as AI-written (0.0–1.0).
float
Fraction of text classified as AI-assisted (0.0–1.0).
float
Fraction of text classified as human-written (0.0–1.0).
integer
Number of text segments classified as AI.
integer
Number of text segments classified as AI-assisted.
integer
Number of text segments classified as human.
Dashboard link. Only present when public_dashboard_link is True.
list
List of text windows and their classifications. Each window contains:
Results remain normal dictionaries. Typed applications can import PredictionResult and PredictionWindow from pangram. Raises ValueError if the API returns an error, the task fails, or the response is invalid. Raises TimeoutError if the task does not complete before timeout.
Classify text and include a public dashboard link in the completed response.
This is equivalent to:
The timeout, poll_interval, and keyword-only model parameters have the same behavior as predict().

submit_bulk()

Submit a Bulk API job for asynchronous AI detection across many inputs. Provide exactly one of text or items. Bulk jobs are processed asynchronously. Completion time depends on the number and length of submitted items and current system load. Use get_bulk_status() or wait_for_bulk() to monitor progress. Use text=[...] for plain string inputs, or items=[{"id": "...", "text": "..."}] when you want customer IDs returned with status and results. Do not pass both.
Parameters
list[string]
List of input texts. Use this shape when you do not need customer item IDs.
list[dict]
List of item dictionaries. Each item must include text and may include a unique customer-defined id.
string
Keyword-only model selector returned by list_models(). Applies to the entire bulk job; per-item model selectors are not supported.
Returns
string
The ID of the bulk job.
string
Initial status. Usually queued; returns failed if every item failed immediate validation.
integer
Total number of submitted items.
list
Items accepted for processing. Each item includes index, optional id, and task_id.
list
Items that failed immediate validation. Each item includes index, optional id, task_id: None, stage, and error.

wait_for_bulk()

Poll a bulk job until it reaches a terminal status.
Terminal statuses are succeeded, failed, and partial. Completion time depends on the number and length of submitted items and current system load. Parameters
string
required
The bulk job ID returned by submit_bulk().
float
default:"3600"
Maximum number of seconds to wait for terminal completion.
float
default:"0.5"
Number of seconds to wait between polling attempts. Values below 0.1 are clamped to 0.1.
Returns The same dictionary returned by get_bulk_status() after the job reaches a terminal status. Raises TimeoutError if the job does not complete before timeout.

get_bulk_status()

Fetch the current status and counters for a bulk job.
Returns
string
The ID of the bulk job.
string
One of queued, running, succeeded, failed, or partial.
integer
Total number of submitted items.
integer
Number of items accepted for processing.
integer
Number of items that completed successfully.
integer
Number of items that failed.
string
Job creation timestamp as Unix epoch seconds encoded as a string.
string
Job completion timestamp as Unix epoch seconds encoded as a string. None while the job is not terminal.

get_bulk_items()

Fetch paginated item metadata for a bulk job.
Parameters
string
required
The bulk job ID returned by submit_bulk().
integer
default:"0"
Zero-based item offset.
integer
default:"100"
Maximum number of items to return. The API allows up to 1000.
Returns A dictionary containing bulk_id, offset, limit, total_items, and items. Each item includes index, optional id, task_id, stage, and optional error.

get_bulk_results()

Fetch all available results for a bulk job.
Parameters
string
required
The bulk job ID returned by submit_bulk().
integer
default:"1000"
Number of submitted item slots to request per API call. The API allows up to 1000.
Returns A dictionary containing bulk_id, total_items, items, and failed_items aggregated across every results page. Successful completed items include result with the same shape returned by predict(). In-progress items have result set to None. get_bulk_results() materializes all pages into memory. For large jobs, use get_bulk_results_page() in a loop and process each page as it arrives. The SDK returns this dictionary as BulkResults; successful item results use PredictionResult.

get_bulk_results_page()

Fetch one paginated results page for a bulk job.
Use this when you need incremental page-level inspection before fetching or storing the full result set.
Parameters
string
required
The bulk job ID returned by submit_bulk().
integer
default:"0"
Zero-based submitted-item offset.
integer
default:"100"
Maximum number of submitted item slots to return. The API allows up to 1000.
Returns A dictionary containing bulk_id, offset, limit, total_items, items, and failed_items for the requested page. The SDK returns this dictionary as BulkResultsPage.

check_plagiarism()

Check text for potential plagiarism against a database of online content.
Parameters
string
required
The text to check for plagiarism.
Returns A dictionary with the following fields:
string
The input text.
boolean
Whether plagiarism was detected.
list
List of detected plagiarized content with source URLs.
integer
Total number of sentences checked.
list
List of sentences detected as plagiarized.
float
Percentage of text detected as plagiarized.
Raises ValueError if the API returns an error.

Typed response contracts

The SDK ships a py.typed marker and exports its public TypedDict contracts from pangram:
The runtime values remain ordinary dictionaries and lists; these types provide static checking without changing existing access patterns.

Deprecated Methods

The following SDK compatibility methods are deprecated. Use predict() for one-off calls or submit_bulk() for asynchronous bulk jobs.

predict_short() Deprecated

Forwards to predict() and returns the current async result schema.

batch_predict() Deprecated

Calls predict() once per input text. Use submit_bulk() for asynchronous bulk jobs.

Removed Legacy Methods

predict_extended() and predict_sliding_window() are no longer part of the current pangram-sdk. Use predict() for current AI detection and segment-level results.