utopic 0.2.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- utopic-0.3.0/PKG-INFO +114 -0
- utopic-0.3.0/README.txt +91 -0
- {utopic-0.2.0 → utopic-0.3.0}/pyproject.toml +17 -3
- utopic-0.3.0/src/utopic_cli/billing.py +148 -0
- {utopic-0.2.0 → utopic-0.3.0}/src/utopic_cli/cli.py +42 -6
- {utopic-0.2.0 → utopic-0.3.0}/src/utopic_cli/client.py +4 -1
- utopic-0.2.0/PKG-INFO +0 -73
- utopic-0.2.0/README.txt +0 -59
- {utopic-0.2.0 → utopic-0.3.0}/.gitignore +0 -0
- {utopic-0.2.0 → utopic-0.3.0}/LICENSE +0 -0
- {utopic-0.2.0 → utopic-0.3.0}/src/utopic_cli/__init__.py +0 -0
- {utopic-0.2.0 → utopic-0.3.0}/src/utopic_cli/__main__.py +0 -0
- {utopic-0.2.0 → utopic-0.3.0}/src/utopic_cli/login.py +0 -0
- {utopic-0.2.0 → utopic-0.3.0}/src/utopic_cli/py.typed +0 -0
utopic-0.3.0/PKG-INFO
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: utopic
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Sign in to Utopic, manage API keys, and buy API credits
|
|
5
|
+
Project-URL: Homepage, https://utopic.company
|
|
6
|
+
Project-URL: Source, https://github.com/adavyas/utopic-package-manager
|
|
7
|
+
Author: Adavya Sharma
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Python: >=3.12
|
|
11
|
+
Requires-Dist: annotated-types==0.8.0
|
|
12
|
+
Requires-Dist: anyio==4.16.0
|
|
13
|
+
Requires-Dist: certifi==2026.10.23
|
|
14
|
+
Requires-Dist: h11==0.16.0
|
|
15
|
+
Requires-Dist: httpcore==1.0.9
|
|
16
|
+
Requires-Dist: httpx==0.28.1
|
|
17
|
+
Requires-Dist: idna==3.20
|
|
18
|
+
Requires-Dist: pydantic-core==2.50.2
|
|
19
|
+
Requires-Dist: pydantic==2.14.2
|
|
20
|
+
Requires-Dist: typing-extensions==4.16.0
|
|
21
|
+
Requires-Dist: typing-inspection==0.4.4
|
|
22
|
+
Description-Content-Type: text/plain
|
|
23
|
+
|
|
24
|
+
Utopic CLI
|
|
25
|
+
|
|
26
|
+
Sign in with Google, manage your Utopic inference API keys, and buy API credits.
|
|
27
|
+
Requires Python 3.12 or newer. The client uses HTTPS; it runs no model or server.
|
|
28
|
+
|
|
29
|
+
Install:
|
|
30
|
+
uv tool install utopic
|
|
31
|
+
utopic login
|
|
32
|
+
utopic keys create
|
|
33
|
+
utopic keys list
|
|
34
|
+
utopic keys revoke <key-id>
|
|
35
|
+
utopic account
|
|
36
|
+
utopic add-credit 10
|
|
37
|
+
uv tool upgrade utopic
|
|
38
|
+
|
|
39
|
+
If uv reports that its executable directory is not on PATH:
|
|
40
|
+
uv tool update-shell
|
|
41
|
+
|
|
42
|
+
Alternatively, use uv pip or pip within an activated virtual environment:
|
|
43
|
+
uv pip install utopic
|
|
44
|
+
python -m pip install utopic
|
|
45
|
+
|
|
46
|
+
No version or Python flags are needed in the standard install command. Runtime
|
|
47
|
+
dependencies, including transitive dependencies, are pinned in the package
|
|
48
|
+
metadata. Development Python is pinned in .python-version; build and quality
|
|
49
|
+
tool versions are pinned in pyproject.toml and uv.lock.
|
|
50
|
+
|
|
51
|
+
For an unpublished build, pass the wheel filename to either installer:
|
|
52
|
+
uv tool install /path/to/utopic-0.3.0-py3-none-any.whl
|
|
53
|
+
python -m pip install /path/to/utopic-0.3.0-py3-none-any.whl
|
|
54
|
+
|
|
55
|
+
Hosted login opens Google directly, prints a verification code, and polls the
|
|
56
|
+
gateway over HTTPS. Authorize only when the browser code matches the terminal.
|
|
57
|
+
Use utopic login --no-browser to print the link without opening a browser.
|
|
58
|
+
No localhost callback or Google client secret is needed on the user's machine.
|
|
59
|
+
|
|
60
|
+
The gateway defaults to https://utopicrt-gateway.fly.dev for compatibility with
|
|
61
|
+
existing sessions. Use utopic --gateway https://api.utopic.company login for the
|
|
62
|
+
custom domain. Credentials are isolated per gateway origin.
|
|
63
|
+
|
|
64
|
+
The existing ~/.local/state/utopic-mcp location is retained only for credential
|
|
65
|
+
compatibility. This distribution includes no MCP server, dependencies or commands.
|
|
66
|
+
--state-dir overrides the directory. On macOS and Linux, credential files are
|
|
67
|
+
owner-only. Windows credential storage has not been qualified.
|
|
68
|
+
|
|
69
|
+
keys create prints the secret once to stdout; save it privately. Never paste it
|
|
70
|
+
into support logs. Keys list emits metadata, not secrets. Creation is never
|
|
71
|
+
automatically retried; after a connection failure, inspect keys list first.
|
|
72
|
+
|
|
73
|
+
API credit and balance
|
|
74
|
+
|
|
75
|
+
utopic account
|
|
76
|
+
utopic account --json
|
|
77
|
+
utopic add-credit 7.50
|
|
78
|
+
utopic add-credit 25 --use business
|
|
79
|
+
utopic add-credit 5 --no-browser
|
|
80
|
+
|
|
81
|
+
account reads your live account status and available/reserved balances. add-credit
|
|
82
|
+
uses your saved Google management session to call the billing API and opens its
|
|
83
|
+
Stripe Checkout link. Enter any USD amount from $5 to $999999.99 in cent increments;
|
|
84
|
+
tax is added at checkout and provider payment limits apply. Personal use is the
|
|
85
|
+
default; select --use business for business purchases. No card details or Stripe
|
|
86
|
+
secrets are collected by the CLI. No MCP installation is required.
|
|
87
|
+
|
|
88
|
+
The URL is also printed to stdout; --no-browser only prints it. Complete payment
|
|
89
|
+
on Stripe. The backend adds credit after verifying Stripe's signed payment event;
|
|
90
|
+
creating/opening a link does not add credit. Run utopic account after payment.
|
|
91
|
+
|
|
92
|
+
A purchase ID and exact Retry command are printed before the checkout request.
|
|
93
|
+
If the request fails, reuse that command with the same amount, use, gateway, and
|
|
94
|
+
ID. --purchase-id <uuid> resumes an existing purchase. The CLI never retries a
|
|
95
|
+
purchase automatically. A new add-credit invocation without --purchase-id creates
|
|
96
|
+
a new purchase; do not use it to retry an uncertain previous attempt.
|
|
97
|
+
|
|
98
|
+
Run utopic --help, utopic add-credit --help, or utopic --version for usage and version.
|
|
99
|
+
python -m utopic_cli invokes the same interface.
|
|
100
|
+
|
|
101
|
+
When migrating an old checkout launcher, move that executable to a backup before
|
|
102
|
+
installing the tool in the same location. Preserve the private credential folder.
|
|
103
|
+
|
|
104
|
+
Migration from utopic 0.1.x
|
|
105
|
+
|
|
106
|
+
Version 0.2.0 replaces the native-runtime package manager with this API-only CLI.
|
|
107
|
+
The old setup, run, models, chat, bridge, server, MCP and ACP commands are removed.
|
|
108
|
+
Existing model downloads are not removed. Keep a separate environment pinned to
|
|
109
|
+
utopic==0.1.7 if you still need the old runtime commands. Upgrade the API CLI with:
|
|
110
|
+
uv tool upgrade utopic
|
|
111
|
+
|
|
112
|
+
The published package is utopic, maintained by adavyas. The Python import namespace
|
|
113
|
+
is utopic_cli. An existing Google session from the API CLI is reused when the
|
|
114
|
+
gateway origin and private state directory are unchanged.
|
utopic-0.3.0/README.txt
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
Utopic CLI
|
|
2
|
+
|
|
3
|
+
Sign in with Google, manage your Utopic inference API keys, and buy API credits.
|
|
4
|
+
Requires Python 3.12 or newer. The client uses HTTPS; it runs no model or server.
|
|
5
|
+
|
|
6
|
+
Install:
|
|
7
|
+
uv tool install utopic
|
|
8
|
+
utopic login
|
|
9
|
+
utopic keys create
|
|
10
|
+
utopic keys list
|
|
11
|
+
utopic keys revoke <key-id>
|
|
12
|
+
utopic account
|
|
13
|
+
utopic add-credit 10
|
|
14
|
+
uv tool upgrade utopic
|
|
15
|
+
|
|
16
|
+
If uv reports that its executable directory is not on PATH:
|
|
17
|
+
uv tool update-shell
|
|
18
|
+
|
|
19
|
+
Alternatively, use uv pip or pip within an activated virtual environment:
|
|
20
|
+
uv pip install utopic
|
|
21
|
+
python -m pip install utopic
|
|
22
|
+
|
|
23
|
+
No version or Python flags are needed in the standard install command. Runtime
|
|
24
|
+
dependencies, including transitive dependencies, are pinned in the package
|
|
25
|
+
metadata. Development Python is pinned in .python-version; build and quality
|
|
26
|
+
tool versions are pinned in pyproject.toml and uv.lock.
|
|
27
|
+
|
|
28
|
+
For an unpublished build, pass the wheel filename to either installer:
|
|
29
|
+
uv tool install /path/to/utopic-0.3.0-py3-none-any.whl
|
|
30
|
+
python -m pip install /path/to/utopic-0.3.0-py3-none-any.whl
|
|
31
|
+
|
|
32
|
+
Hosted login opens Google directly, prints a verification code, and polls the
|
|
33
|
+
gateway over HTTPS. Authorize only when the browser code matches the terminal.
|
|
34
|
+
Use utopic login --no-browser to print the link without opening a browser.
|
|
35
|
+
No localhost callback or Google client secret is needed on the user's machine.
|
|
36
|
+
|
|
37
|
+
The gateway defaults to https://utopicrt-gateway.fly.dev for compatibility with
|
|
38
|
+
existing sessions. Use utopic --gateway https://api.utopic.company login for the
|
|
39
|
+
custom domain. Credentials are isolated per gateway origin.
|
|
40
|
+
|
|
41
|
+
The existing ~/.local/state/utopic-mcp location is retained only for credential
|
|
42
|
+
compatibility. This distribution includes no MCP server, dependencies or commands.
|
|
43
|
+
--state-dir overrides the directory. On macOS and Linux, credential files are
|
|
44
|
+
owner-only. Windows credential storage has not been qualified.
|
|
45
|
+
|
|
46
|
+
keys create prints the secret once to stdout; save it privately. Never paste it
|
|
47
|
+
into support logs. Keys list emits metadata, not secrets. Creation is never
|
|
48
|
+
automatically retried; after a connection failure, inspect keys list first.
|
|
49
|
+
|
|
50
|
+
API credit and balance
|
|
51
|
+
|
|
52
|
+
utopic account
|
|
53
|
+
utopic account --json
|
|
54
|
+
utopic add-credit 7.50
|
|
55
|
+
utopic add-credit 25 --use business
|
|
56
|
+
utopic add-credit 5 --no-browser
|
|
57
|
+
|
|
58
|
+
account reads your live account status and available/reserved balances. add-credit
|
|
59
|
+
uses your saved Google management session to call the billing API and opens its
|
|
60
|
+
Stripe Checkout link. Enter any USD amount from $5 to $999999.99 in cent increments;
|
|
61
|
+
tax is added at checkout and provider payment limits apply. Personal use is the
|
|
62
|
+
default; select --use business for business purchases. No card details or Stripe
|
|
63
|
+
secrets are collected by the CLI. No MCP installation is required.
|
|
64
|
+
|
|
65
|
+
The URL is also printed to stdout; --no-browser only prints it. Complete payment
|
|
66
|
+
on Stripe. The backend adds credit after verifying Stripe's signed payment event;
|
|
67
|
+
creating/opening a link does not add credit. Run utopic account after payment.
|
|
68
|
+
|
|
69
|
+
A purchase ID and exact Retry command are printed before the checkout request.
|
|
70
|
+
If the request fails, reuse that command with the same amount, use, gateway, and
|
|
71
|
+
ID. --purchase-id <uuid> resumes an existing purchase. The CLI never retries a
|
|
72
|
+
purchase automatically. A new add-credit invocation without --purchase-id creates
|
|
73
|
+
a new purchase; do not use it to retry an uncertain previous attempt.
|
|
74
|
+
|
|
75
|
+
Run utopic --help, utopic add-credit --help, or utopic --version for usage and version.
|
|
76
|
+
python -m utopic_cli invokes the same interface.
|
|
77
|
+
|
|
78
|
+
When migrating an old checkout launcher, move that executable to a backup before
|
|
79
|
+
installing the tool in the same location. Preserve the private credential folder.
|
|
80
|
+
|
|
81
|
+
Migration from utopic 0.1.x
|
|
82
|
+
|
|
83
|
+
Version 0.2.0 replaces the native-runtime package manager with this API-only CLI.
|
|
84
|
+
The old setup, run, models, chat, bridge, server, MCP and ACP commands are removed.
|
|
85
|
+
Existing model downloads are not removed. Keep a separate environment pinned to
|
|
86
|
+
utopic==0.1.7 if you still need the old runtime commands. Upgrade the API CLI with:
|
|
87
|
+
uv tool upgrade utopic
|
|
88
|
+
|
|
89
|
+
The published package is utopic, maintained by adavyas. The Python import namespace
|
|
90
|
+
is utopic_cli. An existing Google session from the API CLI is reused when the
|
|
91
|
+
gateway origin and private state directory are unchanged.
|
|
@@ -4,14 +4,28 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "utopic"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.3.0"
|
|
8
8
|
authors = [{name = "Adavya Sharma"}]
|
|
9
|
-
description = "Sign in to Utopic and
|
|
9
|
+
description = "Sign in to Utopic, manage API keys, and buy API credits"
|
|
10
10
|
readme = {file = "README.txt", content-type = "text/plain"}
|
|
11
11
|
license = "Apache-2.0"
|
|
12
12
|
license-files = ["LICENSE"]
|
|
13
13
|
requires-python = ">=3.12"
|
|
14
|
-
|
|
14
|
+
# Ship the tested runtime closure in wheel metadata; pip/uv tool installs do not
|
|
15
|
+
# consume this repository's uv.lock.
|
|
16
|
+
dependencies = [
|
|
17
|
+
"annotated-types==0.8.0",
|
|
18
|
+
"anyio==4.16.0",
|
|
19
|
+
"certifi==2026.10.23",
|
|
20
|
+
"h11==0.16.0",
|
|
21
|
+
"httpcore==1.0.9",
|
|
22
|
+
"httpx==0.28.1",
|
|
23
|
+
"idna==3.20",
|
|
24
|
+
"pydantic==2.14.2",
|
|
25
|
+
"pydantic-core==2.50.2",
|
|
26
|
+
"typing-extensions==4.16.0",
|
|
27
|
+
"typing-inspection==0.4.4",
|
|
28
|
+
]
|
|
15
29
|
|
|
16
30
|
[project.scripts]
|
|
17
31
|
utopic = "utopic_cli.cli:main"
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"""Account balances and Stripe Checkout through the authenticated gateway API."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import json
|
|
5
|
+
import re
|
|
6
|
+
import shlex
|
|
7
|
+
import sys
|
|
8
|
+
import webbrowser
|
|
9
|
+
from decimal import Decimal
|
|
10
|
+
from typing import Literal
|
|
11
|
+
from urllib.parse import urlsplit
|
|
12
|
+
from uuid import UUID, uuid4
|
|
13
|
+
|
|
14
|
+
from pydantic import BaseModel, Field, field_validator
|
|
15
|
+
|
|
16
|
+
from utopic_cli.client import Gateway
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class AccountInfo(BaseModel):
|
|
20
|
+
"""Public account identity and spending status."""
|
|
21
|
+
|
|
22
|
+
id: UUID
|
|
23
|
+
email: str = Field(max_length=320)
|
|
24
|
+
frozen: bool = Field(strict=True)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class Balance(BaseModel):
|
|
28
|
+
"""Use integer accounting units rather than rounded display fields."""
|
|
29
|
+
|
|
30
|
+
available_microusd: int = Field(strict=True)
|
|
31
|
+
reserved_microusd: int = Field(strict=True, ge=0)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class Checkout(BaseModel):
|
|
35
|
+
"""Validate the provider destination before printing or opening it."""
|
|
36
|
+
|
|
37
|
+
url: str = Field(max_length=16384)
|
|
38
|
+
order_id: UUID
|
|
39
|
+
|
|
40
|
+
@field_validator("url")
|
|
41
|
+
@staticmethod
|
|
42
|
+
def stripe_url(value: str) -> str:
|
|
43
|
+
"""Allow only the backend's Stripe-hosted HTTPS checkout surface."""
|
|
44
|
+
parsed = urlsplit(value)
|
|
45
|
+
if (
|
|
46
|
+
parsed.scheme != "https"
|
|
47
|
+
or parsed.netloc != "checkout.stripe.com"
|
|
48
|
+
or not parsed.path.startswith("/")
|
|
49
|
+
or any(char.isspace() or ord(char) < 32 or ord(char) == 127 for char in value)
|
|
50
|
+
):
|
|
51
|
+
raise ValueError("Invalid Stripe checkout URL")
|
|
52
|
+
return value
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def amount_cents(value: str) -> int:
|
|
56
|
+
"""Parse decimal USD without float rounding, truncation, or exponent notation."""
|
|
57
|
+
if len(value) > 32 or not re.fullmatch(r"[0-9]+(?:\.[0-9]{1,2})?", value):
|
|
58
|
+
raise argparse.ArgumentTypeError("Use a USD amount with at most two decimals, e.g. 7.50")
|
|
59
|
+
dollars, _, fraction = value.partition(".")
|
|
60
|
+
cents = int(dollars) * 100 + int(fraction.ljust(2, "0"))
|
|
61
|
+
if not 500 <= cents <= 99_999_999:
|
|
62
|
+
raise argparse.ArgumentTypeError("Choose between $5 and $999999.99, plus applicable tax")
|
|
63
|
+
return cents
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _session_token(gateway: Gateway) -> str:
|
|
67
|
+
credentials = gateway.state.load()
|
|
68
|
+
if credentials is None:
|
|
69
|
+
raise ValueError("Run utopic login first (with the same --gateway, if specified).")
|
|
70
|
+
return credentials.session_token.get_secret_value()
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def account(gateway: Gateway, *, as_json: bool) -> None:
|
|
74
|
+
"""Read account status and exact balances without changing credentials or credit."""
|
|
75
|
+
token = _session_token(gateway)
|
|
76
|
+
identity = AccountInfo.model_validate(gateway.request("GET", "/v1/account", token=token))
|
|
77
|
+
balance = Balance.model_validate(gateway.request("GET", "/v1/billing/balance", token=token))
|
|
78
|
+
available = format(Decimal(balance.available_microusd) / 1_000_000, ".6f")
|
|
79
|
+
reserved = format(Decimal(balance.reserved_microusd) / 1_000_000, ".6f")
|
|
80
|
+
if as_json:
|
|
81
|
+
data = {
|
|
82
|
+
**identity.model_dump(mode="json"),
|
|
83
|
+
**balance.model_dump(),
|
|
84
|
+
"available_usd": available,
|
|
85
|
+
"reserved_usd": reserved,
|
|
86
|
+
}
|
|
87
|
+
sys.stdout.write(json.dumps(data, indent=2) + "\n")
|
|
88
|
+
return
|
|
89
|
+
# JSON quoting also prevents account text from injecting terminal control codes.
|
|
90
|
+
sys.stdout.write(
|
|
91
|
+
f"Email: {json.dumps(identity.email)}\n"
|
|
92
|
+
f"Status: {'frozen' if identity.frozen else 'active'}\n"
|
|
93
|
+
f"Available: ${available}\nReserved: ${reserved}\n"
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def add_credit(
|
|
98
|
+
gateway: Gateway,
|
|
99
|
+
cents: int,
|
|
100
|
+
use: Literal["personal", "business"],
|
|
101
|
+
purchase_id: UUID | None,
|
|
102
|
+
*,
|
|
103
|
+
open_browser: bool,
|
|
104
|
+
) -> None:
|
|
105
|
+
"""Create one checkout; print its recovery identity before sending any mutation."""
|
|
106
|
+
token = _session_token(gateway)
|
|
107
|
+
purchase_id = purchase_id or uuid4()
|
|
108
|
+
dollars = f"{cents // 100}.{cents % 100:02d}"
|
|
109
|
+
retry = [
|
|
110
|
+
"utopic",
|
|
111
|
+
"--gateway",
|
|
112
|
+
gateway.origin,
|
|
113
|
+
"--state-dir",
|
|
114
|
+
str(gateway.state.path.parent.resolve()),
|
|
115
|
+
"add-credit",
|
|
116
|
+
dollars,
|
|
117
|
+
"--use",
|
|
118
|
+
use,
|
|
119
|
+
"--purchase-id",
|
|
120
|
+
str(purchase_id),
|
|
121
|
+
]
|
|
122
|
+
if not open_browser:
|
|
123
|
+
retry.append("--no-browser")
|
|
124
|
+
sys.stderr.write(f"Purchase ID: {purchase_id}\nRetry: {shlex.join(retry)}\n")
|
|
125
|
+
sys.stderr.flush()
|
|
126
|
+
checkout = Checkout.model_validate(
|
|
127
|
+
gateway.request(
|
|
128
|
+
"POST",
|
|
129
|
+
"/v1/billing/checkout",
|
|
130
|
+
token=token,
|
|
131
|
+
body={"amount_cents": cents, "use": use},
|
|
132
|
+
idempotency_key=str(purchase_id),
|
|
133
|
+
)
|
|
134
|
+
)
|
|
135
|
+
sys.stdout.write(checkout.url + "\n")
|
|
136
|
+
sys.stdout.flush()
|
|
137
|
+
sys.stderr.write(
|
|
138
|
+
f"Checkout for ${dollars} credit plus applicable tax ({use}). Order: {checkout.order_id}\n"
|
|
139
|
+
"Complete payment in your browser. Credits appear after payment verification; "
|
|
140
|
+
"check with utopic account.\n"
|
|
141
|
+
)
|
|
142
|
+
if open_browser:
|
|
143
|
+
try:
|
|
144
|
+
opened = webbrowser.open(checkout.url)
|
|
145
|
+
except (OSError, webbrowser.Error):
|
|
146
|
+
opened = False
|
|
147
|
+
if not opened:
|
|
148
|
+
sys.stderr.write("Open the link above in your browser to complete payment.\n")
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""Sign in and
|
|
1
|
+
"""Sign in, manage API keys, and buy Utopic API credits from a terminal."""
|
|
2
2
|
|
|
3
3
|
import argparse
|
|
4
4
|
import hashlib
|
|
@@ -11,6 +11,7 @@ from uuid import UUID
|
|
|
11
11
|
|
|
12
12
|
from pydantic import BaseModel, Field, SecretStr, TypeAdapter, ValidationError
|
|
13
13
|
|
|
14
|
+
from utopic_cli.billing import account, add_credit, amount_cents
|
|
14
15
|
from utopic_cli.client import (
|
|
15
16
|
DEFAULT_GATEWAY,
|
|
16
17
|
Gateway,
|
|
@@ -103,6 +104,15 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
103
104
|
actions.add_parser("list", help="List key IDs, prefixes and revocation status as JSON")
|
|
104
105
|
revoke = actions.add_parser("revoke", help="Revoke a key by its ID")
|
|
105
106
|
revoke.add_argument("id", type=UUID)
|
|
107
|
+
account_parser = commands.add_parser("account", help="Show account status and credit balance")
|
|
108
|
+
account_parser.add_argument("--json", action="store_true", help="Print account data as JSON")
|
|
109
|
+
credit = commands.add_parser("add-credit", help="Buy API credit through Stripe, minimum $5")
|
|
110
|
+
credit.add_argument("amount", type=amount_cents, help="USD credit amount, e.g. 10 or 7.50")
|
|
111
|
+
credit.add_argument("--use", choices=["personal", "business"], default="personal")
|
|
112
|
+
credit.add_argument(
|
|
113
|
+
"--purchase-id", type=UUID, help="Reuse the same ID when retrying a purchase"
|
|
114
|
+
)
|
|
115
|
+
credit.add_argument("--no-browser", action="store_true", help="Print the checkout link only")
|
|
106
116
|
args = parser.parse_args(argv)
|
|
107
117
|
gateway = None
|
|
108
118
|
try:
|
|
@@ -111,6 +121,12 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
111
121
|
gateway = Gateway(origin, PrivateState(args.state_dir / name, origin))
|
|
112
122
|
if args.command == "login":
|
|
113
123
|
login(gateway, open_browser=not args.no_browser)
|
|
124
|
+
elif args.command == "account":
|
|
125
|
+
account(gateway, as_json=args.json)
|
|
126
|
+
elif args.command == "add-credit":
|
|
127
|
+
add_credit(
|
|
128
|
+
gateway, args.amount, args.use, args.purchase_id, open_browser=not args.no_browser
|
|
129
|
+
)
|
|
114
130
|
else:
|
|
115
131
|
keys(gateway, args.action, getattr(args, "id", None))
|
|
116
132
|
return 0
|
|
@@ -121,6 +137,13 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
121
137
|
f"Cannot connect to {endpoint} for login. Check DNS and network access, "
|
|
122
138
|
"then run utopic login again.\n"
|
|
123
139
|
)
|
|
140
|
+
elif args.command == "add-credit":
|
|
141
|
+
sys.stderr.write(
|
|
142
|
+
"Checkout connection failed. Reuse the printed Retry command; "
|
|
143
|
+
"do not create a new purchase ID for this attempt.\n"
|
|
144
|
+
)
|
|
145
|
+
elif args.command == "account":
|
|
146
|
+
sys.stderr.write(f"Cannot read account from {endpoint}; try utopic account again.\n")
|
|
124
147
|
else:
|
|
125
148
|
sys.stderr.write(
|
|
126
149
|
f"Connection to {endpoint} failed. A key operation may have completed; "
|
|
@@ -130,19 +153,32 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
130
153
|
message = (
|
|
131
154
|
"Session expired or invalid. Run utopic login again." if exc.status == 401 else str(exc)
|
|
132
155
|
)
|
|
156
|
+
if args.command == "add-credit" and exc.status in {409, 503}:
|
|
157
|
+
message = {
|
|
158
|
+
409: "Purchase conflict or reconciliation required. Preserve this purchase ID and its original amount/use; contact support if it persists.",
|
|
159
|
+
503: "Credit checkout is currently unavailable. Try the same Retry command later.",
|
|
160
|
+
}[exc.status]
|
|
133
161
|
sys.stderr.write(message + "\n")
|
|
134
162
|
except ValidationError:
|
|
135
|
-
|
|
136
|
-
"Invalid
|
|
163
|
+
message = (
|
|
164
|
+
"Invalid billing response. For checkout, reuse the printed Retry command."
|
|
165
|
+
if args.command in {"account", "add-credit"}
|
|
166
|
+
else "Invalid gateway response. Check utopic keys list before retrying creation."
|
|
137
167
|
)
|
|
168
|
+
sys.stderr.write(message + "\n")
|
|
138
169
|
except ValueError as exc:
|
|
139
170
|
sys.stderr.write(str(exc) + "\n")
|
|
140
171
|
except OSError:
|
|
141
172
|
sys.stderr.write("Local file or output access failed; check permissions before retrying.\n")
|
|
142
173
|
except KeyboardInterrupt:
|
|
143
|
-
|
|
144
|
-
"
|
|
145
|
-
|
|
174
|
+
if args.command == "add-credit":
|
|
175
|
+
sys.stderr.write("Checkout cancelled. If a Retry command was printed, reuse it.\n")
|
|
176
|
+
elif args.command == "account":
|
|
177
|
+
sys.stderr.write("Account lookup cancelled.\n")
|
|
178
|
+
else:
|
|
179
|
+
sys.stderr.write(
|
|
180
|
+
"Cancelled. Sign-in cancelled or key operation status unknown; check keys list.\n"
|
|
181
|
+
)
|
|
146
182
|
return 130
|
|
147
183
|
finally:
|
|
148
184
|
if gateway is not None:
|
|
@@ -137,10 +137,13 @@ class Gateway:
|
|
|
137
137
|
*,
|
|
138
138
|
token: str = "",
|
|
139
139
|
body: dict[str, Any] | None = None,
|
|
140
|
+
idempotency_key: str | None = None,
|
|
140
141
|
timeout: float = 30,
|
|
141
142
|
) -> Any: # noqa: ANN401 -- external JSON; command models validate the response.
|
|
142
143
|
"""Return decoded JSON or a safe error without request headers or tokens."""
|
|
143
144
|
headers = {"Authorization": "Bearer " + token} if token else {}
|
|
145
|
+
if idempotency_key is not None:
|
|
146
|
+
headers["Idempotency-Key"] = idempotency_key
|
|
144
147
|
try:
|
|
145
148
|
with self._client.stream(
|
|
146
149
|
method, path, headers=headers, json=body, timeout=timeout
|
|
@@ -164,7 +167,7 @@ class Gateway:
|
|
|
164
167
|
) from exc
|
|
165
168
|
except json.JSONDecodeError as exc:
|
|
166
169
|
raise ValueError(
|
|
167
|
-
"Invalid gateway JSON response. Check
|
|
170
|
+
"Invalid gateway JSON response. Check operation status before retrying."
|
|
168
171
|
) from exc
|
|
169
172
|
|
|
170
173
|
def save_session(self, data: dict[str, Any]) -> None:
|
utopic-0.2.0/PKG-INFO
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: utopic
|
|
3
|
-
Version: 0.2.0
|
|
4
|
-
Summary: Sign in to Utopic and manage inference API keys
|
|
5
|
-
Project-URL: Homepage, https://utopic.company
|
|
6
|
-
Project-URL: Source, https://github.com/adavyas/utopic-package-manager
|
|
7
|
-
Author: Adavya Sharma
|
|
8
|
-
License-Expression: Apache-2.0
|
|
9
|
-
License-File: LICENSE
|
|
10
|
-
Requires-Python: >=3.12
|
|
11
|
-
Requires-Dist: httpx<1,>=0.28.1
|
|
12
|
-
Requires-Dist: pydantic<3,>=2.12
|
|
13
|
-
Description-Content-Type: text/plain
|
|
14
|
-
|
|
15
|
-
Utopic CLI
|
|
16
|
-
|
|
17
|
-
Sign in with Google and manage your Utopic inference API keys.
|
|
18
|
-
Requires Python 3.12 or newer. The client uses HTTPS; it runs no model or server.
|
|
19
|
-
|
|
20
|
-
After publication to PyPI:
|
|
21
|
-
uv tool install 'utopic>=0.2.0'
|
|
22
|
-
utopic login
|
|
23
|
-
utopic keys create
|
|
24
|
-
utopic keys list
|
|
25
|
-
utopic keys revoke <key-id>
|
|
26
|
-
uv tool upgrade utopic
|
|
27
|
-
|
|
28
|
-
If uv reports that its executable directory is not on PATH:
|
|
29
|
-
uv tool update-shell
|
|
30
|
-
|
|
31
|
-
Alternatively, use pip within an activated virtual environment:
|
|
32
|
-
python -m pip install --upgrade 'utopic>=0.2.0'
|
|
33
|
-
|
|
34
|
-
For an unpublished build, pass the wheel filename to either installer:
|
|
35
|
-
uv tool install /path/to/utopic-0.2.0-py3-none-any.whl
|
|
36
|
-
python -m pip install /path/to/utopic-0.2.0-py3-none-any.whl
|
|
37
|
-
|
|
38
|
-
Hosted login opens Google directly, prints a verification code, and polls the
|
|
39
|
-
gateway over HTTPS. Authorize only when the browser code matches the terminal.
|
|
40
|
-
Use utopic login --no-browser to print the link without opening a browser.
|
|
41
|
-
No localhost callback or Google client secret is needed on the user's machine.
|
|
42
|
-
|
|
43
|
-
The gateway defaults to https://utopicrt-gateway.fly.dev for compatibility with
|
|
44
|
-
existing sessions. Use utopic --gateway https://api.utopic.company login for the
|
|
45
|
-
custom domain. Credentials are isolated per gateway origin.
|
|
46
|
-
|
|
47
|
-
The existing ~/.local/state/utopic-mcp location is retained only for credential
|
|
48
|
-
compatibility. This distribution includes no MCP server, dependencies or commands.
|
|
49
|
-
--state-dir overrides the directory. On macOS and Linux, credential files are
|
|
50
|
-
owner-only. Windows credential storage has not been qualified.
|
|
51
|
-
|
|
52
|
-
keys create prints the secret once to stdout; save it privately. Never paste it
|
|
53
|
-
into support logs. Keys list emits metadata, not secrets. Creation is never
|
|
54
|
-
automatically retried; after a connection failure, inspect keys list first.
|
|
55
|
-
|
|
56
|
-
Run utopic --help, utopic keys --help, or utopic --version for usage and version.
|
|
57
|
-
python -m utopic_cli invokes the same interface.
|
|
58
|
-
|
|
59
|
-
When migrating an old checkout launcher, move that executable to a backup before
|
|
60
|
-
installing the tool in the same location. Preserve the private credential folder.
|
|
61
|
-
|
|
62
|
-
Migration from utopic 0.1.x
|
|
63
|
-
|
|
64
|
-
Version 0.2.0 replaces the native-runtime package manager with this API-only CLI.
|
|
65
|
-
The old setup, run, models, chat, bridge, server, MCP and ACP commands are removed.
|
|
66
|
-
Existing model downloads are not removed. Keep a separate environment pinned to
|
|
67
|
-
utopic==0.1.7 if you still need the old runtime commands. This release requires
|
|
68
|
-
Python 3.12+, so choose that interpreter explicitly when upgrading an older tool:
|
|
69
|
-
uv tool install --python 3.12 --upgrade 'utopic>=0.2.0'
|
|
70
|
-
|
|
71
|
-
The published package is utopic, maintained by adavyas. The Python import namespace
|
|
72
|
-
is utopic_cli. An existing Google session from the API CLI is reused when the
|
|
73
|
-
gateway origin and private state directory are unchanged.
|
utopic-0.2.0/README.txt
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
Utopic CLI
|
|
2
|
-
|
|
3
|
-
Sign in with Google and manage your Utopic inference API keys.
|
|
4
|
-
Requires Python 3.12 or newer. The client uses HTTPS; it runs no model or server.
|
|
5
|
-
|
|
6
|
-
After publication to PyPI:
|
|
7
|
-
uv tool install 'utopic>=0.2.0'
|
|
8
|
-
utopic login
|
|
9
|
-
utopic keys create
|
|
10
|
-
utopic keys list
|
|
11
|
-
utopic keys revoke <key-id>
|
|
12
|
-
uv tool upgrade utopic
|
|
13
|
-
|
|
14
|
-
If uv reports that its executable directory is not on PATH:
|
|
15
|
-
uv tool update-shell
|
|
16
|
-
|
|
17
|
-
Alternatively, use pip within an activated virtual environment:
|
|
18
|
-
python -m pip install --upgrade 'utopic>=0.2.0'
|
|
19
|
-
|
|
20
|
-
For an unpublished build, pass the wheel filename to either installer:
|
|
21
|
-
uv tool install /path/to/utopic-0.2.0-py3-none-any.whl
|
|
22
|
-
python -m pip install /path/to/utopic-0.2.0-py3-none-any.whl
|
|
23
|
-
|
|
24
|
-
Hosted login opens Google directly, prints a verification code, and polls the
|
|
25
|
-
gateway over HTTPS. Authorize only when the browser code matches the terminal.
|
|
26
|
-
Use utopic login --no-browser to print the link without opening a browser.
|
|
27
|
-
No localhost callback or Google client secret is needed on the user's machine.
|
|
28
|
-
|
|
29
|
-
The gateway defaults to https://utopicrt-gateway.fly.dev for compatibility with
|
|
30
|
-
existing sessions. Use utopic --gateway https://api.utopic.company login for the
|
|
31
|
-
custom domain. Credentials are isolated per gateway origin.
|
|
32
|
-
|
|
33
|
-
The existing ~/.local/state/utopic-mcp location is retained only for credential
|
|
34
|
-
compatibility. This distribution includes no MCP server, dependencies or commands.
|
|
35
|
-
--state-dir overrides the directory. On macOS and Linux, credential files are
|
|
36
|
-
owner-only. Windows credential storage has not been qualified.
|
|
37
|
-
|
|
38
|
-
keys create prints the secret once to stdout; save it privately. Never paste it
|
|
39
|
-
into support logs. Keys list emits metadata, not secrets. Creation is never
|
|
40
|
-
automatically retried; after a connection failure, inspect keys list first.
|
|
41
|
-
|
|
42
|
-
Run utopic --help, utopic keys --help, or utopic --version for usage and version.
|
|
43
|
-
python -m utopic_cli invokes the same interface.
|
|
44
|
-
|
|
45
|
-
When migrating an old checkout launcher, move that executable to a backup before
|
|
46
|
-
installing the tool in the same location. Preserve the private credential folder.
|
|
47
|
-
|
|
48
|
-
Migration from utopic 0.1.x
|
|
49
|
-
|
|
50
|
-
Version 0.2.0 replaces the native-runtime package manager with this API-only CLI.
|
|
51
|
-
The old setup, run, models, chat, bridge, server, MCP and ACP commands are removed.
|
|
52
|
-
Existing model downloads are not removed. Keep a separate environment pinned to
|
|
53
|
-
utopic==0.1.7 if you still need the old runtime commands. This release requires
|
|
54
|
-
Python 3.12+, so choose that interpreter explicitly when upgrading an older tool:
|
|
55
|
-
uv tool install --python 3.12 --upgrade 'utopic>=0.2.0'
|
|
56
|
-
|
|
57
|
-
The published package is utopic, maintained by adavyas. The Python import namespace
|
|
58
|
-
is utopic_cli. An existing Google session from the API CLI is reused when the
|
|
59
|
-
gateway origin and private state directory are unchanged.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|