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
string
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.
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.
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.boolean
default:"false"
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.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 API version identifier (e.g.,
"4.0" for Pangram 4).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.
string
Dashboard link. Only present when
public_dashboard_link is True.list
List of text windows and their classifications. Each window contains:
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[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.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.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.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.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.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.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.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.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.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.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.string
required
The text to check for plagiarism.
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.
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.