-
Notifications
You must be signed in to change notification settings - Fork 782
Open
Labels
Description
What Happened?
Yo guys!
When do request to anthropic provider (with streaming disabled), response got enriched with content-length header along with transfer-encoded: chunk header, which causes error on the client side due to wrong HTTP/1.1 response structure.
I investigated a issue a bit, adding middleware at the end of the chain and found that content-length header is actually removed.
So I can say that it happens when we give response object to node.js http service, which does this enrichment.
Environment
Node.js: v20.19.5, v22.14.0 and v22.16.0.
Command: npm run dev:node
Positive
When run with wrangler - issue is not present.
What Should Have Happened?
content-length header must not be present in response along with transfer-encoded: chunk header. According to HTTP/1.1 spec.
Relevant Code Snippet
import { ChatOpenAI } from '@langchain/openai';
const AI_GATEWAY_URL = 'http://localhost:8787/v1';
const AI_GATEWAY_API_KEY = 'super-duper-secret-unhackable-api-key';
const model = new ChatOpenAI({
apiKey: AI_GATEWAY_API_KEY,
configuration: {
baseURL: AI_GATEWAY_URL,
defaultHeaders: createHeaders({
strictOpenAiCompliance: false,
config: {
strategy: {
mode: 'loadbalance',
},
targets: [
{
provider: 'anthropic',
api_key: process.env.ANTHROPIC_API_KEY,
override_params: {
model: 'claude-haiku-4-5-20251001',
},
},
],
},
}),
},
});
await model.invoke('Hello, world!');Your Twitter/LinkedIn
narengogi