-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_count_tokens.sh
More file actions
executable file
·53 lines (51 loc) · 1.65 KB
/
Copy pathrun_count_tokens.sh
File metadata and controls
executable file
·53 lines (51 loc) · 1.65 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
#!/usr/bin/env bash
# Usage: CLAUDE_API_KEY=... ./run_count_tokens.sh "Echoes input."
set -euo pipefail
export CLAUDE_API_KEY=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
DESCRIPTION="${1:-Echoes input.}"
if [ -z "${CLAUDE_API_KEY:-}" ]; then
echo "CLAUDE_API_KEY is not set" >&2
exit 1
fi
payload=$(cat <<JSON
{
"model": "claude-sonnet-4-5-20250929",
"messages": [
{ "role": "user", "content": "foo" }
],
"tools": [
{
"name": "mcp__minimalmcp__echo_tool",
"description": "${DESCRIPTION}",
"input_schema": {
"type": "object",
"properties": {
"message": { "type": "string" }
},
"required": ["message"],
"additionalProperties": false,
"\$schema": "http://json-schema.org/draft-07/schema#"
}
}
]
}
JSON
)
set -x
curl -s -X POST "https://api.anthropic.com/v1/messages/count_tokens?beta=true" \
-H "accept: application/json" \
-H "anthropic-beta: claude-code-20250219,oauth-2025-04-20,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14,token-counting-2024-11-01" \
-H "anthropic-dangerous-direct-browser-access: true" \
-H "anthropic-version: 2023-06-01" \
-H "Authorization: Bearer ${CLAUDE_API_KEY}" \
-H "x-app: cli" \
-H "x-stainless-arch: arm64" \
-H "x-stainless-lang: js" \
-H "x-stainless-os: MacOS" \
-H "x-stainless-package-version: 0.68.0" \
-H "x-stainless-retry-count: 0" \
-H "x-stainless-runtime: node" \
-H "x-stainless-runtime-version: v24.3.0" \
-H "Content-Type": "application/json" \
-H "Accept-Encoding: gzip, deflate, br, zstd" \
-d "$payload"