Skip to content

Commit 4f78277

Browse files
httpx client for python
1 parent 2025d92 commit 4f78277

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

api-reference/sdk/python.mdx

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,38 @@ async def main():
101101
asyncio.run(main())
102102
```
103103

104+
## Using a Custom httpx Client
104105

105-
### Adding Trace ID or Metadata
106+
If you need to customize HTTP networking—for example, to disable SSL verification due to VPNs like Zscaler or to use custom proxies—you can pass your own `httpx.Client` to the Portkey SDK.
107+
108+
<Warning>Disabling SSL certificate verification is insecure and should only be used for debugging or in trusted internal environments. Never use this in production.</Warning>
109+
110+
**Example: Disable SSL Verification**
111+
```python
112+
import httpx
113+
from portkey_ai import Portkey
114+
115+
# Create an httpx client with SSL verification disabled
116+
custom_client = httpx.Client(verify=False)
117+
118+
portkey = Portkey(
119+
api_key="your_api_key_here",
120+
virtual_key="your_virtual_key_here",
121+
http_client=custom_client
122+
)
123+
124+
response = portkey.chat.completions.create(
125+
messages=[{"role": "user", "content": "Hello!"}],
126+
model="gpt-4o"
127+
)
128+
print(response)
129+
```
130+
131+
- You can use any `httpx.Client` options (e.g., for proxies, timeouts, custom headers).
132+
- For async usage, pass an `httpx.AsyncClient` to `AsyncPortkey`.
133+
- See [OpenAI Python SDK: Configuring the HTTP client](https://github.com/openai/openai-python#configuring-the-http-client) for more examples and best practices.
134+
135+
## Adding Trace ID or Metadata
106136

107137
You can choose to override the configuration in individual requests as well and send trace id or metadata along with each request.
108138

@@ -156,6 +186,9 @@ completion = portkey.with_options(
156186
<Accordion title="Can I use this SDK with OpenAI-compatible code?">
157187
Yes! Portkey’s Python SDK is OpenAI-compatible. You can also use any OpenAI-compatible library by pointing it to the Portkey API endpoint and using your Portkey API key.
158188
</Accordion>
189+
<Accordion title="How do I fix CERTIFICATE_VERIFY_FAILED or SSL errors?">
190+
If you are behind a VPN (like Zscaler) or a corporate proxy and see SSL/certificate errors, you can pass a custom `httpx.Client` to the Portkey SDK with SSL verification disabled. See the docs above for an example. **Warning:** Disabling SSL verification is insecure—only use this as a last resort or for debugging.
191+
</Accordion>
159192
<Accordion title="Where can I find more examples?">
160193
Check out our integration docs [here](/integrations/ecosystem).
161194
</Accordion>

0 commit comments

Comments
 (0)