MCPcopy Create free account
hub / github.com/anthropics/anthropic-sdk-python / new_client

Function new_client

tests/test_tracing.py:126–146  ·  view source on GitHub ↗

Constructs a client, which reads the environment. One that is given a `server` sends its requests there.

(request: pytest.FixtureRequest)

Source from the content-addressed store, hash-verified

124
125@pytest.fixture(params=[Anthropic, AsyncAnthropic], ids=["sync", "async"])
126def new_client(request: pytest.FixtureRequest) -> NewClient:
127 """Constructs a client, which reads the environment. One that is given a `server` sends its requests there."""
128
129 def new(server: Server | None = None, open_telemetry: OpenTelemetryClientOption = None) -> Client:
130 http_client: Any = None
131 if server is not None:
132 http_client_class = httpx2.Client if request.param is Anthropic else httpx2.AsyncClient
133 http_client = http_client_class(transport=httpx2.MockTransport(server))
134 return cast(
135 Client,
136 request.param(
137 base_url=base_url,
138 api_key=api_key,
139 _strict_response_validation=True,
140 http_client=http_client,
141 open_telemetry=open_telemetry,
142 max_retries=1,
143 ),
144 )
145
146 return new
147
148
149async def call(client: Client, **options: Any) -> None:

Calls

no outgoing calls

Tested by

no test coverage detected