Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "pixelvault"
version = "0.5.0"
version = "0.5.1"
description = "Official Python SDK for PixelVault, agent-first media hosting"
readme = "README.md"
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion src/pixelvault/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from .errors import PixelVaultError

__version__ = "0.5.0"
__version__ = "0.5.1"

DEFAULT_BASE_URL = "https://api.pixelvault.dev"
MAX_BACKOFF = 30.0
Expand Down
26 changes: 25 additions & 1 deletion src/pixelvault/types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Any, Dict, List, Optional, TypedDict
from typing import Any, Dict, List, Literal, Optional, TypedDict

import sys

Expand Down Expand Up @@ -73,13 +73,33 @@ class UsageLimits(TypedDict):
storage_bytes: int
uploads_per_month: int
bandwidth_bytes_per_month: int
transforms_per_month: NotRequired[int]


class BandwidthUsage(TypedDict):
"""CDN bandwidth preflight. Null values are unknown/not applicable, never zero."""

status: Literal["available", "unavailable", "unlimited"]
used: Optional[int]
remaining: Optional[int]
limit: Optional[int]
unit: Literal["bytes"]
accounting_period: str
resets_at: str
measured_at: Optional[str]
freshness: Literal["near_real_time", "delayed", "unavailable", "not_applicable"]


class GenerationUsage(TypedDict):
credits_used: int
credits_limit: int
credits_remaining: int

class VideoSecondsUsage(TypedDict):
seconds_used: int
seconds_limit: int
seconds_remaining: int


class Usage(TypedDict):
plan: str
Expand All @@ -90,6 +110,10 @@ class Usage(TypedDict):
remaining: UsageCounts
#: AI image-generation credits for the month (images.generate).
generation: NotRequired[GenerationUsage]
editing: NotRequired[GenerationUsage]
bandwidth: NotRequired[BandwidthUsage]
video_optimization: NotRequired[VideoSecondsUsage]
video_enrichment: NotRequired[VideoSecondsUsage]


class ApiKey(TypedDict):
Expand Down
21 changes: 20 additions & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,32 @@ def handler(req: httpx.Request):
assert len(calls) == 1 # a lost response must never spend credits twice


def test_usage_exposes_generation_credits():
def test_usage_exposes_credits_video_quota_and_honest_bandwidth():
usage = {
"plan": "free",
"generation": {"credits_used": 1, "credits_limit": 10, "credits_remaining": 9},
"video_optimization": {
"seconds_used": 11,
"seconds_limit": 120,
"seconds_remaining": 109,
},
"bandwidth": {
"status": "unavailable",
"used": None,
"remaining": None,
"limit": 1_073_741_824,
"unit": "bytes",
"accounting_period": "2026-11",
"resets_at": "2026-12-01T00:00:00.000Z",
"measured_at": None,
"freshness": "unavailable",
},
}
got = make(lambda r: httpx.Response(200, json={"data": usage})).usage.get()
assert got["generation"]["credits_remaining"] == 9
assert got["video_optimization"]["seconds_remaining"] == 109
assert got["bandwidth"]["used"] is None
assert got["bandwidth"]["limit"] == 1_073_741_824


@pytest.mark.asyncio
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading