Installation
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
Your API key for Pangram Labs. If not provided, the
PANGRAM_API_KEY environment variable will be used.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
Requirespangram-sdk 1.2.0 or later.
Account read errors
Each method accepts a positive finite keyword-onlytimeout, 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.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.
Required keyword-only selector:
pangram-image-1, pangram-image-flash-1, pangram-image-0.2, or default.Keyword-only timeout in seconds for submission and polling combined. Must be positive and finite.
Keyword-only delay in seconds between status requests. Must be positive and finite; values below
0.1 are clamped to 0.1.ImageResult dictionary after successful analysis:
Image model display version, such as
Pangram Image 1.0; None for a provenance-only result.Patch scores in
grid and their input-pixel spacing in patch_stride; None for a provenance-only result.submit_image()
Submit one image and receive a task ID.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.
Required keyword-only selector:
pangram-image-1, pangram-image-flash-1, pangram-image-0.2, or default.Keyword-only timeout in seconds for the submission request. Must be positive and finite.
MediaTaskSubmission dictionary without polling:
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.Keyword-only timeout in seconds for the status request. Must be positive and finite.
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.Keyword-only delay in seconds between status requests. Must be positive and finite; values below
0.1 are clamped to 0.1.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.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.
Keyword-only upload filename, including its
.mp4, .mov, or .webm extension. Required for bytes or an unnamed stream; otherwise inferred from the file.Keyword-only timeout in seconds for submission and polling combined. Must be positive and finite.
Keyword-only delay in seconds between status requests. Must be positive and finite; values below
0.1 are clamped to 0.1.VideoResult dictionary using response schema 1.1:
file_name, content_type, size_bytes, duration_ms, width, height, and optional native fps. The uploaded video is not returned.Sampled frames with
frame_id, timestamp_ms, and an image result. Frame predictions use Human, AI Detected, Mixed, or Unsure.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.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.submit_video()
Upload one video and receive a task ID.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.
Keyword-only upload filename, including its
.mp4, .mov, or .webm extension. Required for bytes or an unnamed stream; otherwise inferred from the file.Keyword-only timeout in seconds for the upload request. Must be positive and finite.
MediaTaskSubmission dictionary without polling:
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.Keyword-only timeout in seconds for the status request. Must be positive and finite.
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.Keyword-only delay in seconds between status requests. Must be positive and finite; values below
0.1 are clamped to 0.1.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
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.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.
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.
Keyword-only model selector returned by
list_models(). Pass "default" to follow Pangram’s current default model.Number of seconds to wait between polling attempts. Values below
0.1 are clamped to 0.1.STAGE_SUCCESS:
The analyzed text returned by the model. Pangram 4 may normalize the submitted text before inference; window offsets refer to this value.
The model version used for this result (e.g.,
"4.1" or "4.0"). Minor versions can change within the selected model series.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.
predict_with_dashboard_link()
Classify text and include a public dashboard link in the completed response.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 oftext 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.
List of item dictionaries. Each item must include
text and may include a unique customer-defined id.Keyword-only model selector returned by
list_models(). Applies to the entire bulk job; per-item model selectors are not supported.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.succeeded, failed, and partial.
Completion time depends on the number and length of submitted items and current system load.
Parameters
Number of seconds to wait between polling attempts. Values below
0.1 are clamped to 0.1.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.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.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.Number of submitted item slots to request per API call. The API allows up to
1000.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.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.ValueError if the API returns an error.
Typed response contracts
The SDK ships apy.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
predict_short() Deprecated
Forwards topredict() and returns the current async result schema.
batch_predict() Deprecated
Callspredict() 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.