Everything broke
NeoPrint3D opened this issue ยท 30 comments
I'm not sure if someone removed the Claude description on npm, but nevertheless, it broke on two of my projects and will not output anything
same issue for me +1
Please settle it as soon as possible
Hi guys, really not sure what's going on. I've been looking into it and they've changed a lot of stuff so it's really hard to debug what's going on. I'll look into this more later as I'm really busy right now but if someone gets it working again feel free to submit a PR.
Sorry, I realize this is pretty urgent but I just don't have the time to fix it right now due to irl stuff.
Happy to transfer this to another maintainer as well if that would interest anyone
Hi guys, really not sure what's going on. I've been looking into it and they've changed a lot of stuff so it's really hard to debug what's going on. I'll look into this more later as I'm really busy right now but if someone gets it working again feel free to submit a PR.
Sorry, I realize this is pretty urgent but I just don't have the time to fix it right now due to irl stuff.
It seems Claude blocked non-browser traffic based on TLS fingerprint.
I saw in python, have solution, use module curl_cffi, may be use curl can pass it
https://github.com/KoushikNavuluri/Claude-API/blob/main/claude-api/claude_api.py
@Explosion-Scratch Plz try to use module CycleTLS to impersonate browsers' fingerprints.
https://www.npmjs.com/package/cycletls
@Explosion-Scratch่ฏทๅฐ่ฏไฝฟ็จๆจกๅ CycleTLS ๆฅๆจกๆๆต่งๅจ็ๆ็บนใ https://www.npmjs.com/package/cycletls
Yes, you provided a great idea, I have verified it, thank you very much.
How do I spoof a specific browser with this? I've looked through the code of curl_cffi. Where do I get the JA3 tokens? @jackytj
Just visit https://browserleaks.com/tls with the browser u want to impersonate.
Just visit https://browserleaks.com/tls with the browser u want to impersonate.
Are these reusable/do they expire?
Hi guys, working on it now. Good news! Instead of getting 403 I'm getting 400! Different error = progress
I just used the CycleTLS method to simulate Ja3, and I can get the result normally, but I can't get the stream result, and I also working on it.
I found exec use curl can get response
import { spawn, exec } from 'child_process';
const command = `curl 'https://claude.ai/api/append_message' \
-H 'cookie: claude_cookie' \
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 Edg/115.0.1901.203' \
-H 'Content-Type: application/json' \
--data-raw '{"completion":{"prompt":"niaho","timezone":"Asia/Shanghai","model":"claude-2"},"organization_uuid":"d5c9185a-ff0a-47e1-a7d3-fa982296171e","conversation_uuid":"db263529-fce4-4d1e-9b73-5aec5d1ad248","text":"niaho","attachments":[]}'`;
const a = async () => {
const b = new Promise((res, rej)=> {
exec(command, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
console.log(`stdout: ${stdout}`, typeof stdout);
console.log(`stderr: ${stderr}`);
});
})
await b;
}
@unbrain According to your method, I failed to reproduce it successfully. Can you add your operating environment and curl version in detail?
@yhostc make sure you change cookie , i use the cookie from browser post request header
macos 13.4.1
* Connected to 127.0.0.1 (127.0.0.1) port 7890 (#0)
* allocate connect buffer
* Establish HTTP proxy tunnel to claude.ai:443
> CONNECT claude.ai:443 HTTP/1.1
> Host: claude.ai:443
> User-Agent: curl/7.88.1
> Proxy-Connection: Keep-Alive
>
< HTTP/1.1 200 Connection established
<
* CONNECT phase completed
* CONNECT tunnel established, response 200
* ALPN: offers h2,http/1.1
* (304) (OUT), TLS handshake, Client hello (1):
} [314 bytes data]
* CAfile: /etc/ssl/cert.pem
* CApath: none
* (304) (IN), TLS handshake, Server hello (2):
{ [122 bytes data]
* (304) (IN), TLS handshake, Unknown (8):
{ [19 bytes data]
* (304) (IN), TLS handshake, Certificate (11):
{ [2316 bytes data]
* (304) (IN), TLS handshake, CERT verify (15):
{ [79 bytes data]
* (304) (IN), TLS handshake, Finished (20):
{ [36 bytes data]
* (304) (OUT), TLS handshake, Finished (20):
} [36 bytes data]
* SSL connection using TLSv1.3 / AEAD-CHACHA20-POLY1305-SHA256
* ALPN: server accepted h2
* Server certificate:
* subject: C=US; ST=California; L=San Francisco; O=Cloudflare, Inc.; CN=claude.ai
* start date: Jul 8 00:00:00 2023 GMT
* expire date: Jul 7 23:59:59 2024 GMT
* subjectAltName: host "claude.ai" matched cert's "claude.ai"
* issuer: C=US; O=Cloudflare, Inc.; CN=Cloudflare Inc ECC CA-3
* SSL certificate verify ok.
* using HTTP/2
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* h2h3 [:method: POST]
* h2h3 [:path: /api/append_message]
* h2h3 [:scheme: https]
* h2h3 [:authority: claude.ai]
* h2h3 [accept: */*]
* h2h3 [cookie:-0-1-2a03815d.-0.2.1692682368; intercom-session-lupk8zyo=N04rdDkrUTk5S2RVM3RVeExHZXJJbHhwNjFpMllWR3pBZTJGaEVxUE1ONXluZTVYQ3hBcEtvOXdRWERDRklINy0tMEd3a0tzZ3E5YXVXclVrVDc2eG9DQT09--6ae8ef50952e26edbd5e77f81249a93ea53e042c; __cf_bm=UfBMiPympREfaGW4uITwjOl0bAUr1x1EoRemiRjA_9g-1692683329-0-AaoAx4P9UN+UmmkIz1taZAM9wMtjqjwpDnK/7aebV1I6GySONBy/e445+dMEFOKIQvS8J4D0N6aYy97l6ghhX+4=]
* h2h3 [user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 Edg/115.0.1901.203]
* h2h3 [content-type: application/json]
* h2h3 [content-length: 229]
* Using Stream ID: 1 (easy handle 0x13580ba00)
> POST /api/append_message HTTP/2
> Host: claude.ai
> accept: */*
> cookie:+4=
> user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 Edg/115.0.1901.203
> content-type: application/json
> content-length: 229
>
} [229 bytes data]
* We are completely uploaded and fine
100 229 0 0 100 229 0 62 0:00:03 0:00:03 --:--:-- 62< HTTP/2 200
< date: Tue, 22 Aug 2023 08:43:11 GMT
< content-type: text/event-stream
< cache-control: no-cache, no-transform
< content-security-policy: script-src 'strict-dynamic' https: 'nonce-c2431704-b7d0-4a00-8f80-960bacb2871b'; object-src 'none'; base-uri 'none'; upgrade-insecure-requests; block-all-mixed-content
< strict-transport-security: max-age=63072000; includeSubDomains; preload
< vary: RSC, Next-Router-State-Tree, Next-Router-Prefetch, Next-Url
< x-content-type-options: nosniff
< x-frame-options: SAMEORIGIN
< x-xss-protection: 1; mode=block
< via: 1.1 google
< cf-cache-status: DYNAMIC
< set-cookie: __cf_bm=.EY-1692693791-0-+GLlk8Z478hAyyluOuEsuL/4p+jBYBPOn/9lW4mj9PfoIXb6Y=; path=/; expires=Tue, 22-Aug-23 09:13:11 GMT; domain=.claude.ai; HttpOnly; Secure; SameSite=None
< server: cloudflare
< cf-ray: 7fa9d38c6dd3c38f-SEA
<
{ [193 bytes data]
100 3955 0 3726 100 229 738 45 0:00:05 0:00:05 --:--:-- 863
This seems to be a special case, due to newer curl versions or special circumstances caused by local proxies, the fingerprint of the function has not been blacklisted. This solution is not conducive to deploying to a production environment.
I can make a simple request directly in nodejs without a problem, my nodejs version is v18.15.0 for MacOS
const cookie = "xxxxxx"
const headers = new Headers()
headers.append('Referer', 'https://claude.ai/chats')
headers.append('Cookie', cookie)
fetch("https://claude.ai/api/organizations", {method: 'GET', headers: headers})
.then(res => res.json())
.then(console.log)
.catch(console.log)
Guys, any progress?
I just used the CycleTLS method to simulate Ja3, and I can get the result normally, but I can't get the stream result, and I also working on it.
My draft implements both a cycleTLS approach (400 error currently) and a curl approach (403 error currently), feel free to contribute to it over at #54. Hopefully I'll get this worked out soon
I can make a simple request directly in nodejs without a problem, my nodejs version is v18.15.0 for MacOS
const cookie = "xxxxxx" const headers = new Headers() headers.append('Referer', 'https://claude.ai/chats') headers.append('Cookie', cookie) fetch("https://claude.ai/api/organizations", {method: 'GET', headers: headers}) .then(res => res.json()) .then(console.log) .catch(console.log)
Organizations request almost always works, it's sending messages which I'm receiving error messages
Sorry for the delay y'all. I'll work on it a bit tomorrow probably
Guys, if you're open to paying (same price as official API), just use openRouter, it supports Claude 2 via the official API: https://openrouter.ai/docs
so it's guaranteed to always work
Can you give a try using my library? https://github.com/st1vms/unofficial-claude2-api
It was updated to support 2.1 model, it's now using curl_cffi to mimic the browser handshaking.
It's full of feature and it has now reached a stable state. Come check it out! : )
const fetch = require("node-fetch");
const headers = new Headers()
headers.append('Referer', 'https://claude.ai/chats')
headers.append('Cookie', `cookie`)
fetch("https://claude.ai/api/organizations", {method: 'GET', headers: headers})
.then(res => res.json())
.then(console.log)
.catch(console.log)
Tried this and got an error:
{
error: {
message: 'We are unable to serve your request',
type: 'permission_error'
}
}
Is this something?