Run multi-step document processing workflows via the Upstage Document Agent API (v2). Two paths:
agt_xxx) from your code.references/agents-and-configs.md.Both paths execute the same way: upload a File → run a Job → poll for results.
python
import os
import time
from openai import OpenAI
client = OpenAI(
api_key=os.environ["UPSTAGE_API_KEY"],
base_url="https://api.upstage.ai/v2"
)
# 1. Upload file
file = client.files.create(
file=open("document.pdf", "rb"),
purpose="user_data"
)
# 2. Create workflow job
job = client.responses.create(
model="agt_BxcRatEWzVYH2yRNtyWynn", # Studio Agent ID
input=[{
"role": "user",
"content": [{"type": "input_file", "file_id": file.id}]
}],
include=["all"] # "all": all step results, "last": final step only
)
# 3. Poll until complete
while job.status in ("queued", "in_progress"):
time.sleep(5)
job = client.responses.retrieve(job.id, include=["all"])
# 4. Print results
if job.status == "completed":
for step in job.output:
print(f"\n=== {step.model} ===")
for content in step.content:
print(content.text)
else:
print(f"Job failed: {job.status}")
# 5. Cleanup
client.files.delete(file.id)
API Key: Always use os.environ["UPSTAGE_API_KEY"]. Get your key at console.upstage.ai/api-keys (keys start with up_).
Base URL: https://api.upstage.ai (Document Agent endpoints live under /v2)
text
Agent (execution unit)
└─ Config (workflow definition: ordered Steps + conditional branching)
└─ Job (execution instance)
├─ File (input document)
└─ Results (per-step output)
ConceptDescriptionID FormatAgentBasic unit of workflow execution. Includes library metadata, publish state, thumbnail, copy stats, and like statsagt_xxxConfigWorkflow attached to an Agent. Defines Steps as a DAG with conditional branching. Immutable once created — create a new Config to change stepscfg_xxx or numeric index ( "1", "2")StepIndividual processing stage: document-parse, information-extract, document-classify, instructUUIDJobResult of executing a Config. Status: in_progress → completed / failed``job_xxxFileUploaded document. Automatically converted to page images on uploadfile_xxx
text
1. Upload file POST /v2/files → get file_id
2. Create Agent POST /v2/agents → get agent_id (skip if using Studio UI)
3. Define Config POST /v2/agents/{id}/configs → define workflow (skip if using Studio UI)
4. Run Job POST /v2/responses → execute pipeline
5. Get results GET /v2/responses/{id} → retrieve output
ModeSettingBehaviorSynchronous(default)Waits until completion, returns JSONBackgroundbackground: trueReturns Job ID immediately, poll for results
Agents with agt_ prefix automatically use background: true.
StatusDescriptionqueuedWaiting to startin_progressProcessingcompletedFinishedfailedError occurred (check failure_message)
Applied to all list endpoints ( /v2/files, /v2/agents, /v2/agents/{id}/jobs, etc.).
ParameterTypeDescriptionafterstringReturn items after this IDbeforestringReturn items before this IDlimitint (≥1)Maximum number of itemsorder``"asc" | "desc"Sort by created_at (default: "asc")
Response shape:
json
{ "object": "list", "data": [...], "first_id": "xxx", "last_id": "yyy", "has_more": true }
All errors share the same structure:
json
{
"error": {
"type": "invalid_request_error",
"message": "No access to agent: agt_xxx",
"param": "agent_id",
"code": null
}
}
HTTPTypeDescription400invalid_request_errorBad request (missing fields, type mismatch, step validation failure)404not_found_errorNon-existent ID409file_status_errorState conflict (creating Job with file still being processed)415unsupported_file_formatUploading e.g. .zip500internal_server_errorServer error
<system-temp>/<input-stem>.agent.json (e.g., /tmp/document.agent.json).<system-temp>/<input-stem>.<step-name>.json (e.g., /tmp/document.document-parse.json, /tmp/document.information-extract.json).agt_. Find yours in the Studio UI or list via GET /v2/agents.include=["all"] to get intermediate step results for debugging; ["last"] for final output only.upstage-builder.upstage-schema-generation.upstage-document-classification.FileContentreferences/files.mdFiles API: upload, get, delete, supported formats, file status, errorsreferences/agents-and-configs.mdAgent CRUD, library metadata, publish/unpublish, thumbnails, likes, Config (workflow) definition with conditional branchingreferences/step-types.mdStep parameters: document-parse, document-classify, information-extract, instruct, schema rulesreferences/preset-agents.mdBuilt-in agents ( schema-generate, class-generate, schema-update) — no agent setup requiredreferences/jobs.mdRun Jobs, poll, list, delete, status values, execution errors, caching, stats APIreferences/examples.mdFull end-to-end curl examples (parse→extract, classify→branch, split, instruct chaining, clone, publish, like)