8 ms·
Claude's API now supports CORS requests, enabling client-side applications
- yuz 2y agoMaybe for internal development, but definitely not for a user-facing app. Making less impactful of a change. But still nice
- Kiro 2y agoI'm thinking it enables apps where users can bring their own keys without exposing it to my server.
- Yodel0914 2y agoThat's what I've done for my chatgpt UI - I store the API key and any other user config in local storage.
- OccamsMirror 2y agoThat's the only good use of this but I bet people will end up leaking their keys being stupid with it.
- TeMPOraL 2y agoThat's on them though. It's nice to have an option where the third party app just provides its value-add, instead of insisting on being the first party.
- panarky 2y agoThe "dangerous" part of "anthropic-dangerous-direct-browser-access" is because you should never expose API keys in client code.
- unglaublich 2y agoUnless it's the client's keys. Or keys obtained on the client's behalf.
- ozfive 2y agoEven using the client's keys it would be a good idea to give a disclaimer that their key may be stored (If that is the case) and can be accessible through nefarious means. People are very susceptible to phishing attempts etc. and this sort of business model (where you have the client supply the key and store it through the browser is a slippery slope.
- skybrian 2y agoYes, it’s like storing passwords.
- TeMPOraL 2y agoYes. It's as bad as using password managers. Wait.
- skybrian 2y agoFrom an application developer's perspective, the nice thing about using a passkey with a browser cookie is that you don't have to store anything sensitive. You're only guarding access to your own app with meaningless numbers. If your app doesn't store other sensitive data, the blast radius is small. There are still denial of service attacks to worry about where an attacker can use network or compute to run up your bill. What are we guarding when building an app that uses a cloud API that costs money? Access to more compute resources. Probably a lot more than the app itself ever uses. It raises the stakes a bit. Still, in monetary terms, you're operating a vending machine that the user puts money into. Maybe there could be some kind of protocol and workflow to securely buy a dollar of compute time from an AI vendor? If they send some of the money to the app developer's account, it's starting to sound like an app store or micropayments system.
- jdenning 2y ago> I must strongly advise against making direct API calls from a browser, as it exposes your API key and violates best practices for API security. Hilarious that even the LLM warned against this
- creesch 2y agoBit of an odd warning though, considering how half the internet works. I suppose the warning is missing some context. It is a bad idea to give your API key directly to web services you don't know or trust. For those situations, OAuth with fine-grained scopes would be more suitable. If it is just your own web app, and you have an input for a key, I don't really see the issue.
- jillesvangurp 2y agoDepends how you do this. If you allow users to configure their own key, they basically end up using https to communicate the API key directly to the party that issued it. Not much of a risk of leakage there and very common with e.g. browser and editor extensions written in javascript. In a browser, you need the server to be setting CORS headers for this to work. Provisioning some key to your users so they can then pass it on via a client side API call would indeed be more risky. Don't do that. But if it's their own key it's all fine.
- axegon_ 2y agoI see three problems with this: 1. From a product perspective, this is like going to a restaurant to get dinner but having to bring your own kitchen utensils, food and cooking your dinner yourself. 2. Anything running in a browser is inherently insecure - what's the guarantee that the site where you're pasting your key doesn't have some incredibly stupid security flaw and your key gets leaked? 3. Even if there are no vulnerabilities, you're still pasting your code in a random form somewhere on the web. All it takes is an ajax call or a websocket and someone, somewhere has your key.
- simonw 2y agoThis is true: you do have to trust the site author that you are pasting your key into not to steal it. For my https://tools.simonwillison.net/haiku https://tools.simonwillison.net/haiku thing I deliberately kept the code as simple as possible: if you know basic JavaScript you can view source and confirm that your key is not being stolen. The code is also open source, so you can run a copy on your own hosting if you want to. If you don’t trust that then I guess you don’t get to use my tool to write haikus about your dog! As for usability: obviously if you want your thing to be used by people who don’t know how to pay for their own API key you should use a different solution. I mainly want to ship cool demos that are trivial to host and that other people can try out without bankrupting me, so I’m really excited about this.
- afiodorov 2y agoI love making web apps where users bring their own keys. This approach combines the best of both worlds: the convenience of distributing executable files and the benefits of open source. So far, I have developed two web apps: 1. A live transcription and translation app that uses microphone input. This is useful for watching proprietary content and facilitating communication. 2. An app that translates SRT subtitles into various languages. I opt for the "bring your own keys" model for two main reasons: 1. Low maintenance: As a professional software developer, I already maintain a lot of software, and the last thing I want is to maintain my side projects. My goal is to write and distribute these apps so they continue working without requiring constant attention from me. 2. Low cost: This model allows me to distribute the apps without ads. By having users provide their own keys, I can keep operational costs down and avoid the need for monetization through advertising. This approach enables me to create and share useful tools while keeping both my maintenance burden and user costs to a minimum.
- KeplerBoy 2y agoCould ads even support such AI heavy use cases? I'm kind of out of touch with current AI API pricing and ad revenues, so i'm curious how the economics work out.
- deleted 2y ago[deleted]
- InsideOutSanta 2y agoYes, we're now at an inflection point where this is starting to become possible. gpt-4o mini costs $0.15 per 1 million input tokens, and $0.60 per 1 million output. This is cheap enough that it can, at least in some cases, be funded by ad impressions. Of course, the implications here are mixed. If you want to build an ad-supported tool that actually helps people, that's great. But it also means it now makes clear financial sense to fill the web with AI-generated garbage with the assumption that that ad impressions will pay for it.
- hhh 2y ago
- ellellem 2y ago[flagged]
- kreetx 2y agoHow do you MITM TLS?
- simonw 2y agoRight - MITM isn’t a threat here.
- ellellem 2y ago[flagged]
- simonw 2y agoDon’t try to support your arguments by pasting paragraphs of text from ChatGPT. That said, there is a little nugget of useful information in there: “To do this, they install a corporate root certificate on all employee devices.” This is true: if you are using a device which has had a root certificate installed on it you are vulnerable to MITM attacks. I would argue that your employer stealing your Anthropic API key is a pretty low risk compared to everything else that is wrong with that scenario! Your original message above also mentioned coffee shop WiFi: that’s not a threat here. Your coffee shop has not installed a root certificate in your device.
- saagarjha 2y agoWeb security noob here. Why does CORS even exist? The fact that a website can’t make a request to another website unless that domain likes it is kind of insane to me. Everyone in the comments here is going on about how maybe the user’s API key gets leaked by a malicious application or whatever but, like, when I write software that isn’t in the browser I can just send a request to anyone without restrictions and as far as I can tell the world has not ended. Why is the browser any different?
- barrkel 2y agoCORS - or specifically, not permitting cross-origin requests by default - is for preventing CSRF, cross-site request forgery. In particular if the user's credentials (cookies) are passed along with a request to a third party site, then the first party site can act as the user with the user's authority. In other words, evil.com could e.g. send emails on your behalf by making direct requests to your email provider's web interface.
- saagarjha 2y agoOk but like why would you pass cookies along
- easton 2y agoBecause in the 90s/early 2000s someone thought it was a good idea to send cookies for the given site along with all requests (probably a good move, since it would stink to have to tell the browser somehow to explicitly send a cookie for every request, even ones initiated outside of JS). You could say that sites instead must prescribe a "send-cookies-when-requests-are-from-this-site" header, but that's kind of the same thing as CORS.
- joquarky 2y agoWe used to rewrite the session ID into all link href and form action URLs for browsers that didn't enable/support cookies. If any link or form did not contain the SID, the app broke. It was tedious.
- londons_explore 2y ago> if you embed your API key in your client code, anyone with access to that site can steal your API key and use it to make requests on your behalf. Great. Anyone know a search engine to find these 'free usage' keys?
- notpushkin 2y agoI think https://publicwww.com/ https://publicwww.com/ could do the trick?
- _pdp_ 2y agoI don't see this being a problem in situations where a customer / user can bring their own keys. The actions happens on the client-side and as long as the device or the website are not compromised it is all good. However, this is definitely increasing the attack surface where a developer may decide for whatever reason to use production keys client-side without proxying the requests as they would normally do. I can see this being done out of convenience and performance reasons not taking into account security considerations.
- vdfs 2y agoAlso, this was always possible using a simple proxy that directly send requests to their API
- riquito 2y ago> as long as the device or the website are not compromised it is all good But that is THE problem. You are making yourself a huge target. The more users you have the most likely someone will attempt to hack you to use all those keys. The "client side" point is moot because the code that uses those keys comes from the server, once that's compromised all hell is loose.
- ikekkdcjkfke 2y agoNotnpossible to generate a limitee key in 2024?
- me551ah 2y agoFor the use case of user bringing their own keys, oAuth is a much better solution. Some developer is going to hardcode their actual keys on the frontend and find out the hard way. OAuth is a more dumb-proof solution
- judevector 2y agoGreat to see CORS support added! This will make integrating Claude's API into client-side apps much smoother.
- wonderfuly 2y agoI'm really glad to see this. Last week, when I upgraded the Anthropic TypeScript SDK from 0.23.0 to 0.26.0, my browser extension (chathub.gg) broke because they completely banned the use of this SDK in browsers!
- ramonverse 2y agoIt was about time. We definitely wasted a bunch of time making a server side arch for pretzelai.app because claude (unlike openai) didn't have dangerouslyAllowBrowser option. No idea why this took them so long
- samstave 2y ago>>why this took them so long They were trying to have Claude code it up - but every time it got close to working, Claude would lose context and hallucinate and the code would break. Been there too many times with Good Ol' Claude.
- meiraleal 2y agofunny but this proves that claude is now good for code?
- farco12 2y agoI can say from using the chat interface, Claude 3.5 is a top tier model for coding tasks. I used ChatGPT Pro previously, but I really find the experience of using Claude much more enjoyable overall.
- GaggiX 2y agoClaude 3.5 Sonnet is best model at coding.
- samstave 2y agoIve been coding with claude pro an app for the past month and While claude is amazing - it loses context pretty darn quick - and its ultra frustrating - look at my post history where I have written about it in some detail. When I have the energy I should write up a detailed response - but I feel that I have experienced a lot of nefarious with Claude and how it operates.
- e12e 2y ago> It’s fine for internal tools exposed to trusted users, No, not really? > or you can implement a “bring your own API key” pattern where users supply their own key to use with your client-side app. This is a valid use-case, even if it breeds unsafe patterns (just allow random site/code on the internet impersonate you and spend money on your behalf). But it's not really worse than how 3rd party integrations generally do that anyway.
- rvnx 2y agoThey could do a system where you can create one API key with a budget for a site, and that's it, that would be enough, but until they have that budget system, it's not really a good approach
- simonw 2y agoWhy isn’t it OK for internal tools with trusted users? It’s functionally the same as saying “hey coworker, here’s an API key you can use, it’s billed to the company”.
- e12e 2y agoI suppose - my general reaction is that use of such magic api keys are difficult to audit, revoke etc - and there's the constant risk they will leak.
- ripped_britches 2y agoI’m not sure why they don’t support JWTs so we can mint limited user-specific keys instead of exposing the master key Supabase is a great example of how to use claims to give safe client side access
- jasondigitized 2y agoThis would unlock so many interesting use cases and protect the developer from getting a huge bill. Let me basically resell your API and abstract away any complexity to the end user. I'll charge use some % markup on top of what I pay Claude.
- MeetingsBrowser 2y agoHow are people using the Claude API as individuals? Officially, individuals are not allowed to use the API. https://support.anthropic.com/en/articles/8987200-can-i-use-the-anthropic-api-for-individual-use https://support.anthropic.com/en/articles/8987200-can-i-use-...
- buildbot 2y agoEveryone’s their own Sole Proprietorship?
- deleted 2y ago[deleted]
- LeoPanthera 2y agoHuh! That's a surprise. Especially as OpenAI has no problem with it.
- MitchellCash 2y agoI’m going to out myself, but you just do it anyway…
- deleted 2y ago[deleted]
- simonw 2y agoI asked someone at Anthropic about it and it turned out to be a stale page, it’s updated now and says: “Yes, individuals and hobbyists are welcome to use the Anthropic API.”
- zczc 2y agoThey have just updated the FAQ: > Can I use the Anthropic API for individual use? > [Updated yesterday] > Yes, individuals and hobbyists are welcome to use the Anthropic API. However, please note that use of the API is subject to our Commercial Terms of Service, regardless of whether you are an individual or representing a company. Previously: > No. Access to the API is subject to our Commercial Terms of Service and is not intended for individual use.
- orenlindsey 2y agoI mean, you could have just made a quick proxy with a little express server to get around this anyways. But I shouldn't be complaining, it's good that they did this. Edit: of course, I just realized that people may not want their api key being sent to your server.
- allanren 2y agoClaude is growing strong with these new features
- hagope 2y agoAnthropic and all the AI vendors need to implement "Login with ___" allowing users to trust sites to use their own AI resources, similar to how Dropbox allows 3rd party access to the User's storage. Most users don't want to bother with generating and loading API keys, nor can they manage it safely.
- pzo 2y agoAgree. I wish OpenRouter did something like that so that we can have only 1 vendor and app can decide themself what AI API want to use. Then user don't need to have digital wallets topped up with money for 3+ different AI vendors. Basically you want to have something similar to crypto wallet that you can easily fill with money and authorize apps.