sdk-client
Use LeptonAI's Python SDK Client and v2 API resource/model objects safely from scripts and notebooks.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- sdk-client
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- Use LeptonAI's Python SDK Client and v2 API resource/model objects safely from scripts and notebooks.
- disable-model-invocation
- true
02 资源文件 6
- 参考文档references/api-resources.md7.7 KB
- 参考文档references/client-api.md7.1 KB
- 参考文档references/specs-and-models.md6.6 KB
- 参考文档references/troubleshooting.md7.9 KB
- 脚本scripts/client_path_tree_demo.py3.2 KB
- 脚本scripts/sdk_introspection.py5.5 KB
03 SKILL.md 正文
sdk-client
Use this sub-skill when the task is to call a deployed Lepton endpoint from Python, inspect endpoint OpenAPI-derived methods, or build SDK scripts/notebooks with leptonai.api.v2 resource objects and Pydantic models.
Route here for
Client(workspace_or_url, deployment=None, token=None, stream=None, chunk_size=None, timeout=None, no_check=False, http2=True)endpoint-call code.local(port),Client.local(port),current(), andClient.current()usage.- Dynamic
PathTreebehavior for OpenAPI paths exposed as Python attributes. APIClient(...)workspace API resource objects and their method surfaces.APIResourse.safe_json(...)model serialization and v2 Pydantic spec construction.- Pure parsing helpers
make_mounts_from_strings(...)andmake_env_vars_from_strings(...).
Route elsewhere
- Workspace login, workspace record maintenance, token refresh, or auth setup: use the
workspace-and-authroute. - Shell-first workload recipes such as endpoint/job/pod/Ray/finetune create/list/update/delete: use the
workload-managementroute. - Storage, secrets, ingress, or canary routing plans: use the storage/ingress route even when SDK model helpers appear in the plan.
Safety rule
Creating a Client(...) for a real URL or workspace endpoint performs network checks and tries to fetch openapi.json. APIClient resource methods perform authenticated workspace API requests. Do not run live or credentialed cloud calls unless the user has explicitly authorized the operation and supplied an appropriate workspace context. The bundled scripts in this sub-skill are designed to avoid network calls.
Quick starts
Inspect the installed SDK without network calls
python scripts/sdk_introspection.py
python scripts/client_path_tree_demo.py
The first script prints the installed package version, important signatures, and APIClient resource method surfaces without constructing a live workspace client. The second script demonstrates PathTree and local(...) behavior with fake callables only.
Call a deployed endpoint from Python
import os
from leptonai.client import Client, local
# Local endpoint URL plan; constructing the client contacts the local service.
c = Client(local(port=8080), timeout=60, no_check=True)
print(list(c.paths()))
# Workspace endpoint URL plan; pass an auth token explicitly if the endpoint is private.
remote = Client(
"workspace-id",
"endpoint-name",
token=os.environ.get("LEPTON_WORKSPACE_TOKEN"),
timeout=None,
)
# OpenAPI path /run becomes remote.run(...)
result = remote.run(inputs="hello")
For dynamic path rules, streaming return behavior, and failure modes, read client-api.md.
Build v2 specs without cloud calls
from leptonai.api.v2.api_resource import APIResourse
from leptonai.api.v2.spec_utils import make_env_vars_from_strings, make_mounts_from_strings
from leptonai.api.v2.types.common import Metadata
from leptonai.api.v2.types.deployment import LeptonDeployment, LeptonDeploymentUserSpec
spec = LeptonDeployment(
metadata=Metadata(name="example"),
spec=LeptonDeploymentUserSpec(
envs=make_env_vars_from_strings(["MODE=test"], ["API_SECRET"]),
mounts=make_mounts_from_strings(["/data:/mnt/data:node-local"]),
),
)
payload = APIResourse.safe_json(APIResourse.__new__(APIResourse), spec)
For resource surfaces, serialization caveats, and spec helpers, read api-resources.md and specs-and-models.md.
Troubleshooting index
- OpenAPI path not found, invalid identifier, or confusing attribute name: troubleshooting.md.
current()says no current workspace: troubleshooting.md.- 401/403/auth token required: troubleshooting.md.
- Pydantic v1/v2 model or validator issues: troubleshooting.md.
safe_jsondroppedNoneunexpectedly or rejected a dict: troubleshooting.md.- Mount/env parsing errors: troubleshooting.md.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).