MCPcopy
hub / github.com/anthropics/anthropic-sdk-python / _prepare_options

Function _prepare_options

src/anthropic/lib/vertex/_client.py:420–452  ·  view source on GitHub ↗
(input_options: FinalRequestOptions, *, project_id: str | None, region: str)

Source from the content-addressed store, hash-verified

418
419
420def _prepare_options(input_options: FinalRequestOptions, *, project_id: str | None, region: str) -> FinalRequestOptions:
421 options = model_copy(input_options, deep=True)
422
423 if is_dict(options.json_data):
424 options.json_data.setdefault("anthropic_version", DEFAULT_VERSION)
425
426 if options.url in {"/v1/messages", "/v1/messages?beta=true"} and options.method == "post":
427 if project_id is None:
428 raise RuntimeError(
429 "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."
430 )
431
432 if not is_dict(options.json_data):
433 raise RuntimeError("Expected json data to be a dictionary for post /v1/messages")
434
435 model = options.json_data.pop("model")
436 stream = options.json_data.get("stream", False)
437 specifier = "streamRawPredict" if stream else "rawPredict"
438
439 options.url = f"/projects/{project_id}/locations/{region}/publishers/anthropic/models/{model}:{specifier}"
440
441 if options.url in {"/v1/messages/count_tokens", "/v1/messages/count_tokens?beta=true"} and options.method == "post":
442 if project_id is None:
443 raise RuntimeError(
444 "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."
445 )
446
447 options.url = f"/projects/{project_id}/locations/{region}/publishers/anthropic/models/count-tokens:rawPredict"
448
449 if options.url.startswith("/v1/messages/batches"):
450 raise AnthropicError("The Batch API is not supported in the Vertex client yet")
451
452 return options

Callers 2

_prepare_optionsMethod · 0.70
_prepare_optionsMethod · 0.70

Calls 4

model_copyFunction · 0.85
is_dictFunction · 0.85
AnthropicErrorClass · 0.85
getMethod · 0.45

Tested by

no test coverage detected