claude-unofficial-api icon indicating copy to clipboard operation
claude-unofficial-api copied to clipboard

Everything broke

Open NeoPrint3D opened this issue 2 years ago • 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

NeoPrint3D avatar Aug 15 '23 21:08 NeoPrint3D

same to me ~~ Generating

image

joostshao avatar Aug 16 '23 05:08 joostshao

same issue for me +1

Stainless5792 avatar Aug 16 '23 07:08 Stainless5792

Please settle it as soon as possible

Sylar-W avatar Aug 16 '23 07:08 Sylar-W

image

Jarvan-via avatar Aug 16 '23 09:08 Jarvan-via

https://github.com/Explosion-Scratch/claude-unofficial-api/issues/49

joostshao avatar Aug 16 '23 09:08 joostshao

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.

Explosion-Scratch avatar Aug 16 '23 12:08 Explosion-Scratch

Happy to transfer this to another maintainer as well if that would interest anyone

Explosion-Scratch avatar Aug 16 '23 12:08 Explosion-Scratch

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.

M-a-s-a-t-o avatar Aug 17 '23 10:08 M-a-s-a-t-o

image image

still stuck in "Generating...."

joostshao avatar Aug 17 '23 13:08 joostshao

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

boxirada avatar Aug 17 '23 22:08 boxirada

@Explosion-Scratch Plz try to use module CycleTLS to impersonate browsers' fingerprints. https://www.npmjs.com/package/cycletls

M-a-s-a-t-o avatar Aug 18 '23 03:08 M-a-s-a-t-o

@Explosion-Scratch请尝试使用模块 CycleTLS 来模拟浏览器的指纹。 https://www.npmjs.com/package/cycletls

Yes, you provided a great idea, I have verified it, thank you very much.

isnolan avatar Aug 21 '23 02:08 isnolan

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

Explosion-Scratch avatar Aug 21 '23 12:08 Explosion-Scratch

Just visit https://browserleaks.com/tls with the browser u want to impersonate.

M-a-s-a-t-o avatar Aug 21 '23 16:08 M-a-s-a-t-o

Just visit https://browserleaks.com/tls with the browser u want to impersonate.

Are these reusable/do they expire?

Explosion-Scratch avatar Aug 21 '23 20:08 Explosion-Scratch

Hi guys, working on it now. Good news! Instead of getting 403 I'm getting 400! Different error = progress

Explosion-Scratch avatar Aug 21 '23 21:08 Explosion-Scratch

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.

isnolan avatar Aug 22 '23 05:08 isnolan

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 avatar Aug 22 '23 07:08 unbrain

@unbrain According to your method, I failed to reproduce it successfully. Can you add your operating environment and curl version in detail?

Screenshot 2023-08-22 at 16 18 17

isnolan avatar Aug 22 '23 08:08 isnolan

@yhostc make sure you change cookie , i use the cookie from browser post request header

image image image

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

unbrain avatar Aug 22 '23 08:08 unbrain

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.

isnolan avatar Aug 22 '23 09:08 isnolan

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)

nendonerd avatar Aug 22 '23 10:08 nendonerd

Guys, any progress?

M-a-s-a-t-o avatar Aug 24 '23 11:08 M-a-s-a-t-o

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

Explosion-Scratch avatar Aug 24 '23 23:08 Explosion-Scratch

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

Explosion-Scratch avatar Aug 24 '23 23:08 Explosion-Scratch

Sorry for the delay y'all. I'll work on it a bit tomorrow probably

Explosion-Scratch avatar Aug 28 '23 13:08 Explosion-Scratch

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

sobrienti avatar Aug 29 '23 18:08 sobrienti

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! : )

st1vms avatar Dec 05 '23 14:12 st1vms

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?

Legends-of-NGDB avatar May 04 '24 16:05 Legends-of-NGDB