Skip to main content

Installation

pip install veri-sdk
Requires Python 3.10 or later.

Quick Start

from veri import VeriClient

# Initialize the client
client = VeriClient(api_key="your-api-key")

# Detect an image
result = client.detect(open("image.jpg", "rb"))
print(f"Prediction: {result.prediction}")
print(f"Is fake: {result.is_fake} ({result.confidence:.1%})")

Client Options

from veri import VeriClient

client = VeriClient(
    api_key="your-api-key",
    base_url="https://api.tryveri.com/v1",  # Custom base URL
    timeout=30.0,  # Request timeout in seconds
    max_retries=3,  # Number of retry attempts
)

Detection Methods

detect(image, options=None)

Detect whether an image is AI-generated.
from pathlib import Path
from veri import VeriClient, DetectionOptions

client = VeriClient(api_key="your-api-key")

# From file path
result = client.detect(Path("image.jpg"))

# From bytes
with open("image.jpg", "rb") as f:
    result = client.detect(f.read())

# From file object
result = client.detect(open("image.jpg", "rb"))

# From base64 string
result = client.detect(base64_encoded_string)

# With options
result = client.detect(
    image_bytes,
    options=DetectionOptions(
        models=["veri_face"],
        threshold=0.7,
    )
)

detect_url(url, options=None)

Detect an image from a URL.
result = client.detect_url("https://example.com/image.jpg")

get_profile()

Get the authenticated user’s profile.
profile = client.get_profile()
print(f"User ID: {profile['userId']}")
print(f"Credits: {profile['credits']}")

Async Client

For async applications, use AsyncVeriClient:
import asyncio
from veri import AsyncVeriClient

async def main():
    async with AsyncVeriClient(api_key="your-api-key") as client:
        result = await client.detect(image_bytes)
        print(f"Is fake: {result.is_fake}")

asyncio.run(main())
All methods have async equivalents:
async with AsyncVeriClient(api_key="your-api-key") as client:
    # Single detection
    result = await client.detect(image)

    # URL detection
    result = await client.detect_url("https://example.com/image.jpg")

    # Get profile
    profile = await client.get_profile()

Error Handling

from veri import (
    VeriClient,
    VeriAPIError,
    VeriValidationError,
    VeriRateLimitError,
    VeriTimeoutError,
    VeriInsufficientCreditsError,
)

client = VeriClient(api_key="your-api-key")

try:
    result = client.detect(image)
except VeriValidationError as e:
    print(f"Invalid input: {e.message} (field: {e.field})")
except VeriRateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after} seconds")
except VeriInsufficientCreditsError as e:
    print("Not enough credits")
except VeriTimeoutError as e:
    print(f"Request timed out after {e.timeout_ms}ms")
except VeriAPIError as e:
    print(f"API error: {e.message} (code: {e.code}, status: {e.status_code})")

Type Definitions

DetectionResult

class DetectionResult:
    prediction: str              # "ai", "real", or "uncertain"
    confidence: float            # Overall confidence (0-1)
    ensemble_score: float | None # Weighted ensemble score
    verdict: str                 # "ai_generated", "uncertain", or "likely_real"
    models_succeeded: int        # Models that returned results
    models_total: int            # Total models invoked
    model_results: dict          # Per-model results keyed by model name
    detection_latency_ms: int    # Detection latency in ms
    is_fake: bool | None         # True=AI, False=real, None=uncertain
    processing_time_ms: int      # Total processing time in ms
    image_hash: str              # SHA-256 hash of image
    cached: bool                 # Whether result was from cache
    timestamp: str               # ISO 8601 timestamp

DetectionOptions

class DetectionOptions:
    models: list[str] | None   # Specific models to use
    threshold: float           # Classification threshold (default 0.5)