claude-api
Audited by Runlayer on Mar 4, 2026
Malicious tool definition detected
Use Token Counting Before Requests ```python count_response = client.messages.count_tokens( model="claude-opus-4-6", messages=messages, system=system ) estimated_input_cost = count_response.input_tokens * 0.000005 # $5/1M tokens print(f"Estimated input cost: ${estimated_input_cost:.4f}") ``` --- ## Retry with Exponential Backoff > **Note:** The Anthropic SDK automatically retries rate limit (429) and server errors (5xx) with exponential backoff.
Tool passed security scan
Malicious tool definition detected
Use Token Counting Before Requests ```typescript const countResponse = await client.messages.countTokens({ model: "claude-opus-4-6", messages: messages, system: system, }); const estimatedInputCost = countResponse.input_tokens * 0.000005; // $5/1M tokens console.log(`Estimated input cost: $${estimatedInputCost.toFixed(4)}`); ```
Tool passed security scan
Malicious tool definition detected
memory = MyMemoryTool() # Use with tool runner runner = client.beta.messages.tool_runner( model="claude-opus-4-6", max_tokens=2048, tools=[memory], messages=[{"role": "user", "content": "Remember my preferences"}], ) for message in runner: print(message) ``` For full implementation examples, use WebFetch: - `https://github.com/anthropics/anthropic-sdk-python/blob/main/examples/memory/basic.py` --- ## Structured Outputs ### JSON Outputs (Pydantic — Recommended) ```python from pydantic import Base
Malicious tool definition detected
print(f"Status: {cancelled.processing_status}") # "canceling" ``` --- ## Batch with Prompt Caching ```python shared_system = [ {"type": "text", "text": "You are a literary analyst."}, { "type": "text", "text": large_document_text, # Shared across all requests "cache_control": {"type": "ephemeral"} } ] message_batch = client.messages.batches.create( requests=[ Request( custom_id=f"analysis-{i}", params=MessageCreateParamsNonStreaming( model="claude-opus-4-6", max_tokens=1024, system=shared_syst
Tool passed security scan
Malicious tool definition detected
**Critical:** Append `response.content` (not just the text) back to your messages on every turn. Compaction blocks in the response must be preserved — the API uses them to replace the compacted history on the next request. Extracting only the text string and appending that will silently lose the compaction state. See `{lang}/claude-api/README.md` (Compaction section) for code examples.
Tool passed security scan
Tool passed security scan
Tool passed security scan
Tool passed security scan
Tool passed security scan
Tool passed security scan
Tool passed security scan
Passed Files (14)Click to expand
Tool passed security scan
Tool passed security scan
Tool passed security scan
Tool passed security scan
Tool passed security scan
Tool passed security scan
Tool passed security scan
Tool passed security scan
Tool passed security scan
Tool passed security scan
Tool passed security scan
Tool passed security scan
Tool passed security scan
Tool passed security scan