forked from openai/openai-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmtls_httpx2.py
More file actions
30 lines (26 loc) · 835 Bytes
/
Copy pathmtls_httpx2.py
File metadata and controls
30 lines (26 loc) · 835 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
#!/usr/bin/env -S rye run python
import os
import ssl
from openai import OpenAI, DefaultHttpx2Client
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"),
)
with OpenAI(
api_key=os.environ["OPENAI_API_KEY"],
base_url=os.environ.get(
"OPENAI_BASE_URL",
"https://mtls.api.openai.com/v1",
),
http_client=DefaultHttpx2Client(
verify=ssl_context,
follow_redirects=False,
),
) as client:
print(client.files.list())