Hi Shivam,
Thanks for replying.
Any payload has the same issue. However, the same call via postman (and same API key) doesn’t.
See the snippet below:
import os
import httpx, ssl
from datetime import datetime
import openai
from google import genai
from google.genai import types
import tiktoken
from constants import *
from logger import setup_logger
# Initialize logger
logger = setup_logger(“medsii-ai.openai_func”)
def trace_event(label: str):
*# httpx event hooks receive the request/response; accept \*args to be liberal*
*def hook(\*\_args, \*\*\_kwargs):*
*print(f"{datetime.now().strftime('%H:%M:%S')} {label}")*
*return hook*
# NOTE: The client automatically looks for the GEMINI_API_KEY environment variable.
try:
*GEMINI_API_KEY = os.environ.get('GEMINI_API_KEY')*
*# Force TLS 1.2, avoid TLS 1.3 negotiation stalls*
*ssl_ctx = ssl.create_default_context()*
*ssl_ctx.minimum_version = ssl.TLSVersion.TLSv1_2*
*ssl_ctx.maximum_version = ssl.TLSVersion.TLSv1_2*
*client = genai.Client(*
*api_key=GEMINI_API_KEY,*
*http_options=types.HttpOptions(*
*client_args={*
*"event_hooks": {*
*"request": \[trace_event("→ request start")\],*
*"response": \[trace_event("← response headers")\]*
*},*
*"timeout": httpx.Timeout(connect=5.0, read=20.0, write=10.0, pool=5.0),*
*"trust_env": False, # Good to keep*
*# --- THIS IS THE TEST ---*
*# --- CRITICAL FIX 2: Explicitly set proxies to an empty dictionary ---*
*# This is the most forceful way to tell httpx to NOT use a proxy*
*# for ANY traffic, bypassing even low-level system injections.*
*"proxies": {},*
*# This is NOT for production.*
*# If this is fast, the problem is 100% certificate verification.*
*"verify": False*
*},*
*))*
*models = client.models.list() # this returns a Pager (iterable)*
*for m in models:*
*print(m.name)
The time between request and response headers varies from 30 to 60 srec. You will notice various attempts to bypass proxies etc. in the httpOptions. But even with the default client configuration the issue is the same.
Kind Regards,
Paolo