# Proxy Authentication Required 407

**URL:** <https://forum.langchain.com/t/proxy-authentication-required-407/3877>\
**Category:** LangGraph\
**Tags:** python-help\
**Created:** [June 4, 2026, 1:36pm UTC](https://forum.langchain.com/t/proxy-authentication-required-407/3877 "2026-06-04T13:36:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![letsmoto](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/letsmoto/32/3108_2.png) [@letsmoto](https://forum.langchain.com/u/letsmoto)\
**Post date:** [June 4, 2026, 1:36pm UTC](https://forum.langchain.com/t/proxy-authentication-required-407/3877/1 "2026-06-04T13:36:10Z")

</div>

Hello. Please help to improve code to communicate with model via class ChatOpenAI (from langchain\_openai import ChatOpenAI).

Now I have error “Proxy Authentication Required 407”

I’ve tried different options for about 2 weeks and I’m already giving up.I tried using clientx, but in vain.

my code:

```python

from langchain_openai import ChatOpenAI
from langchain_core.message import HumanMessage, AIMessage

```

```python
class LLMClient:

```

def **init** (self):  
self.model = “Qwen3-Coder-Next-FP8”  
self.headers = {  
“Authorization”: “Bearer eyJ…”  
}

```python
self.llm = ChatOpenAI (
  model = self.model,
  api_key = "None",
  base_url = "https://mysite.com/codegen/v1",
  temperature=0.5,
  default_headers=self.headers
)

```

def SendMessage:  
messages =   
messages.appdend({“role”:“user”, “content”: “Hello my friend”})

```auto
langchain_messages = []
for msg in messages:
   if msg["role"] == "user":
     langchain_messages.append(HumanMessage(content=msg["content"]))
     
response = await self.llm.ainvoke([HumanMessage(content=langchain_messages)])
print(response.content)

---
Another way exclude ChatOpenAI working good:
import asyncio
from aiohttp import ClientSession, ClientTimeout

class HTTPClient():
  def __init__ (self):
    self.model = "Qwen3-Coder-Next-FP8",
    self.api_key = "None",
    self.max_retries = 3
    self.base_url = "https://mysite.com/codegen/v1/chat/completions",
    self.temperature=0.5,
    self.headers = {
      "Content-Type": "application/json",
      "Authentication": "Bearer eyJ......"
    }
  
  async def _call_llm_with_rety(self, messages:list, max_retries: int = None) -> Optional[str]:
    url = self.base_url
    
    for attempt in range (max_retries + 1 ):
      try:
        timeout = ClientTimeout(total=self.timeout)
        async with ClintSession(timeout=timeout) as session:
          headers= self.headers
          payload = { "model": self.model, "messages": messages, "temperature": 0.1 }
          
          async with session.post(url, json=payload, headers=headers) as response:
            if response.status == 200:
              data = await response.json()
              return data.get("choises", [{}])[0].get("message", {}).get("content", "")

--- Please help!

```

---

<div class="post-metadata">

**Author:** ![keenborder786](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/keenborder786/32/1757_2.png) [@keenborder786](https://forum.langchain.com/u/keenborder786)\
**Post date:** [June 5, 2026, 5:35am UTC](https://forum.langchain.com/t/proxy-authentication-required-407/3877/2 "2026-06-05T05:35:28Z")

</div>

Hi @letsmoto welcome to the langchain community, **407 means an HTTP proxy wants credentials** , not that your API rejected the Bearer token (that’s usually 401/403).

`ChatOpenAI` uses **httpx** , which follows `HTTP_PROXY` / `HTTPS_PROXY` and system proxy settings. Your **aiohttp** call likely skips the proxy, so it works while LangChain hits the proxy and gets 407.

**Check:**

```python
import os
print({k: os.environ[k] for k in os.environ if "proxy" in k.lower()})

```

**If you don’t need a proxy** (same path as aiohttp):

```python
import httpx
from langchain_openai import ChatOpenAI
from langchain_core.messages import HumanMessage

llm = ChatOpenAI(
    model="Qwen3-Coder-Next-FP8",
    api_key="YOUR_TOKEN",
    base_url="https://mysite.com/codegen/v1",
    http_client=httpx.Client(trust_env=False),
    http_async_client=httpx.AsyncClient(trust_env=False),
)
response = await llm.ainvoke([HumanMessage(content="Hello my friend")])

```

**If you need the proxy** , set credentials via `openai_proxy="http://user:pass@proxy:8080"` or `HTTPS_PROXY` with auth.

**Also fix in your snippet:**

- Use `api_key="YOUR_TOKEN"`, not `"None"`.
- `base_url` = `.../v1` only (no `/chat/completions`).
- `from langchain_core.messages import HumanMessage`

---

<div class="post-metadata">

**Author:** ![letsmoto](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/letsmoto/32/3108_2.png) [@letsmoto](https://forum.langchain.com/u/letsmoto)\
**Post date:** [June 30, 2026, 2:53pm UTC](https://forum.langchain.com/t/proxy-authentication-required-407/3877/3 "2026-06-30T14:53:13Z")

</div>

Something else helped me. Everything turned out to be much simpler.  
Let me clarify that I have Windows.  
I added  
import truststore  
import pip-system-certs  
next:  
llm = ChatOpenAI(  
model=model,  
openai\_api\_key=my\_token,  
openai\_api\_base=url,  
temperature=0.7,  
**openai\_proxy=None**  
)

---

<div class="post-metadata">

**Author:** ![keenborder786](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/keenborder786/32/1757_2.png) [@keenborder786](https://forum.langchain.com/u/keenborder786)\
**Post date:** [June 30, 2026, 4:01pm UTC](https://forum.langchain.com/t/proxy-authentication-required-407/3877/4 "2026-06-30T16:01:12Z")

</div>

@letsmoto if that works for can you mark your answer as solution so it is helpful for other members of the community.
