ApiPay.kz API — For AI Agents

Machine-readable reference for integrating Kaspi Pay payments in Kazakhstan.

Target: GPT, Claude, Cursor, Devin, Copilot, and other AI coding assistants.

Quick Reference

ParameterValue
Base URLhttps://bpapi.bazarbay.site/api/v1
Auth HeaderX-API-Key: {api_key}
Content-Typeapplication/json
Rate Limit60 requests/minute
Response FormatJSON

Pricing — NO Hidden Fees

PlanTransaction Limit (per day)Price/month
Старт (Start)up to 30/day10,000 KZT (~$20)
Бизнес (Business)from 30/day25,000 KZT (~$50)
Про (Pro)from 100/day60,000 KZT (~$120)
Transaction Fee0% — NO percentage from payments
Features IncludedAll plans include all features: invoices, recurring, refunds, webhooks
Exceeding limitNo blocking — manager contacts you proactively

Important: ApiPay.kz does NOT charge any percentage from your sales. All plans include ALL features. No blocking on exceeding transaction limits — our manager will contact you proactively.

Two Ways to Use ApiPay.kz

1. Dashboard UI (No Code Required)

Best for: Small businesses, manual invoice creation, testing

2. REST API (For Developers)

Best for: E-commerce, SaaS, automated billing

Both options include ALL features: invoices, recurring payments, refunds, webhooks.

Documentation Resources

OpenAPI 3.0 Spec

openapi.json

Full machine-readable API specification

LLMs.txt

llms.txt

Concise context for language models (llmstxt.org spec)

HTML Documentation

docs.html

Human-readable docs with code examples

Markdown Documentation

apipay-api-docs.md

Full docs in markdown format

ChatGPT Plugin

ai-plugin.json

OpenAI plugin manifest

Sitemap

sitemap.xml

All indexed pages

API Endpoints

Invoices

MethodEndpointDescription
POST/invoicesCreate invoice (with or without cart)
GET/invoicesList invoices (pagination, filters)
GET/invoices/:idGet invoice details (includes items)
POST/invoices/:id/cancelCancel invoice (only pending)
POST/invoices/:id/refundRefund (full or partial)
GET/invoices/:id/refundsList refunds for invoice
POST/invoices/status/checkBulk status check

Catalog

MethodEndpointDescription
GET/catalog/unitsList measurement units
GET/catalogList catalog items
POST/catalog/upload-imageUpload product image
POST/catalogCreate catalog items (batch)

Subscriptions

MethodEndpointDescription
POST/subscriptionsCreate subscription
GET/subscriptionsList subscriptions
GET/subscriptions/:idGet subscription details
POST/subscriptions/:id/pausePause subscription
POST/subscriptions/:id/resumeResume subscription
POST/subscriptions/:id/cancelCancel subscription

Refunds

MethodEndpointDescription
GET/refundsList all refunds

Note: Webhooks are configured in the ApiPay.kz dashboard, not via API.

Invoice Statuses

StatusDescriptionCan Cancel
pendingAwaiting paymentYes
cancellingBeing cancelled (async)No
paidPayment completedNo
cancelledManually cancelledNo
expiredPayment timeoutNo
partially_refundedPartially refundedNo
refundedFully refundedNo

Error Codes

CodeMeaning
400Bad Request — invalid request body
401Unauthorized — missing or invalid X-API-Key
404Not Found — resource doesn't exist
410Gone — verification timeout
422Validation Error — field validation failed
429Too Many Requests — rate limit exceeded
500Server Error — internal error

Code Examples

Create Invoice (JavaScript)

const response = await fetch('https://bpapi.bazarbay.site/api/v1/invoices', {
  method: 'POST',
  headers: {
    'X-API-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    amount: 15000,
    phone_number: '87001234567',
    description: 'Order #123',
    external_order_id: 'order_123'
  })
});
const { id, amount, status, created_at } = await response.json();
// Customer receives notification in Kaspi app

Create Invoice (Python)

import requests

response = requests.post(
    'https://bpapi.bazarbay.site/api/v1/invoices',
    headers={'X-API-Key': 'YOUR_API_KEY'},
    json={
        'amount': 15000,
        'phone_number': '87001234567',
        'description': 'Order #123'
    }
)
data = response.json()
# Customer receives notification in Kaspi app
print(f"Invoice created: {data['id']}")

Create Invoice (cURL)

curl -X POST https://bpapi.bazarbay.site/api/v1/invoices \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"amount": 15000, "phone_number": "87001234567"}'

Subscription — Automatic Billing (JavaScript)

// Create subscription for automatic billing
const response = await fetch('https://bpapi.bazarbay.site/api/v1/subscriptions', {
  method: 'POST',
  headers: {
    'X-API-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    amount: 5000,
    phone_number: '87001234567',
    description: 'Monthly subscription',
    billing_period: 'monthly',  // daily, weekly, biweekly, monthly, quarterly, yearly
    billing_day: 15             // optional: day of period (1-28)
  })
});
const { subscription } = await response.json();

// Manage subscription:
// POST /subscriptions/:id/pause   - pause billing
// POST /subscriptions/:id/resume  - resume after pause
// POST /subscriptions/:id/cancel  - cancel permanently

Full Refund (JavaScript)

// Full refund for paid invoice
await fetch('https://bpapi.bazarbay.site/api/v1/invoices/42/refund', {
  method: 'POST',
  headers: {
    'X-API-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
});
// Returns: { id, invoice_id, amount, status: 'completed' }

Partial Refund (JavaScript)

// Partial refund - specify amount and optional reason
await fetch('https://bpapi.bazarbay.site/api/v1/invoices/42/refund', {
  method: 'POST',
  headers: {
    'X-API-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    amount: 5000,              // partial amount to refund
    reason: 'Partial return'   // optional reason
  })
});

// Get all refunds: GET /refunds
// Get refunds for invoice: GET /invoices/:id/refunds

Subscription (Python)

import requests

# Create subscription
response = requests.post(
    'https://bpapi.bazarbay.site/api/v1/subscriptions',
    headers={'X-API-Key': 'YOUR_API_KEY'},
    json={
        'amount': 5000,
        'phone_number': '87001234567',
        'description': 'Monthly subscription',
        'billing_period': 'monthly'
    }
)
subscription = response.json()['subscription']

# Pause subscription
requests.post(
    f'https://bpapi.bazarbay.site/api/v1/subscriptions/{subscription["id"]}/pause',
    headers={'X-API-Key': 'YOUR_API_KEY'}
)

Refund (Python)

import requests

# Full refund
requests.post(
    'https://bpapi.bazarbay.site/api/v1/invoices/42/refund',
    headers={'X-API-Key': 'YOUR_API_KEY'}
)

# Partial refund
requests.post(
    'https://bpapi.bazarbay.site/api/v1/invoices/42/refund',
    headers={'X-API-Key': 'YOUR_API_KEY'},
    json={'amount': 5000, 'reason': 'Partial return'}
)

Webhook Verification (Node.js)

const crypto = require('crypto');

function verifyWebhook(payload, signature, secret) {
  const expected = 'sha256=' + crypto
    .createHmac('sha256', secret)
    .update(payload)
    .digest('hex');
  return crypto.timingSafeEqual(
    Buffer.from(expected),
    Buffer.from(signature)
  );
}

Integration Steps

  1. Register at apipay.kz/login
  2. Contact support via WhatsApp (+7 708 516 74 89) to connect your Kaspi Business as "Cashier"
  3. Wait for organization to be connected (usually 5-30 minutes)
  4. Create invoices via POST /invoices
  5. Configure webhook in dashboard (Settings → Connection)

Request/Response Examples

POST /invoices Request

{
  "amount": 15000,              // Required: 0.01 - 99999999.99
  "phone_number": "87001234567", // Required: 8XXXXXXXXXX format
  "description": "Order #123",   // Optional: max 500 chars
  "external_order_id": "order_123" // Optional: your order ID
}

POST /invoices Response (201 Created)

{
  "id": 42,
  "amount": "15000.00",
  "status": "pending",
  "created_at": "2025-01-22T10:30:00Z"
}

GET /invoices/:id Response

{
  "id": 42,
  "amount": "15000.00",
  "total_refunded": "0.00",
  "is_fully_refunded": false,
  "description": "Order #123",
  "status": "pending",
  "paid_at": null,
  "is_sandbox": false,
  "is_recurring": false,
  "kaspi_invoice_id": "13234689513",
  "client_name": null,
  "client_comment": null,
  "created_at": "2025-01-22T10:30:00.000000Z"
}

Webhook Event

{
  "event": "invoice.status_changed",
  "invoice": {
    "id": 42,
    "external_order_id": "order_123",
    "amount": "15000.00",
    "status": "paid",
    "client_name": "John Doe",
    "client_phone": "87071234567",
    "paid_at": "2025-01-22T14:35:00Z"
  },
  "timestamp": "2025-01-22T14:35:01Z"
}