-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsdk_quick_start.py
More file actions
64 lines (52 loc) · 2.1 KB
/
Copy pathsdk_quick_start.py
File metadata and controls
64 lines (52 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""
SDK quick start — autonomous first-time flow.
Run:
pip install pathcourse-sdk
python python/sdk_quick_start.py \
--tx 0xYOUR_DEPOSIT_TX \
--wallet 0xYOUR_SENDING_WALLET
What this does:
1. Calls pathcourse.claim_key(tx_hash, wallet) to retrieve an API key for
your on-chain deposit. Polls up to ~3 min while the gateway reconciles
your USDC transfer on Base.
2. Constructs a PathCourseClient with the returned key.
3. Makes a single pch-fast inference call so you can verify the full loop.
If you already have a saved API key and just want to test the client,
set PCH_API_KEY instead and skip --tx / --wallet.
"""
import argparse
import os
import sys
import pathcourse
from pathcourse import PathCourseClient, PCH_FAST
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("--tx", help="Base L2 tx hash of your USDC deposit to the PCH treasury")
parser.add_argument("--wallet", help="Sending wallet address (0x...)")
args = parser.parse_args()
api_key = os.environ.get("PCH_API_KEY")
if not api_key:
if not args.tx or not args.wallet:
print("Provide PCH_API_KEY, or both --tx and --wallet.", file=sys.stderr)
return 1
print(f"Claiming API key for deposit {args.tx[:10]}... ", flush=True)
result = pathcourse.claim_key(tx_hash=args.tx, wallet=args.wallet)
api_key = result["api_key"]
print(f" tier : {result.get('tier')}")
print(f" balance : {result.get('balance_usdc')} USDC")
print(f" agent_id : {result.get('agent_id')}")
print(" Save this key — it is only shown once.")
client = PathCourseClient(api_key=api_key)
assert client.verify_key(), "API key rejected by gateway"
print("verify_key -> OK\n")
resp = client.chat(
messages=[{"role": "user", "content": "Reply with exactly: SDK smoke test OK"}],
model=PCH_FAST,
max_tokens=20,
)
print(f"model : {resp.model}")
print(f"response : {resp.content!r}")
print(f"usage : {resp.usage}")
return 0
if __name__ == "__main__":
sys.exit(main())