Sync & Async Client

UiForm offers both synchronous and asynchronous client interfaces, making it versatile for different application needs. The asynchronous client (AsyncUiForm) is ideal for high-performance, non-blocking applications where multiple tasks run concurrently. For simpler or blocking operations, the synchronous client (UiForm) provides a straightforward approach.

Here’s how you can use both:

# Async client
from uiform import AsyncUiForm

async def fetch_models():
    uiclient = AsyncUiForm()
    models = await uiclient.models.list()
    print(models)

# Sync client
from uiform import UiForm

client = UiForm()
models = client.models.list()
print(models)

Both clients provide the same core functionality, enabling you to list models, create messages, extract data from documents, and more, with the flexibility to match your application’s concurrency model.

Rate Limits

UiForm implements rate limiting to ensure stable service for all users. The API uses a rolling window rate limit with the following configuration:

  • 300 requests per 60-second window
  • Applies across the following API endpoints:
    • POST /api/v1/documents/extractions
    • POST /api/v1/documents/create_messages

When you exceed the rate limit, the API will return a 429 Too Many Requests response. The response headers will include:

Status 429 - {'detail': 'Rate limit exceeded. Please try again later.'}

For high-volume applications, we can provide a dedicated plan. Contact us for more information.

Modality

LLM works with text and image data. UiForm converts documents into different modalities, based on the document type.

Native modalities

Here are the list of native modalities supported by UiForm:

You can also use the modality parameter to specify the modality of the document and override the default modality.

import json
from uiform.client import UiForm

with open("booking_confirmation_json_schema.json", "r") as f:
    json_schema = json.load(f)

client = UiForm()

response = client.documents.extract(
    json_schema = json_schema,
    document="booking_confirmation.jpg",
    model="gpt-4o-mini-2024-07-18",
    temperature=0,
    modality='text' # The image will be converted to text (with an OCR model) before being sent to the LLM
)

Idempotency

Idempotency in UIForm ensures that repeated API requests with the same idempotency key are handled consistently without duplicating processing or generating unintended side effects. When a request is made, UIForm checks if a record with the same idempotency key exists in its database. If a match is found:

  1. If the request content matches the original request: The previously computed response is returned.
  2. If the request content differs: An error is returned, indicating a conflict.
  3. If the original request is still being processed: The API prevents concurrent execution by blocking duplicate processing.

By leveraging idempotency, UIForm ensures each document or operation is processed only once, returning consistent results and avoiding unnecessary computation.

Text Operations

When processing documents, you may want to provide additional context to help the AI better understand the document. This could be previous communications, related documents, or any other relevant information.

Regex Instructions

Define custom patterns to extract specific data types:

  • Document Numbers: Extract invoice numbers, PO numbers, etc.
  • Custom Formats: Identify company-specific identifiers
  • Validation: Ensure extracted data matches expected patterns

Best Practices

  • Use consistent formatting in regex patterns
  • Only use regex patterns to extract data that is not easily extracted by the LLM

API Reference

text_operations
TextOperations Object

Mathematical operations performed on the text to help the AI better extract the data.

Image Operations (Coming Soon)

When processing images, several factors can affect the LLM’s ability to accurately interpret and extract information. The image_operations parameter allows you to preprocess images to improve extraction quality.

API Reference

image_operations
ImageOperations Object

Image preprocessing operations to optimize document analysis.