Django
This guide covers a function-based synchronous view that uploads a file to/convert/raw, maps contract status codes from API to idiomatic Django responses, and a async def variant with httpx for Django 4.1+.
Synchronous view (function-based)
Userequests because Django’s synchronous views already run on a dedicated WSGI worker; there is no benefit in putting async in there.
The
@csrf_exempt decorator assumes that this endpoint is consumed by an API client (mobile app or another service), not by a browser form within the same Django session. If you expose it to a form with a user session, use the normal CSRF token instead of exempting it.Vista basada en clase (alternativa)
If you prefer the CBV style, the same flow fits well in aView:
Vista async (Django 4.1+)
Django 4.1+ supportsasync def in views. Combined with httpx.AsyncClient, avoid blocking the worker while waiting for a response from API (useful if your deployment uses ASGI, e.g. behind Uvicorn/Daphne).
URLs
Settings
Production
Timeouts
It will separate the connection timeout from the reading timeout. Large documents inquality mode may take longer than the default of requests:
Retries with exponential backoff
Just retry429 and 5xx. For the rest of the 4xx, I corrected the request instead of retrying:
Large files with BYOS (output_url)
For large documents, avoid passing the entire Markdown through the body of your Django view: generate a pre-signed URL %0005%% from your own storage (S3, R2, etc.) and pass it as output_url. API uploads the result there directly and returns a small JSON instead of the full Markdown. This also auto-activates response_format=json, output_encoding=zstd and slim=true.
