@@ -269,6 +269,7 @@ async def edge():
269269
270270if no_sentinel :
271271 openai_sentinel_tokens_cache = {}
272+ openai_sentinel_cookies_cache = {}
272273
273274 @app .post ("/backend-api/sentinel/chat-requirements" )
274275 async def sentinel_chat_conversations (request : Request ):
@@ -309,8 +310,12 @@ async def sentinel_chat_conversations(request: Request):
309310 config = get_config (user_agent , session_id )
310311 p = get_requirements_token (config )
311312 data = {'p' : p }
312- r = await clients .post (f'{ host_url } /backend-api/sentinel/chat-requirements' , headers = headers , json = data ,
313- timeout = 10 )
313+ for cookie in openai_sentinel_cookies_cache .get (req_token , []):
314+ clients .session .cookies .set (** cookie )
315+ r = await clients .post (f'{ host_url } /backend-api/sentinel/chat-requirements' , headers = headers , json = data , timeout = 10 )
316+ oai_sc = r .cookies .get ("oai-sc" )
317+ if oai_sc :
318+ openai_sentinel_cookies_cache [req_token ] = [{"name" : "oai-sc" , "value" : oai_sc }]
314319 if r .status_code != 200 :
315320 raise HTTPException (status_code = r .status_code , detail = "Failed to get chat requirements" )
316321 resp = r .json ()
@@ -321,7 +326,7 @@ async def sentinel_chat_conversations(request: Request):
321326 try :
322327 if turnstile_solver_url :
323328 res = await client .post (turnstile_solver_url ,
324- json = {"url" : "https://chatgpt.com" , "p" : p , "dx" : turnstile_dx })
329+ json = {"url" : "https://chatgpt.com" , "p" : p , "dx" : turnstile_dx , "ua" : user_agent })
325330 turnstile_token = res .json ().get ("t" )
326331 except Exception as e :
327332 logger .info (f"Turnstile ignored: { e } " )
@@ -419,7 +424,7 @@ async def chat_conversations(request: Request):
419424 try :
420425 if turnstile_solver_url :
421426 res = await client .post (turnstile_solver_url ,
422- json = {"url" : "https://chatgpt.com" , "p" : p , "dx" : turnstile_dx })
427+ json = {"url" : "https://chatgpt.com" , "p" : p , "dx" : turnstile_dx , "ua" : user_agent })
423428 turnstile_token = res .json ().get ("t" )
424429 except Exception as e :
425430 logger .info (f"Turnstile ignored: { e } " )
0 commit comments