forked from openai/openai-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmtls_httpx2_async.py
More file actions
36 lines (29 loc) · 1019 Bytes
/
Copy pathmtls_httpx2_async.py
File metadata and controls
36 lines (29 loc) · 1019 Bytes
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
#!/usr/bin/env -S rye run python
import os
import ssl
import asyncio
from openai import AsyncOpenAI, DefaultAsyncHttpx2Client
async def main() -> None:
ssl_context = ssl.create_default_context(
cafile=os.environ.get("OPENAI_MTLS_CA_BUNDLE"),
)
ssl_context.load_cert_chain(
# Leaf certificate first; if intermediate-chain support is enabled,
# follow it with all required intermediates.
certfile=os.environ["OPENAI_MTLS_CERTIFICATE_CHAIN"],
keyfile=os.environ["OPENAI_MTLS_PRIVATE_KEY"],
password=os.environ.get("OPENAI_MTLS_PRIVATE_KEY_PASSWORD"),
)
async with AsyncOpenAI(
api_key=os.environ["OPENAI_API_KEY"],
base_url=os.environ.get(
"OPENAI_BASE_URL",
"https://mtls.api.openai.com/v1",
),
http_client=DefaultAsyncHttpx2Client(
verify=ssl_context,
follow_redirects=False,
),
) as client:
print(await client.files.list())
asyncio.run(main())