> ## Documentation Index
> Fetch the complete documentation index at: https://idto.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Aadhaar OKYC: send an OTP

> Start Aadhaar offline KYC by sending an OTP to the holder's registered mobile, then submit the OTP to get the result.

Aadhaar OKYC is a two-call flow. The first call sends an OTP to the mobile number registered with the Aadhaar and returns a `session_id`. The second call submits the OTP the holder received.

> [!WARNING]
>
> Only send an OTP for an Aadhaar the holder has given you consent for. The OTP goes to a real person's phone.

**1. Set your credentials**

Use `https://dev.idto.ai` (staging) while you build and `https://prod.idto.ai` (production) when you go live. Keep the client ID and API key on your server only. Never ship them to a browser or a mobile app.

```bash .env theme={null}
IDTO_BASE_URL=https://dev.idto.ai
IDTO_CLIENT_ID=your-client-id
IDTO_API_KEY=your-api-key
```

```bash theme={null}
set -a; source .env; set +a
```

**2. Send the OTP**

```bash curl theme={null}
curl -sS -X POST "$IDTO_BASE_URL/v2/verify/okyc_generate_otp" \
  -H "X-Client-ID: $IDTO_CLIENT_ID" \
  -H "X-API-Key: $IDTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"aadhaar_number": "999999990019", "user_consent": true}'
```

```javascript okyc.mjs theme={null}
const BASE_URL = process.env.IDTO_BASE_URL ?? "https://dev.idto.ai";
const HEADERS = {
  "X-Client-ID": process.env.IDTO_CLIENT_ID,
  "X-API-Key": process.env.IDTO_API_KEY,
  "Content-Type": "application/json",
};

async function post(path, payload) {
  const response = await fetch(`${BASE_URL}${path}`, {
    method: "POST",
    headers: HEADERS,
    body: JSON.stringify(payload),
    signal: AbortSignal.timeout(30000),
  });
  return { http: response.status, body: await response.json() };
}

export async function sendOtp(aadhaarNumber) {
  const { http, body } = await post("/v2/verify/okyc_generate_otp", {
    aadhaar_number: aadhaarNumber,
    user_consent: true,
  });
  if (body.status === "success" && body.error_code === null) return { sessionId: body.data.session_id };
  return { http, errorCode: body.error_code, message: body.message ?? body.detail };
}

export async function submitOtp(sessionId, otp) {
  const { http, body } = await post("/v2/verify/okyc_get_result", { session_id: sessionId, otp });
  if (body.status === "success" && body.error_code === null) return { outcome: "verified", data: body.data };
  return { outcome: "error", http, errorCode: body.error_code, message: body.message ?? body.detail };
}

if (process.argv[2] === "send") console.log(await sendOtp(process.argv[3]));
```

A successful send returns `200` with `data.session_id`. Keep it with the user's record.

```json 200 theme={null}
{"status": "success", "error_code": null, "data": {"session_id": "<session-id>"}, "billed": true}
```

**3. Submit the OTP**

Call `submitOtp(sessionId, otp)` with the OTP the holder types in. A verified result returns `error_code: null` and the Aadhaar details in `data`.

## Test it

The sample Aadhaar `999999990019` is a placeholder. It passes idto's format check, so the call reaches a source, and the result depends on which source serves your account. No OTP is sent to anyone in either case. A source that rejects the number answers like this, and nothing is billed:

```json 400 Rejected by the source, not billed theme={null}
{"status": "error", "message": "Invalid input. Please check the request and try again.", "error_code": "IDTO_001", "data": null, "billed": false}
```

A source that finds no Aadhaar record answers `200` with `error_code: "IDTO_202"` and `data: null`, and that call is billed. `sendOtp` returns the HTTP status and `error_code` for both, so branch on `error_code`.

## Good to know

* `user_consent` must be `true`, or the call returns `IDTO_005`.
* A malformed OTP is rejected with `IDTO_001` before it is checked.

Was this page helpful? Email us at [tech@idto.ai](mailto:tech@idto.ai?subject=Docs%20feedback%3A%20Aadhaar%20OKYC%3A%20send%20an%20OTP) with the page link.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.