extract_receipt_async
Submit a receipt image or PDF for asynchronous AI extraction of receipt data. Receive a job ID to poll for status, with optional webhook notification. Returns extracted data for further processing.
Instructions
Submit a receipt for async AI extraction. Returns a job ID for polling.
Use get_receipt_job to check status and get_receipt_job_result for the result.
Args: image_base64: Base64-encoded receipt image or PDF. filename: Original filename. content_type: MIME type (default: image/jpeg). callback_url: Optional webhook URL to receive the result.
Returns: JSON with jobId and status.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| image_base64 | Yes | ||
| filename | No | receipt.jpg | |
| content_type | No | image/jpeg | |
| callback_url | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- mcp/src/docgen_mcp/server.py:800-822 (handler)Main handler function for the extract_receipt_async MCP tool. Decodes base64 image bytes and calls dg.receipts.extract_async() to submit the receipt for async AI extraction, returning a job ID for polling.
def extract_receipt_async( image_base64: str, filename: str = "receipt.jpg", content_type: str = "image/jpeg", callback_url: str | None = None, ) -> str: """Submit a receipt for async AI extraction. Returns a job ID for polling. Use get_receipt_job to check status and get_receipt_job_result for the result. Args: image_base64: Base64-encoded receipt image or PDF. filename: Original filename. content_type: MIME type (default: image/jpeg). callback_url: Optional webhook URL to receive the result. Returns: JSON with jobId and status. """ dg = _get_client() file_bytes = base64.b64decode(image_base64) result = dg.receipts.extract_async(file_bytes, filename, content_type, callback_url=callback_url) return json.dumps(result, default=str) - mcp/src/docgen_mcp/server.py:799-800 (registration)Registration of extract_receipt_async as an MCP tool via the @mcp.tool() decorator on the FastMCP instance.
@mcp.tool() def extract_receipt_async( - mcp/src/docgen_mcp/server.py:28-47 (helper)Helper function _get_client() that lazily initializes the DocGen client, which provides the receipts.extract_async() method used by the handler.
def _get_client(): """Lazy-initialise the DocGen client.""" global _client if _client is None: # Import here so the module can be imported without the SDK installed # (useful for schema introspection) from docgen import DocGen api_key = os.environ.get("DOCGEN_API_KEY", "") if not api_key: raise RuntimeError( "DOCGEN_API_KEY environment variable is required. " "Set it to your DocGen API key before starting the server." ) base_url = os.environ.get("DOCGEN_BASE_URL") kwargs: dict[str, Any] = {"api_key": api_key} if base_url: kwargs["base_url"] = base_url _client = DocGen(**kwargs) return _client