AntiCAP-WebApi Documentation

repository·main·Indexed 18 days ago

https://github.com/81newark/anticap-webapi

A web API service (version 1.1.1) for model inference supporting local, LAN, and public network deployment. It provides endpoints for OCR, math recognition, object detection, slider and rotation verification, and image similarity comparison. Includes administrative tools for managing registration codes, user balances, and API endpoint costs.

Tokens
1.8K
Snippets
10
Records
12
Agent score
13%

What's inside AntiCAP-WebApi

  1. Install AntiCAP-WebApi automatically

    main

    For an automated setup, clone the repository and run the platform-specific script. The script will automatically install the required dependencies and start the project.

    Default Credentials:

    • Port: 6688
    • Initial Username: admin
    • Initial Password: admin
    # 1. Clone the repository
    git clone https://github.com/81NewArk/AntiCAP-WebApi
    
    # 2. Run the appropriate script for your OS
    # For Windows:
    Run-Windows.bat
    
    # For Linux:
    ./Run-Linux.sh
  2. Access the Web UI and Developer Documentation

    main

    Once the server is running on the default port 6688, you can access the following interfaces:

    • Web Home Page: http://127.0.0.1:6688/ or http://localhost:6688/
    • Developer Documentation (Swagger/Docs): http://127.0.0.1:6688/docs or http://localhost:6688/docs
  3. Install AntiCAP-WebApi manually

    main

    To install the project manually, clone the repository, install dependencies using the Tsinghua mirror, and run the main script.

    Prerequisites:

    • Python >= 3.8 (64-bit).
    • It is highly recommended to use Python 3.10.6 because the pyjwt library may not support lower versions.
    • Download Python 3.10.6 here: https://registry.npmmirror.com/-/binary/python/3.10.6/python-3.10.6-amd64.exe

    Default Credentials:

    • Port: 6688
    • Initial Username: admin
    • Initial Password: admin
    # 1. Clone the repository
    git clone https://github.com/81NewArk/AntiCAP-WebApi
    
    # 2. Enter the project directory
    cd AntiCAP-WebApi
    
    # 3. Install dependencies using Tsinghua mirror
    pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
    
    # 4. Run the project
    python main.py
  4. Troubleshoot missing system DLL errors

    main

    If you encounter errors regarding missing system DLLs (often required for model inference on servers or home systems), you must install the Microsoft Visual C++ Redistributable packages.

    Download the version corresponding to your architecture:

    • ARM64: https://aka.ms/vs/17/release/vc_redist.arm64.exe
    • x64: https://aka.ms/vs/17/release/vc_redist.x64.exe
  5. Use Slider and Rotation verification APIs

    main

    Solve various captcha types including slider gaps, shadow sliders, and image rotations.

    // Slider Gap Match
    POST /api/slider/match
    {
      "target_base64": "...",
      "background_base64": "..."
    }
    
    // Single Image Rotation
    POST /api/rotate/single/rotate
    {
      "img_base64": "..."
    }
    
    // Double Image Rotation
    POST /api/rotate/double/rotate
    {
      "inside_base64": "...",
      "outside_base64": "..."
    }
  6. Authenticate and obtain a JWT token

    main

    To access protected API endpoints, you must first authenticate using the /api/login endpoint. This endpoint accepts OAuth2 form data (username and password) and returns a JSON response containing a Bearer access token, the user's role, and their current balance. Use this token in the Authorization header for subsequent requests.

    POST /api/login
    Content-Type: application/x-www-form-urlencoded
    
    username=admin&password=admin
    
    // Response
    {
      "access_token": "YOUR_JWT_TOKEN",
      "token_type": "bearer",
      "role": "admin",
      "balance": 1000000
    }
  7. Use Object Detection APIs (Icons and Text)

    main

    Detect specific elements within an image. These endpoints return coordinates for the detected items.

    // Detect Icons
    POST /api/detection/icon
    {
      "img_base64": "..."
    }
    
    // Detect Text
    POST /api/detection/text
    {
      "img_base64": "..."
    }
    
    // Detect Icons in a specific order (requires target and order images)
    POST /api/detection/icon/order
    {
      "order_img_base64": "...",
      "target_img_base64": "..."
    }
  8. Admin: Manage registration codes

    main

    Administrators can generate new registration codes with specific point values, list existing codes, or delete unused codes.

    // Generate a new code with 5000 points
    POST /api/admin/generate_code
    {
      "points": 5000
    }
    
    // Delete a specific code by ID
    DELETE /api/admin/regcodes/{code_id}
  9. Use OCR and Math recognition APIs

    main

    The API provides endpoints to extract text from images using OCR or mathematical expressions. These endpoints require a base64 encoded string of the image and consume user balance based on the configured endpoint cost.

    // OCR Recognition
    POST /api/ocr
    {
      "img_base64": "iVBORw0KGgoAAAANSUhEUgAA..."
    }
    
    // Math Recognition
    POST /api/math
    {
      "img_base64": "iVBORw0KGgoAAAANSUhEUgAA..."
    }
  10. Register a new user with a registration code

    main

    New users can register via the /api/register endpoint. This requires a username, password, and a valid, unused registration_code. Upon successful registration, the user's initial balance is set to the number of points associated with that registration code, and the code is marked as used.

    POST /api/register
    {
      "username": "new_user",
      "password": "secure_password",
      "registration_code": "UUID-STRING-FROM-ADMIN"
    }
  11. Admin: Manage users and endpoint costs

    main

    Administrators can view all users, update user details (password or balance), and configure the 'cost' (points deducted) for specific API paths.

    // Update a user's balance
    PUT /api/admin/users/{username}
    {
      "balance": 5000
    }
    
    // Set the cost for a specific API endpoint
    POST /api/admin/costs
    {
      "path": "/api/ocr",
      "cost": 10,
      "description": "OCR processing"
    }