Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORS: Message API return CORS issues. #410

Closed
firllyw opened this issue May 7, 2024 · 6 comments
Closed

CORS: Message API return CORS issues. #410

firllyw opened this issue May 7, 2024 · 6 comments

Comments

@firllyw
Copy link

firllyw commented May 7, 2024

image

Step to Reproduce:

`const anthropic = new Anthropic({
apiKey: process.env.NEXT_PUBLIC_ANTHROPIC_API_KEY,
});

function MyDiagrams() {
const [loading, setLoading] = useState(false);

const askClaude = async (question) => {
    setLoading(true);
    
    const msg = await anthropic.messages.create({
        model: "claude-3-opus-20240229",
        max_tokens: 4000,
        temperature: 0,
        system: "some prompt engineering here",
        messages: [
            {
                "role": "user",
                "content": [
                    {
                        "type": "text",
                        "text": question
                    }
                ]
            }
        ]
    })

    if (!msg) {
        toast.error('Failed to get response from Claude');
        setLoading(false);
        return;
    }

    setLoading(false);
}

export default MyDiagrams;
`

snippet above is from a Page.js . 

Live app: https://flowy-ai.netlify.app/dashboard/my-diagrams/create
@BrandonStudio
Copy link

Before sending POST request, broswer will first send an OPTIONS preflight request to API (e.g. https://api.anthropic.com/v1/messages). But right now Anthropic API endpoint does not allow OPTIONS method.

@aaronvg
Copy link

aaronvg commented May 11, 2024

Also running into this issue. Anthropic APIs are not callable from the client-side without a proxy server

@cwray-sdc
Copy link

Also seeing this issue when calling from localhost.

@rattrayalex
Copy link
Collaborator

Dup of #219

@rattrayalex rattrayalex closed this as not planned Won't fix, can't repro, duplicate, stale May 11, 2024
@x5a
Copy link
Contributor

x5a commented Aug 21, 2024

@firllyw + thread: our latest SDK release now offers CORS support [changelog].

@x5a x5a closed this as completed Aug 21, 2024
@EliasPereirah
Copy link

EliasPereirah commented Oct 2, 2024

Any updates on this? I'm creating an interface but it doesn't work for Anthropic due to this error.
https://github.com/EliasPereirah/OrionChat/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants