我在集成“https://api.anthropic.com/v1/messages”时遇到 CORS 问题,
有人解决了吗?
try {
const response = await axios.post(
'https://api.anthropic.com/v1/messages',
{
model: "claude-3-5-sonnet-20240620",
max_tokens: 1024,
messages: [
{ "role": "user", "content": "one word" }
]
},
{
headers: {
'x-api-key': 'APIKey',
'anthropic-version': '2023-06-01',
'content-Type': 'application/json',
},
}
);
console.log('Model used:', response.data.model);
return response?.data?.choices[0]?.message?.content?.trim();
} catch (error) {
console.error('Error:', error.response ? error.response.data : error.message);
throw error;
}
您能分享一下错误吗?您是否从其他服务器或本地主机使用它?