How can I use my API key without signing in?
Resolved 💬 38 comments Opened Mar 11, 2025 by crowdwave Closed Aug 22, 2025
💡 Likely answer: A maintainer (bcherny, collaborator)
responded on this thread — see the highlighted reply below.
Or how can I use a separate user id/password to API key?
I have an API key and I have a user account but Claude Code seems to require them to be connected in some way.
I want to configure them independently.
38 Comments
Bump
+1 Think an API key login option this would be an interesting use case for CI
Hey! When you log in, we'll generate an API key for you under the hood. It's still using API keys and will be billed to your Console account like other API requests.
Exactly what I don't want. I have an API key and account to Claude - I want to use that one.
+1, can we reopen this?
+1 I also have a key different than my console.anthropic.com account, how can I use it? @bcherny
@bcherny look at how https://github.com/antinomyhq/forge handles this. Right now now way to mimic the preset auth state.
Hello, I wanted this feature too, as I want to run Claude Code (thanks for this btw, it is awesome) in virtual machines for which I don’t want full compromise of my Anthropic Console account to be possible (for example, a VM used for a coding dojo, accessed by multiple people).
The API key is the best solution for this, I don’t care about leaking a temporary rate-limited api key that I can delete just after the session.
Turns out that you can complete the setup with a burner account and replace the api key in the
.claude.jsonfile.Also turns out that you can drop a very incomplete
.claude.jsonfile in your home directory that will bypass the setup, and as this tool is well made, the missing pieces will all get filled, you just need to replace theprimaryApiKey.Please keep in mind that it can break anytime soon, but for now it will let me secure my setups 👀
Also want. My organization only provided me with an API key and no console access
Hi @bcherny, why did you close this issue? I don't think it's solved, similar to the many comments.
We would like to use the Anthropic console API key directly with Claude Code. We do not want to use the OAuth Login functionality, as the account owner could be another person in the organization. Why have API keys when we can't use them?
Exactly I have an API key from my org but I do not have console access. Is there anyway i can use this API key without having to login to my org's console?
I'm in the same situation - only have an API key from my org without console access.
You can use claude code directly with just your API key:
hope this helps 🤙
Does this work with the claude code. It works with prints but still needs the console access for Claude Code.
@Jiripoz
Yep, you can set the ANTHROPIC_API_KEY (see docs).
@bcherny
claudeCLI (v1.0.3) does not seem to work with ANTHROPIC_API_KEY (doc).will always start the setup dialog:
then will always go into OAuth mode:
But the regular API key is not accepted there:
Note that the API key was created in the "Default" workspace, as creating an API key in "Claude Code " workspace is not permitted in the Anthropic console.
I've tried all of these methods, setting the environment variable and setting it in the .claude.json.
I repopacked claude-code and asked claude, and it said:
Looking at the Claude Code repository, I can see several important details about API key usage:
Based on my analysis of the Claude Code repository, yes, you can definitely use your own API key instead of going through the OAuth process. Here's what I found:
🔑 API Key Usage is Fully Supported
Evidence from the Repository:
claude-code-actionexplicitly accepts ananthropic_api_keyinputANTHROPIC_API_KEYenvironment variableANTHROPIC_API_KEYis the standard environment variableCLAUDE_CONFIG_DIRcan be used to specify custom config directories/home/node/.claude🎯 How to Use Your API Key
Method 1: Environment Variable (Recommended)
Method 2: Configuration File
The
.claude.jsonand.claude/settings.jsonfiles I created earlier should work perfectly:Method 3: Custom Config Directory
However setting the environment variable doesn't seem to work.
@bcherny can you explain the rationale for this choice? there's a lot of very common scenarios that don't work well or at all with this. my guess is that pretty much everyone expects api keys to work universally, at least across anthropic products
@bcherny Any updates on this?
In the long term they may want to force users to register to a specific plan and not handle the pricing as regular api usage
Just do this for now: https://github.com/anthropics/claude-code/issues/441#issuecomment-2874144633
It is still not working with latest version of claude code:
Steps:
Rather than it starting a headless, it starts the setup process with:
!Image
This is so frustrating.
Hey Guys, I figured out this way and it is working for me, wrote steps in this article, please view this. I won't say it is a future proof solution, but at least a temporary fix until Claude solve this problem:
https://przbadu.hashnode.dev/setting-up-claude-code-with-api-key
I have an API key from my org but I do not have console access. Is there anyway i can use this API key without having to login to my org's console????
@iamvikrammishra yes, you can. Just follow instructions @przbadu wrote above. It works for me.
This is insufficient.
Just like with claude code SDK being broken, these are not reasonable things that claude code or SDK require:
1) writing ~/.claude.json that leaks API key and other information to disk
2) requiring signing in via browser
First one is security problem, second one makes non-interactive unusable.
I wasted my time using claude code python SDK and now have to avoid claude code due to these issues.
https://github.com/anthropics/claude-code-sdk-python/issues/70
Simplified and summarized:
Create a
~/.claude/settings.jsonfile with this content:@bcherny please re-open the issue
Any solutions for subscription users?
"apiKeyHelper": "echo {apiKey}"
}
This is the only thing that worked for me 🤷♂️
here's what worked for me:
export ANTHROPIC_API_KEY=sk-your-key
export ANTHROPIC_BASE_URL=https://api.anthropic.com
claude
when logging in, it asks if you want to override the key, no is recommended, but I chose yes.
then it works. there may be auth conflict warnings but can ignore those.
I was experimenting with ANTHROPIC_AUTH_TOKEN as well but that resulted in errors.
I want to use this at my company within our pipelines, I'm having very strong negative feeling towards Anthropic's poor account design. It's very difficult to convince management to switch away from using something like Gemini when they're throwing credits at us, and their process has less friction. Using an API key isn't rocket science, what's going on here?
Right, seem like something very obvious to document.
Just add this section to the readme:
https://github.com/google-gemini/gemini-cli?tab=readme-ov-file#use-a-gemini-api-key
It's indeed kinda red-flaggy to have this issue opened for so long.
On a Mac, it's also possible to edit the API Key from the Keychain.
Follow these steps after logging in to an anthropic account.
When I do:
export ANTHROPIC_BASE_URL=api.anthropic.com
then run claude, it shows:
⎿ API Error: Invalid URL
Any ideas?
@rgaufman you probably need to include the full https path like this:
export ANTHROPIC_BASE_URL=https://api.anthropic.com/
I use my own API key in private projects, and it seems to work like this:
In the project:
Then invoke
claudein inside the project root and verify with/statuscommand:ANTHROPIC_API_KEY=<api kley> claude, or setenv.ANTHROPIC_API_KEYin your settings.json.I tried this and this is also not working, I don't know why but Anthropic is such a big company they should resolve this issue. If we have the API key then why we need Oauth, it does not make sense.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.