Skip to main content

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.

Boost Didit API Throughput with Python Asyncio

Contents

In this guide

Jump to the part you need.

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 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.

Try it

Try this in the sandbox

Run the check this guide describes, free.

ID Verification

The product this post is about, taken from its topic. Run it free in the sandbox.

$0.15 per checkStart free

Author

Alejandro Rosas

Co-founder and CTO

Alejandro Rosas

Alejandro Rosas

Co-founder and CTO

About Didit

Questions

Blog questions

Who writes the Didit blog?
The Didit team. Guides reviewed by Alberto Rosas, co-founder and CEO, carry his byline. The rest are published as Didit.
Which topics does the blog cover?
Eight topics: ID verification, business verification (KYB), AML, sanctions and compliance, fraud prevention, transaction monitoring and crypto, country guides, agents and developers, and product updates.
Is the blog available in my language?
Yes, in 15 languages: English, Spanish, French, German, Brazilian and European Portuguese, Catalan, Russian, Arabic, Chinese, Japanese, Hindi, Indonesian, Korean and Swahili. Not every post is translated, so each language shows the posts it has.
Where do I find product updates?
In the changelog at /changelog/ and under the Product updates topic.
Are these posts legal advice?
No. Regulation posts explain rules; your legal team decides how they apply.
How do I find posts on one topic?
Open one of the eight topics, or search the blog.
Are posts dated?
Yes. Every post shows when it was published and when it was last updated.
Do posts link to the docs?
Developer posts link to the matching page on docs.didit.me and to the API reference.
Is the blog the same as the docs?
No. The blog explains rules, markets and product changes for a general reader, while docs.didit.me holds the integration guides and the API reference. Developer posts link the matching docs page and the API reference they describe.

Compliance built in

Audited, certified and attested.

We hold the certifications and build each country's rules into your flows, so you can launch anywhere without worrying. Security and Compliance center

  • Regulation encoded into your flows

    Tell us what you do and where. Didit lists the rules that apply to you, with sources, and builds the checks each country needs into one workflow.

  • Ready for AMLR

    Every requirement of the new EU anti-money laundering rules, from checking customers to human review, is already covered by a Didit check.

  • Tested in Spain's Treasury sandbox

    Spain's Treasury published its supervised sandbox report on Didit's NFC plus active liveness onboarding; SEPBLAC took part and valued the added measures positively.

  • Audited, not self-declared

    iBeta Level 1 and Level 2. Liveness tested under ISO/IEC 30107-3.

Compliance assistant

Your obligations · 3 regions

EU · AMLRCustomer due diligence, human reviewCovered
Illinois, Texas, ColoradoExplicit biometric consentCovered
Germany · Youth protectionVerified adults only (JMStV)Covered
Workflow checked. Every obligation is met
  • SOC 2 Type 2
  • ISO 27001
  • iBeta Level 1 and Level 2
  • EU regulator attestation
  • FSM youth protection
  • GDPR
  • EBA remote onboarding
  • MiCA compatible
  • FIDO Alliance member
  • AMLREU AML Regulation ready

Integration · Didit MCP

Run Didit from your own AI agent

Connect Didit to Claude, Cursor, VS Code or ChatGPT and just ask in plain words. Your agent can do anything you can do in the console, with the same permissions you have.

Add to ClaudeChatGPT
Didit Academy · Lesson 04 · Use Didit with MCP
  • Build workflowsDescribe the checks you need. The agent creates and publishes the flow.
  • Run investigationsAsk why a session was declined, review cases, search people and companies.
  • Change rulesCreate payment rules, test them on past data and switch them on.
  • Pull reportsAsk for numbers, exports or the audit log.

Verify your first user today.

Start free

Free sandbox. Credit applies to work-email sign-ups.