mirror of
https://github.com/anthropics/claude-code-sdk-python.git
synced 2025-07-08 07:05:06 +00:00

This fix addresses issue #2 where Max subscription users encounter a KeyError when the API response doesn't include the 'cost_usd' field. Changes: - Modified ResultMessage dataclass to make cost_usd and total_cost_usd optional (float | None) - Updated client.py to use .get() with None default for cost-related fields - Maintains backward compatibility for users with cost data This ensures the SDK works for all subscription types, including Max subscriptions that don't have access to cost information. By: Unclecode <https://github.com/unclecode>
25 lines
No EOL
695 B
Python
25 lines
No EOL
695 B
Python
#!/usr/bin/env python3
|
|
"""Test script to verify the cost_usd fix works."""
|
|
|
|
import anyio
|
|
from claude_code_sdk import process_query, ClaudeCodeOptions
|
|
|
|
async def main():
|
|
"""Test the SDK with a simple query."""
|
|
print("Testing claude-code-sdk with cost_usd fix...")
|
|
|
|
try:
|
|
# Simple test query
|
|
async for message in process_query(
|
|
"What is 2+2?",
|
|
ClaudeCodeOptions()
|
|
):
|
|
print(f"Message type: {type(message).__name__}")
|
|
print(f"Message: {message}")
|
|
print("-" * 40)
|
|
except Exception as e:
|
|
print(f"Error: {type(e).__name__}: {e}")
|
|
raise
|
|
|
|
if __name__ == "__main__":
|
|
anyio.run(main) |