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.
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.
The text to be classified.
Whether to include a public dashboard link in the completed response.
Maximum number of seconds to wait for the async task to complete.
Number of seconds to wait between polling attempts. Values below
0.1 are clamped to 0.1.STAGE_SUCCESS:
Terminal async task stage. Successful responses return
"STAGE_SUCCESS".The input text.
The API version identifier (e.g.,
"3.0").Classification headline summarizing the result.
Long-form prediction string describing the classification.
Short-form prediction string (
"AI", "AI-Assisted", "Human", "Mixed").Fraction of text classified as AI-written (0.0–1.0).
Fraction of text classified as AI-assisted (0.0–1.0).
Fraction of text classified as human-written (0.0–1.0).
Number of text segments classified as AI.
Number of text segments classified as AI-assisted.
Number of text segments classified as human.
Dashboard link. Only present when
public_dashboard_link is True.List of text windows and their classifications. Each window contains:
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 and poll_interval 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 input texts. Use this shape when you do not need customer item IDs.
List of item dictionaries. Each item must include
text and may include a unique customer-defined id.The ID of the bulk job.
Initial status. Usually
queued; returns failed if every item failed immediate validation.Total number of submitted items.
Items accepted for processing. Each item includes
index, optional id, and task_id.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
The bulk job ID returned by
submit_bulk().Maximum number of seconds to wait for terminal completion.
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.The ID of the bulk job.
One of
queued, running, succeeded, failed, or partial.Total number of submitted items.
Number of items accepted for processing.
Number of items that completed successfully.
Number of items that failed.
Job creation timestamp as Unix epoch seconds encoded as a 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.The bulk job ID returned by
submit_bulk().Zero-based item offset.
Maximum number of items to return. The API allows up to
1000.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.The bulk job ID returned by
submit_bulk().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.
get_bulk_results_page()
Fetch one paginated results page for a bulk job.The bulk job ID returned by
submit_bulk().Zero-based submitted-item offset.
Maximum number of submitted item slots to return. The API allows up to
1000.bulk_id, offset, limit, total_items, items, and failed_items for the requested page.
check_plagiarism()
Check text for potential plagiarism against a database of online content.The text to check for plagiarism.
The input text.
Whether plagiarism was detected.
List of detected plagiarized content with source URLs.
Total number of sentences checked.
List of sentences detected as plagiarized.
Percentage of text detected as plagiarized.
ValueError if the API returns an error.
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.