Skip to content

TypeError: Failed to fetch #466

Description

@sonicviz

I'm running a prototype locally and keep getting error: TypeError: Failed to fetch (see below).

Error: Connection error.
at Anthropic.makeRequest (core.mjs:297:1)
at async Proxy.sendPrompt (AIWriter2.vue:132:1)Caused by: TypeError: Failed to fetch
at Anthropic.fetchWithTimeout (core.mjs:354:1)
at Anthropic.makeRequest (core.mjs:286:1)
at async Proxy.sendPrompt (AIWriter2.vue:132:1)
AIWriter2.vue:150 Connection error.

The code and api key look fine. I have a similar test with OpenAI and no connection errors, it works fine.
I can also call Anthropic aok via a server function.

Unsure why this local call is giving me so much grief.
Setup looks fine, all the headers should be set automatically according to the docs.

.env file has ANTHROPIC_API_KEY = ""
and code is
const anthropic = new Anthropic({
apiKey: process.env['ANTHROPIC_API_KEY'], // This is the default and can be omitted
});

No errors on setup.

But the call
const message = await anthropic.messages.create({
max_tokens: 1024,
messages: [{ role: 'user', content: aiprompt.value }],
model: "claude-3-haiku-20240307",
});
just keeps giving me
Error: Connection error.
at Anthropic.makeRequest (core.mjs:297:1)
at async Proxy.sendPrompt (AIWriter2.vue:132:1)Caused by: TypeError: Failed to fetch
at Anthropic.fetchWithTimeout (core.mjs:354:1)
at Anthropic.makeRequest (core.mjs:286:1)
at async Proxy.sendPrompt (AIWriter2.vue:132:1)
AIWriter2.vue:150 Connection error.

What's up with that?
Is there some restriction on connecting from local development?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions