Skip to main content
Didit Raises $7.5M to Build the Infrastructure for Identity and Fraud
Didit
Back to blog
Blog · March 7, 2026

Boost Didit API Throughput with Python Asyncio

Discover how Python's Asyncio can dramatically enhance the throughput and efficiency of your applications consuming Didit's identity verification APIs.

By DiditUpdated
boost-didit-api-throughput-with-python-asyncio.png

Optimize API Consumption: Python Asyncio enables non-blocking I/O operations, significantly improving the efficiency of applications making numerous API calls to services like Didit for identity verification.

Master Rate Limiting: Implement sophisticated rate-limiting strategies with Asyncio to stay within Didit's API limits, preventing 429 errors and ensuring continuous service availability for high-throughput scenarios.

Build Scalable Solutions: Leverage Asyncio's concurrency model to design robust and scalable systems capable of processing thousands of identity verification requests per second without incurring high infrastructure costs.

Didit's API-First Advantage: Didit's developer-first approach, with clean APIs and an instant sandbox, is ideally suited for integration with asynchronous frameworks, allowing for seamless, high-performance identity verification workflows from ID verification to liveness detection.

The Need for Speed: Why Asyncio for API Consumption?

In today's fast-paced digital world, applications often need to perform numerous external API calls to fulfill their functions. When these calls are blocking, meaning the application waits for each response before proceeding to the next, performance bottlenecks quickly emerge. This is especially true for identity verification services, where a single user onboarding flow might involve multiple API interactions: ID Verification, Passive & Active Liveness checks, 1:1 Face Match, and AML Screening. For businesses with high user volumes, these sequential operations can lead to significant delays and poor user experiences.

Python's asyncio library provides a robust framework for writing concurrent code using the async/await syntax. Unlike traditional multi-threading, which can introduce complexities like the Global Interpreter Lock (GIL) for CPU-bound tasks, asyncio is designed for I/O-bound operations. API calls are inherently I/O-bound (waiting for network responses), making asyncio an ideal candidate to supercharge your application's ability to consume external APIs efficiently. By allowing your program to perform other tasks while waiting for API responses, asyncio can dramatically increase throughput without requiring a complete rewrite of your application's architecture into a distributed system.

Understanding Didit's API Landscape and Rate Limits

Didit, as an AI-native identity platform, offers a comprehensive suite of APIs for identity verification, including ID Verification (OCR, MRZ, barcodes), Passive & Active Liveness, 1:1 Face Match, AML Screening & Monitoring, and more. Our API is designed for high performance and reliability, but like all robust APIs, it employs rate limiting to ensure stability and fair usage across all clients. Understanding these limits is crucial for any high-throughput consumer.

Didit enforces both global and endpoint-specific rate limits. For instance, global limits are typically 300 requests per minute per application for both GET and Write/Delete endpoints. More restrictive limits apply to high-impact operations, such as 600 RPM for POST /v2/session/ (for creating verification workflows) and 100 RPM for GET /v2/session/<id>/decision/ (to retrieve session decisions). When these limits are exceeded, the API returns a 429 Too Many Requests status code, along with helpful headers like X-RateLimit-Limit, X-RateLimit-Remaining, and Retry-After (epoch seconds) to guide your backoff strategy.

Implementing asyncio allows you to manage these rate limits much more effectively. Instead of a single blocking thread hitting the limit, an asynchronous application can intelligently queue requests, implement exponential backoff, and retry failed calls without blocking the entire application's flow. This results in smoother API consumption and fewer interruptions, ensuring your identity verification processes remain uninterrupted even during peak loads.

Implementing Asyncio for Concurrent Didit API Calls

Integrating asyncio with Didit's APIs involves using an asynchronous HTTP client like aiohttp. Here's a conceptual outline of how you might structure your asynchronous API calls:


import asyncio
import aiohttp
import time

API_KEY = "YOUR_DIDIT_API_KEY"
BASE_URL = "https://verification.didit.me/v3/"

async def call_didit_api(session, endpoint, payload=None, method='POST'):
    headers = {
        'accept': 'application/json',
        'x-api-key': API_KEY
    }
    if method == 'POST':
        headers['content-type'] = 'application/json'

    url = f"{BASE_URL}{endpoint}"
    
    async with session.request(method, url, json=payload, headers=headers) as response:
        if response.status == 429:
            retry_after = int(response.headers.get('Retry-After', '5'))
            print(f"Rate limit hit. Retrying after {retry_after} seconds...")
            await asyncio.sleep(retry_after) # Implement simple backoff
            return await call_didit_api(session, endpoint, payload, method) # Retry
        response.raise_for_status()
        return await response.json()

async def create_verification_session(session, workflow_id, user_id):
    endpoint = "session/"
    payload = {
        "workflow_id": workflow_id,
        "vendor_data": user_id,
        "callback": "https://your-app.com/didit-callback"
    }
    return await call_didit_api(session, endpoint, payload, method='POST')

async def get_session_decision(session, session_id):
    endpoint = f"session/{session_id}/decision/"
    return await call_didit_api(session, endpoint, method='GET')

async def main():
    async with aiohttp.ClientSession() as session:
        tasks = []
        # Example: Create 10 verification sessions concurrently
        for i in range(10):
            tasks.append(create_verification_session(session, "YOUR_WORKFLOW_ID", f"user_{i}"))
        
        results = await asyncio.gather(*tasks)
        for res in results:
            print(f"Created session: {res.get('session_id')}")

        # Example: Retrieve decisions for some sessions concurrently
        decision_tasks = []
        for res in results[:5]: # Take first 5 for decision retrieval
            session_id = res.get('session_id')
            if session_id:
                decision_tasks.append(get_session_decision(session, session_id))
        
        decision_results = await asyncio.gather(*decision_tasks)
        for decision in decision_results:
            print(f"Session decision: {decision}")

if __name__ == "__main__":
    asyncio.run(main())

This example demonstrates how to create multiple verification sessions and retrieve their decisions concurrently. The call_didit_api function includes a basic retry mechanism for 429 Too Many Requests, using the Retry-After header to implement exponential backoff. For production systems, a more sophisticated backoff and circuit breaker pattern would be recommended, but this illustrates the core principle.

By using asyncio.gather, you can initiate multiple API requests simultaneously, allowing your application to process other tasks or wait for responses concurrently, leading to significant performance gains compared to sequential blocking calls.

Strategies for High-Volume Identity Verification

Achieving high throughput with Didit APIs using Asyncio requires more than just making requests concurrently. Consider these strategies:

  • Smart Batching: While Didit's core verification is often user-initiated, for operations like AML Monitoring or certain data lookups, you might design workflows that allow for batch processing when applicable, reducing the total number of API calls.
  • Adaptive Rate Limiting: Beyond simple exponential backoff, implement an adaptive rate limiter that monitors X-RateLimit-Remaining and adjusts the concurrency level of your asyncio tasks dynamically. If the remaining calls are low, slow down; if they're high, speed up.
  • Webhook-Driven Updates: For session results (e.g., after ID Verification or Liveness checks), rely on Didit's webhooks rather than excessive polling. This reduces the number of GET requests to /v2/session/<id>/decision/, which has a stricter rate limit of 100 RPM. Didit's modular architecture means you can set up webhook notifications for various status changes, pushing real-time updates to your system without constant querying.
  • Error Handling and Observability: Implement robust error handling for network issues, API errors (beyond 429s), and timeouts. Log or alert when retries are triggered or rate limits are consistently hit. This provides crucial insights for optimizing your API consumption strategy.
  • Resource Management: Manage your aiohttp.ClientSession instances carefully. Creating a new session for every request is inefficient due to connection overhead. Reusing a single session for multiple requests is generally best practice.

How Didit Helps

Didit is built from the ground up for developers and high-performance applications, making it an ideal partner for Python Asyncio implementations. Our modular architecture allows you to plug-and-play identity checks like ID Verification, Passive & Active Liveness, 1:1 Face Match, and AML Screening as needed, each accessible via clean, well-documented APIs. This modularity means you can orchestrate complex verification workflows tailored to your specific needs, and then optimize their consumption using asynchronous techniques.

We believe in making identity verification accessible, which is why we offer Free Core KYC. This allows you to experiment and build out your asynchronous integrations without upfront costs. Our AI-native approach ensures that our verification services are fast and accurate, perfectly complementing the speed benefits of Asyncio. With no setup fees and a pay-per-successful-check model, Didit provides a cost-effective and scalable solution for businesses looking to implement high-throughput identity verification. Our instant sandbox environment and comprehensive API documentation further empower developers to quickly integrate and optimize their usage of Didit's services, whether you're building a new system or enhancing an existing one.

Ready to Get Started?

Ready to see Didit in action? Get a free demo today.

Start verifying identities for free with Didit's free tier.

Infrastructure for identity and fraud.

One API for KYC, KYB, Transaction Monitoring, and Wallet Screening. Integrate in 5 minutes.

Ask an AI to summarise this page
Boost Didit API Throughput with Python Asyncio.