Dokumentation

API Reference

Complete API reference for K-OTP service endpoints, parameters, and responses.

Base URL

Production: https://api.k-otp.dev/v1
Sandbox: https://api-sandbox.k-otp.dev/v1

Authentication

All API requests must include your API key in the Authorization header:

Authorization: Bearer YOUR_API_KEY

Send OTP

Send an OTP via SMS, email, or voice call.

Endpoint

POST /send

Request Body

{
  "to": "+1234567890",
  "method": "sms",
  "type": "verification",
  "template": "default",
  "ttl": 300,
  "length": 6,
  "metadata": {
    "user_id": "user_123",
    "action": "login"
  }
}

Parameters

ParameterTypeRequiredDescription
tostringYesPhone number (E.164) or email address
methodstringYesDelivery method: sms, email, voice
typestringYesOTP type: verification, two_factor, password_reset, transaction
templatestringNoTemplate name (default: "default")
ttlintegerNoTime to live in seconds (default: 300, max: 900)
lengthintegerNoOTP length (default: 6, min: 4, max: 8)
metadataobjectNoCustom metadata (max 1KB)

Response

{
  "id": "otp_1234567890abcdef",
  "to": "+1234567890",
  "method": "sms",
  "type": "verification",
  "status": "sent",
  "created_at": "2024-01-15T10:30:00Z",
  "expires_at": "2024-01-15T10:35:00Z",
  "cost": {
    "amount": 0.05,
    "currency": "USD"
  }
}

Verify OTP

Verify an OTP code entered by the user.

Endpoint

POST /verify

Request Body

{
  "id": "otp_1234567890abcdef",
  "code": "123456"
}

Parameters

ParameterTypeRequiredDescription
idstringYesOTP ID from send response
codestringYesOTP code entered by user

Response

{
  "valid": true,
  "id": "otp_1234567890abcdef",
  "verified_at": "2024-01-15T10:32:00Z",
  "attempts": 1,
  "metadata": {
    "user_id": "user_123",
    "action": "login"
  }
}

Check Status

Check the delivery status of an OTP.

Endpoint

GET /status/{id}

Parameters

ParameterTypeRequiredDescription
idstringYesOTP ID from send response

Response

{
  "id": "otp_1234567890abcdef",
  "status": "delivered",
  "to": "+1234567890",
  "method": "sms",
  "created_at": "2024-01-15T10:30:00Z",
  "delivered_at": "2024-01-15T10:30:15Z",
  "attempts": 0,
  "verified": false,
  "carrier": "Verizon",
  "country": "US"
}

List OTPs

Get a list of OTPs with filtering options.

Endpoint

GET /otps

Query Parameters

ParameterTypeDescription
limitintegerNumber of results (max: 100, default: 20)
offsetintegerPagination offset (default: 0)
methodstringFilter by delivery method
statusstringFilter by status
fromstringStart date (ISO 8601)
tostringEnd date (ISO 8601)

Response

{
  "data": [
    {
      "id": "otp_1234567890abcdef",
      "to": "+1234567890",
      "method": "sms",
      "status": "delivered",
      "created_at": "2024-01-15T10:30:00Z"
    }
  ],
  "pagination": {
    "limit": 20,
    "offset": 0,
    "total": 150,
    "has_more": true
  }
}

Status Codes

StatusDescription
pendingOTP is being processed
sentOTP has been sent to carrier/provider
deliveredOTP was successfully delivered
failedOTP delivery failed
expiredOTP has expired
verifiedOTP has been successfully verified

Error Responses

All errors follow this format:

{
  "error": {
    "code": "INVALID_PHONE",
    "message": "The phone number format is invalid",
    "details": {
      "field": "to",
      "value": "123456"
    }
  }
}

Common Error Codes

CodeHTTP StatusDescription
INVALID_API_KEY401API key is missing or invalid
INSUFFICIENT_CREDITS402Account has insufficient credits
RATE_LIMITED429Rate limit exceeded
INVALID_PHONE400Phone number format is invalid
INVALID_EMAIL400Email address format is invalid
OTP_NOT_FOUND404OTP ID not found
OTP_EXPIRED400OTP has expired
INVALID_CODE400OTP code is incorrect
MAX_ATTEMPTS400Maximum verification attempts reached

Rate Limits

  • Send OTP: 10 requests per minute per phone/email
  • Verify OTP: 5 attempts per OTP
  • API Calls: 1000 requests per minute per API key

Rate limit headers are included in all responses:

X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 999
X-RateLimit-Reset: 1642248600

Webhooks

Configure webhooks to receive real-time notifications about OTP events. See Webhooks for details.

SDKs and Libraries

  • JavaScript/Node.js: npm install @k-otp/sdk
  • Python: pip install k-otp
  • PHP: composer require k-otp/sdk
  • Go: go get github.com/k-otp/go-sdk
  • Java: Maven/Gradle available