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

Function _prepare_options

src/anthropic/lib/bedrock/_client.py:40–69  ·  view source on GitHub ↗
(input_options: FinalRequestOptions)

Source from the content-addressed store, hash-verified

38
39
40def _prepare_options(input_options: FinalRequestOptions) -> FinalRequestOptions:
41 options = model_copy(input_options, deep=True)
42
43 if is_dict(options.json_data):
44 options.json_data.setdefault("anthropic_version", DEFAULT_VERSION)
45
46 if is_given(options.headers):
47 betas = options.headers.get("anthropic-beta")
48 if betas:
49 options.json_data.setdefault("anthropic_beta", betas.split(","))
50
51 if options.url in {"/v1/complete", "/v1/messages", "/v1/messages?beta=true"} and options.method == "post":
52 if not is_dict(options.json_data):
53 raise RuntimeError("Expected dictionary json_data for post /completions endpoint")
54
55 model = options.json_data.pop("model", None)
56 model = urllib.parse.quote(str(model), safe=":")
57 stream = options.json_data.pop("stream", False)
58 if stream:
59 options.url = f"/model/{model}/invoke-with-response-stream"
60 else:
61 options.url = f"/model/{model}/invoke"
62
63 if options.url.startswith("/v1/messages/batches"):
64 raise AnthropicError("The Batch API is not supported in Bedrock yet")
65
66 if options.url == "/v1/messages/count_tokens":
67 raise AnthropicError("Token counting is not supported in Bedrock yet")
68
69 return options
70
71
72def _infer_region() -> str:

Callers 2

_prepare_optionsMethod · 0.70
_prepare_optionsMethod · 0.70

Calls 5

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

Tested by

no test coverage detected