aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClaude <claude@anthropic.com>2026-03-04 18:44:46 +0100
committerClaude <claude@anthropic.com>2026-03-04 18:44:46 +0100
commitf9cc162f1520d4d84dc37f9a244fae43235f1f5d (patch)
tree0020615e7192961adcd843f067cc9cfa3d9c7b67
parent3eddbbe41ea3a912e695bf2589fc99d25381620d (diff)
parent07c47fbdbb2cd845ac493926880f101eb79838dc (diff)
downloadclaude-py-main.tar.gz
claude-py-main.zip
Add ability to list modelsHEADmain
-rw-r--r--src/claude/chat.py14
-rw-r--r--src/claude/cli.py6
2 files changed, 18 insertions, 2 deletions
diff --git a/src/claude/chat.py b/src/claude/chat.py
index 6c009d7..64be99b 100644
--- a/src/claude/chat.py
+++ b/src/claude/chat.py
@@ -13,6 +13,12 @@ import httpx
from .streaming import StreamParser, parse_sse_stream
from .types import AssistantMessage, StreamChunk, ToolHandler, ToolResult, ToolUse
+MODELS: dict[str, dict[str, str]] = {
+ "claude-haiku-4-5-20251001": {"family": "haiku", "display": "Haiku 4.5"},
+ "claude-sonnet-4-6": {"family": "sonnet", "display": "Sonnet 4.6"},
+ "claude-opus-4-6": {"family": "opus", "display": "Opus 4.6"},
+}
+
BETA_BASE = "oauth-2025-04-20,interleaved-thinking-2025-05-14,prompt-caching-scope-2026-01-05,claude-code-20250219"
BETA_ADAPTIVE = "claude-code-20250219,oauth-2025-04-20,interleaved-thinking-2025-05-14,prompt-caching-scope-2026-01-05,effort-2025-11-24,adaptive-thinking-2026-01-28"
@@ -26,6 +32,10 @@ class ChatClient:
BASE_URL = "https://api.anthropic.com"
API_VERSION = "2023-06-01"
+ @staticmethod
+ def list_models() -> dict[str, dict[str, str]]:
+ return dict(MODELS)
+
def __init__(
self,
api_key: str | None = None,
@@ -131,7 +141,7 @@ class ChatClient:
)
url = f"{self.BASE_URL}/v1/messages"
- last_error = None
+ last_error: Exception | None = None
backoff = self.backoff_factor
for attempt in range(self.max_retries):
try:
@@ -143,7 +153,7 @@ class ChatClient:
if attempt < self.max_retries - 1:
await asyncio.sleep(backoff)
backoff *= 2
- raise last_error
+ raise last_error # type: ignore[misc]
async def stream(
self,
diff --git a/src/claude/cli.py b/src/claude/cli.py
index d688939..47d3d0d 100644
--- a/src/claude/cli.py
+++ b/src/claude/cli.py
@@ -14,10 +14,16 @@ def parse_args() -> argparse.Namespace:
p.add_argument("-s", "--system", default=None, help="System prompt")
p.add_argument("--max-tokens", type=int, default=8192)
p.add_argument("--no-stream", action="store_true", help="Disable streaming")
+ p.add_argument("--list-models", action="store_true", help="List available models and exit")
return p.parse_args()
async def run(args: argparse.Namespace) -> None:
+ if args.list_models:
+ for model_id, info in ChatClient.list_models().items():
+ print(f" {model_id:<35} {info['display']}")
+ return
+
if args.prompt:
prompt = " ".join(args.prompt)
elif not sys.stdin.isatty():