Skip to content

Commit 32eccae

Browse files
authored
fix: make anthropic work in fiddle/vscode (#970)
Anthropic now reacts to the `Origin` header being set, and reacts to such requests complaining about CORS issues. To get around this without magically injecting the Anthropic headers, just delete the `origin` header.
1 parent 847f3a9 commit 32eccae

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

typescript/fiddle-proxy/server.js

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ app.use(
8787
for (const [header, value] of Object.entries(headers)) {
8888
proxyReq.setHeader(header, value)
8989
}
90+
proxyReq.removeHeader('origin')
9091
} catch (err) {
9192
// This is not console.warn because it's not important
9293
console.log('baml-original-url is not parsable', err)

typescript/vscode-ext/packages/vscode/src/extension.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ export function activate(context: vscode.ExtensionContext) {
203203
// Extract the original target URL from the custom header
204204
let originalUrl = req.headers['baml-original-url']
205205
if (typeof originalUrl === 'string') {
206+
// For some reason, Node doesn't like deleting headers in the proxyReq function.
206207
delete req.headers['baml-original-url']
207-
208-
req.headers['origin'] = `http://localhost:${port}`
208+
delete req.headers['origin']
209209

210210
// Ensure the URL does not end with a slash
211211
if (originalUrl.endsWith('/')) {
@@ -218,6 +218,9 @@ export function activate(context: vscode.ExtensionContext) {
218218
},
219219
logger: console,
220220
on: {
221+
proxyReq: (proxyReq, req, res) => {
222+
console.debug('Proxying an LLM request (to bypass CORS)', { proxyReq, req, res })
223+
},
221224
proxyRes: (proxyRes, req, res) => {
222225
proxyRes.headers['Access-Control-Allow-Origin'] = '*'
223226
},

0 commit comments

Comments
 (0)