8000 feat(vertex): support token counting · anthropics/anthropic-sdk-python@45c28dd · GitHub
[go: up one dir, main page]

Skip to content

Commit 45c28dd

Browse files
RobertCraigiestainless-app[bot]
authored andcommitted
feat(vertex): support token counting
1 parent 4e0b15e commit 45c28dd

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/anthropic/lib/vertex/_client.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,15 @@ def _prepare_options(input_options: FinalRequestOptions, *, project_id: str | No
441441

442442
options.url = f"/projects/{project_id}/locations/{region}/publishers/anthropic/models/{model}:{specifier}"
443443

444+
if options.url in {"/v1/messages/count_tokens", "/v1/messages/count_tokens?beta=true"} and options.method == "post":
445+
if project_id is None:
446+
raise RuntimeError(
447+
"No project_id was given and it could not be resolved from credentials. The client should be instantiated with the `project_id` argument or the `ANTHROPIC_VERTEX_PROJECT_ID` environment variable should be set."
448+
)
449+
444450
if is_dict(options.json_data):
445-
options.json_data.pop("model", None)
451+
options.json_data.pop("anthropic_version", None)
452+
453+
options.url = f"/projects/{project_id}/locations/{region}/publishers/anthropic/models/count-tokens:rawPredict"
446454

447455
return options

0 commit comments

Comments
 (0)
0