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.

View original on GitHub ↗

38 Comments

AlejandroEsquivel · 1 year ago

Bump

theodormarcu · 1 year ago

+1 Think an API key login option this would be an interesting use case for CI

bcherny collaborator · 1 year ago

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.

crowdwave · 1 year ago
> When you log in, we'll generate an API key for you under the hood

Exactly what I don't want. I have an API key and account to Claude - I want to use that one.

Stewart86 · 1 year ago

+1, can we reopen this?

wazzan-kahunas · 1 year ago

+1 I also have a key different than my console.anthropic.com account, how can I use it? @bcherny

zkreutzjanz · 1 year ago
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.

@bcherny look at how https://github.com/antinomyhq/forge handles this. Right now now way to mimic the preset auth state.

c4ffein · 1 year ago

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.json file.

Also turns out that you can drop a very incomplete .claude.json file 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 the primaryApiKey.

Please keep in mind that it can break anytime soon, but for now it will let me secure my setups 👀

{
  "changelogLastFetched": 1000000000000,
  "primaryApiKey": "sk-ant-apiXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "isQualifiedForDataSharing": false,
  "hasCompletedOnboarding": true,
  "lastOnboardingVersion": "0.2.107",
  "maxSubscriptionNoticeCount": 0,
  "hasAvailableMaxSubscription": false,
  "lastReleaseNotesSeen": "0.2.107"
}
johns10 · 1 year ago

Also want. My organization only provided me with an API key and no console access

bluepuma77 · 1 year ago

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?

nandatheguntupalli · 1 year ago

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?

Jiripoz · 1 year ago

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:

export ANTHROPIC_API_KEY="your-org-api-key"
claude config add allowedTools Edit Bash
claude -p "your prompt here"

hope this helps 🤙

nandatheguntupalli · 1 year ago

Does this work with the claude code. It works with prints but still needs the console access for Claude Code.

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: `` export ANTHROPIC_API_KEY="your-org-api-key" claude config add allowedTools Edit Bash claude -p "your prompt here" `` hope this helps 🤙

@Jiripoz

bcherny collaborator · 1 year ago

Yep, you can set the ANTHROPIC_API_KEY (see docs).

bluepuma77 · 1 year ago

@bcherny claude CLI (v1.0.3) does not seem to work with ANTHROPIC_API_KEY (doc).

mkdir new-repo
cd new-repo
export ANTHROPIC_API_KEY='sk-ant-api03-...'
claude

will always start the setup dialog:

Claude Code can now be used with your Max subscription from the Claude app or billed based on API usage through your Console account.

Pricing may evolve as we move towards general availability.

Select login method:

 ❯ 1. Anthropic Console (API usage billing)
   2. Claude app (requires Max subscription)

then will always go into OAuth mode:

Browser didn't open? Use the url below to sign in:

https://console.anthropic.com/oauth/authorize?code=true&client_id=234&response_type=code&redirect_uri=https%3A%2F%2Fconsole.anthropic.com%2Foauth%2Fcode%2Fcallback&scope=org%3Acreate_api_key+user%3Aprofile+user%3Ainference&code_challenge=abc&code_challenge_method=S256&state=xyz

Paste code here if prompted > 

But the regular API key is not accepted there:

OAuth error: Invalid code. Please make sure the full code was copied

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.

davenforce · 1 year ago

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:

  1. GitHub Actions Implementation
  • The claude-code-action explicitly accepts an anthropic_api_key input
  • Sets the ANTHROPIC_API_KEY environment variable
  • Successfully runs Claude Code in headless mode with API keys
  1. Environment Variable Support
  • ANTHROPIC_API_KEY is the standard environment variable
  • CLAUDE_CONFIG_DIR can be used to specify custom config directories
  1. Configuration Directory Structure
  • The devcontainer mounts a config volume to /home/node/.claude
  • This suggests Claude Code reads configuration from standard directories

🎯 How to Use Your API Key

Method 1: Environment Variable (Recommended)

export ANTHROPIC_API_KEY="your-api-key-here"
claude

Method 2: Configuration File

The .claude.json and .claude/settings.json files I created earlier should work perfectly:

Method 3: Custom Config Directory

export CLAUDE_CONFIG_DIR="/path/to/your/config"
export ANTHROPIC_API_KEY="your-api-key-here"
claude

However setting the environment variable doesn't seem to work.

cviejo · 1 year ago

@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

shivangraina · 1 year ago

@bcherny Any updates on this?

c4ffein · 1 year ago

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

przbadu · 1 year ago

It is still not working with latest version of claude code:

Steps:

export ANTHROPIC_API_KEY=sk_xxxxx
claude

Rather than it starting a headless, it starts the setup process with:

  1. Asks for setting up the theme (Dark, light, ...)
  2. Ask for:

!Image

  • And there should be a third option to enter an API key, if you can't pick it from ENV var. It shouldn't ask for login at all if the API key is provided in the ENV Var.
  • Don't provide us with API key if your internal tools can't use the API keys?
  • Why is Github actions (Github in general) allowed to use claude code with API key, and why can't we use your API keys to access the claude code?

This is so frustrating.

przbadu · 1 year ago

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

iamvikrammishra · 1 year ago

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????

leksuss · 1 year ago

@iamvikrammishra yes, you can. Just follow instructions @przbadu wrote above. It works for me.

pseudotensor · 1 year ago
Yep, you can set the ANTHROPIC_API_KEY (see docs).

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

sarimarton-ofsz · 1 year ago
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

Simplified and summarized:

Create a ~/.claude/settings.json file with this content:

{
  "apiKeyHelper": "echo <API KEY>"
}
jybp · 1 year ago

@bcherny please re-open the issue

progresivoJS · 12 months ago

Any solutions for subscription users?

eahefnawy · 11 months ago
Create a ~/.claude/settings.json file with this content: {

"apiKeyHelper": "echo {apiKey}"
}

This is the only thing that worked for me 🤷‍♂️

bachittle · 11 months ago

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.

Hedzer · 11 months ago

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?

jybp · 11 months ago

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.

nikhilweee · 11 months ago

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.

  1. Open "Keychain Access"
  2. Make sure you are looking at the "login" keychain in the sidebar
  3. In the main window, double click the entry for "Claude Code"
  4. Click "Show Password". You should see the current API key.
  5. Paste the new API Key
  6. Click "Save Changes"
rgaufman · 11 months ago

When I do:

export ANTHROPIC_BASE_URL=api.anthropic.com

then run claude, it shows:

⎿  API Error: Invalid URL

Any ideas?

bachittle · 11 months ago

@rgaufman you probably need to include the full https path like this:
export ANTHROPIC_BASE_URL=https://api.anthropic.com/

manufaktor · 11 months ago

I use my own API key in private projects, and it seems to work like this:

# .env file
ANTHROPIC_API_KEY=sk-...

In the project:

# .claude/settings.json
{
  "apiKeyHelper": "source .env && echo $ANTHROPIC_API_KEY"
}

Then invoke claude in inside the project root and verify with /status command:

Claude Code v1.0.85
  L Session ID: 69...
...
 Account
  L Auth Token: apiKeyHelper
  L API Key: apiKeyHelper
bcherny collaborator · 10 months ago

ANTHROPIC_API_KEY=<api kley> claude, or set env.ANTHROPIC_API_KEY in your settings.json.

thisismohsinsyed · 10 months ago
ANTHROPIC_API_KEY=<api kley> claude, or set env.ANTHROPIC_API_KEY in 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.

github-actions[bot] · 10 months ago

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.