If your company uses a proxy to access external APIs, you need to configure the appropriate environment variables to allow the connection to our API's Python client.
Configuration Example
Here is an example of code to configure an OpenAI client through a proxy:
import os
import httpx
import ssl
from openai import OpenAI as OpenAICompatibleClient
# Create SSL context using system certificates
ssl_context = ssl.create_default_context()
ssl_context.load_default_certs()
base_url = "https://<PARADIGM_URL>/api/v2"
api_key = <YOUR_API_KEY>
# Set proxy and no_proxy environment variables
os.environ["HTTP_PROXY"] = "http://proxy.example.com:port"
os.environ["HTTPS_PROXY"] = "https://proxy.example.com:port"
os.environ["NO_PROXY"] = "localhost,127.0.0.1"
# Create client with system certificates and proxy configuration
client = OpenAICompatibleClient(
base_url=base_url,
api_key=api_key,
http_client=httpx.Client(
verify=False
)
)
Explanation of parameters:
- "HTTP_PROXY" / "HTTPS_PROXY"
: Address and port of the proxy used for HTTP(S) connections.
- NO_PROXY
: List of addresses that should bypass the proxy.
- ssl.create_default_context()
: Allows the use of system certificates to secure the connection.
- verify=ssl_context
: Ensures a secure connection using the defined SSL context.
- proxies=os.environ["HTTPS_PROXY"]
: Activates the use of the proxy set in the environment variables.
This approach ensures a secure connection and compliance with your company's network constraints.