Goose API key setup

Goose API Key: Set Your Own Key in config.yaml

Paste the block below into config.yaml, put your own API key in ~/.bashrc, and Goose can use Claude models. Pay as you go.

~/.config/goose/config.yamlyaml
config
GOOSE_PROVIDER: openai
GOOSE_MODEL: claude-haiku-4-5-20251001
OPENAI_HOST: https://api.aicodewith.ai
OPENAI_BASE_PATH: v1/chat/completions

Setup steps

Save this key for later terminals

Once you are signed in, this command includes your own key. Copy it, run it once, and the tool keeps the key in the location we tested.

bash
for rc in "$HOME/.zshrc" "$HOME/.bashrc"; do
  touch "$rc"
  echo 'export OPENAI_API_KEY=sk-***' >> "$rc"
done

Signed-out visitors only see a placeholder. Sign in and we fill in your key. Get a key in the console

Copying only puts the command on the clipboard. You still need to run it in a terminal, or paste the key into the tool settings. How to get an API key

These steps were tested on Linux (bash). macOS and Windows have not been tested yet, so they are not listed.

  1. No Goose yet? Install it (skip if installed)

    Run curl -fsSL https://github.com/aaif-goose/goose/releases/download/stable/download_cli.sh | CONFIGURE=false bash, then goose --version. A version number means it is installed.

    Install Goose: curl -fsSL https://github.com/aaif-goose/goose/releases/download/stable/download_cli.sh | CONFIGURE=false bash (CONFIGURE=false skips the interactive setup). It installs to ~/.local/bin/goose. goose --version prints 1.54.0
  2. Paste the config into config.yaml

    Open ~/.config/goose/config.yaml, paste the block from the top of this page, and save. You no longer need to export these.

    The endpoint in ~/.config/goose/config.yaml
  3. Put your API key in ~/.bashrc

    Run echo 'export OPENAI_API_KEY=sk-***' >> ~/.bashrc, replacing sk-*** with your API key (Get an API key). The last line of ~/.bashrc should be that line.

    Check that the last line of ~/.bashrc is export OPENAI_API_KEY=sk-*** (masked here)
  4. Open a new terminal and test Goose

    Open a new terminal and run goose run --no-session --quiet --max-turns 1 -t "Reply with exactly: OK". OK means Goose is using your API key.

    Verify: close the terminal, open a new one, run goose run --no-session --quiet --max-turns 1 -t "Reply with exactly: OK"; an OK reply means it is set up
  5. No OK? Match your error

    Compare the error in your terminal with Common errors below. Each one lists the cause and the fix.

  6. Switch Goose models: change GOOSE_MODEL

    Replace the model name after GOOSE_MODEL in config.yaml with the new Model ID, spelled exactly. Model IDs are on Models and pricing.

Common errors

No key set: Authentication failed for https://api.aicodewith.ai/v1/chat/completions. Status: 401 Unauthorized. Response: {"error":"请在请求中提供有效的 API Key。"}

What you see

error: Ran into this error: Authentication error: Authentication failed for https://api.aicodewith.ai/v1/chat/completions. Status: 401 Unauthorized. Response: {"error":"请在请求中提供有效的 API Key。"}.
(English: "Please provide a valid API key in the request.")
Cause
The terminal has no OPENAI_API_KEY: it is not in ~/.bashrc, or you added it but did not open a new terminal
How to fix
Put the key in ~/.bashrc as in step 3, then open a new terminal

Go back to step 3: Put your API key in ~/.bashrc →

No key set: the new terminal has no OPENAI_API_KEY. Running goose run --no-session --quiet --max-turns 1 -t "Reply with exactly: OK" prints, twice: error: Ran into this error: Authentication error: Authentication failed for https://api.aicodewith.ai/v1/chat/completions. Status: 401 Unauthorized. Response: {"error":"请在请求中提供有效的 API Key。"}. (English: "Please provide a valid API key in the request.") followed by Please retry if you think this is a transient or recoverable error.

Wrong key: Authentication failed for https://api.aicodewith.ai/v1/chat/completions. Status: 401 Unauthorized. Response: {"error":"请在请求中提供有效的 API Key。"}

What you see

error: Ran into this error: Authentication error: Authentication failed for https://api.aicodewith.ai/v1/chat/completions. Status: 401 Unauthorized. Response: {"error":"请在请求中提供有效的 API Key。"}.
(English: "Please provide a valid API key in the request.")
Cause
OPENAI_API_KEY in ~/.bashrc is wrong; the error is the same as with no key
How to fix
Copy the key from the console again, fix the last line of ~/.bashrc, then open a new terminal

Go back to step 3: Put your API key in ~/.bashrc →

Wrong key: tail -n 1 ~/.bashrc shows export OPENAI_API_KEY=sk-wrong. Running goose run --no-session --quiet --max-turns 1 -t "Reply with exactly: OK" prints, twice: error: Ran into this error: Authentication error: Authentication failed for https://api.aicodewith.ai/v1/chat/completions. Status: 401 Unauthorized. Response: {"error":"请在请求中提供有效的 API Key。"}. (English: "Please provide a valid API key in the request.") — the same as with no key

404 "不支持的请求路径" (unsupported request path)

What you see

404 "不支持的请求路径" (unsupported request path)
Cause
OPENAI_BASE_PATH is wrong (for example nope/chat/completions), so the request goes to https://api.aicodewith.ai/nope/chat/completions
How to fix
Set it back to v1/chat/completions

Go back to step 2: Paste the config into config.yaml →

Common error: a wrong OPENAI_BASE_PATH (here nope/chat/completions) sends the request to https://api.aicodewith.ai/nope/chat/completions and returns 404 (unsupported path). Set it back to v1/chat/completions. Note: this relay still accepted (tested) a HOST that already includes /v1, so that is not a reliable way to detect a bad setting

FAQ

How do I use my own API key in Goose?

In ~/.config/goose/config.yaml, set GOOSE_PROVIDER: openai, OPENAI_HOST: https://api.aicodewith.ai and OPENAI_BASE_PATH: v1/chat/completions, then add export OPENAI_API_KEY=your key to ~/.bashrc.

Should the Goose OPENAI_HOST include /v1?

No. Set OPENAI_HOST to https://api.aicodewith.ai and put /v1 in OPENAI_BASE_PATH.

Goose says 401. What now?

The terminal has no OPENAI_API_KEY, or the key is wrong. See Common errors above for the fix.

Goose can't find the model. What now?

Make sure GOOSE_MODEL matches an AI Code With Model ID exactly.

Sources

Related links