Documentation
API Reference
Playground
Chat completionsResponsesSystem One
Document classificationEmbeddings

Studio API

Upload fileList filesRetrieve fileDelete file
Create jobRetrieve job

Search

Create vector storeList vector storesRetrieve vector storeModify vector storeDelete vector storeAdd file to vector storeList files in vector storeRetrieve file in vector storeRemove file from vector storeCreate file batchRetrieve file batchList files in file batchCancel file batchSearch vector store
Create response

Document classification


Examples

Request

# pip install openai
import base64
import json
from openai import OpenAI

client = OpenAI(
    api_key="UPSTAGE_API_KEY",
    base_url="https://api.upstage.ai/v1/document-classification"
)

def encode_img_to_base64(img_path):
    with open(img_path, 'rb') as img_file:
        img_bytes = img_file.read()
        base64_data = base64.b64encode(img_bytes).decode('utf-8')
        return base64_data

filepath = "./your_document.png"
base64_data = encode_img_to_base64(filepath)

response = client.chat.completions.create(
    model="document-classify",
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "image_url",
                    "image_url": {"url": f"data:application/octet-stream;base64,{base64_data}"}
                }
            ]
        }
    ],
    response_format={
        "type": "json_schema",
        "json_schema": {
            "name": "document-classify",
            "schema": {
                "type": "string",
                "oneOf": [
                    {"const": "invoice", "description": "Commercial invoice with itemized charges and billing information"},
                    {"const": "receipt", "description": "Receipt showing purchase transaction details"},
                    {"const": "contract", "description": "Legal agreement or contract document"},
                    {"const": "cv", "description": "Curriculum vitae or resume"},
                    {"const": "others", "description": "Other"}
                ]
            }
        }
    }
)

print(response) 

Response

{
  "id": "8f111e4201de097efa38d4a4d174c001",
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "logprobs": None,
      "message": {
        "content": "invoice",
        "refusal": None,
        "role": "assistant",
        "annotations": None,
        "audio": None,
        "function_call": None,
        "tool_calls": [{
          "id": None,
          "function": {
            "arguments": {"document_type": {"_value": "invoice", "confidence_score": 1.0}},
            "name": "additional_values"
          },
          "type": "function"
        }]
      }
    }
  ],
  "created": 1756270462,
  "model": "document-classify-261113",
  "object": None,
  "service_tier": None,
  "system_fingerprint": None,
  "usage": {
    "completion_tokens": 6,
    "prompt_tokens": 1765,
    "total_tokens": 1771,
    "completion_tokens_details": None,
    "prompt_tokens_details": None
  }
}

Asynchronous API

Submit multiple documents to universal information extraction as an async job and retrieve the results by job ID.

Embeddings

Get high-quality vector representations for semantic search, clustering, and multilingual classification using Upstage embeddings.

On this page

Document classificationExamples
    POST
    /document-classification
    /document-classification

    The Authorization access token

    messages*
    array

    Item 1
    object

    content
    array

    Item 1
    object

    image_url
    object

    response_format*
    object

    json_schema
    object

    schema*
    object

    oneOf
    array

    split_criteria
    array

    Item 1
    object

    Authorization

    Authorization
    Required
    Bearer <token>

    In: header

    Request Body

    application/jsonRequired

    model
    Required
    string

    A string value indicating the model used for inference. We recommend using the alias document-classify, which always points to the latest stable model. You may also specify a particular model version, but please note that models are frequently updated, and services tied to specific versions may be affected when those versions are deprecated. Available snapshot models are listed in the capabilities document.

    messages
    Required
    array<object>

    A list of messages

    response_format
    Required
    object

    A JSON object containing the target class.

    split
    Beta
    boolean

    When set to true, the model will split the document into multiple documents at the boundaries of changing document types.

    Default: false

    split_criteria
    Beta
    array<object>

    Additional criteria for splitting the document. For example, providing a unique identifier like 'card_id' can help split documents even if they are of the same type but distinct entities.