[GH-ISSUE #13776] 401 Unauthorized error when using cloud models with Claude Code #55541

Closed
opened 2026-04-29 09:22:40 -05:00 by GiteaMirror · 12 comments
Owner

Originally created by @Semihocakli on GitHub (Jan 19, 2026).
Original GitHub issue: https://github.com/ollama/ollama/issues/13776

Originally assigned to: @ParthSareen on GitHub.

What is the issue?

Describe the bug
Getting 401 unauthorized error when trying to use cloud models with Claude Code.

Steps to reproduce:

  1. Created API key at https://ollama.com/settings/keys
  2. Set environment variables:
   export ANTHROPIC_BASE_URL=https://ollama.com
   export ANTHROPIC_API_KEY=<my-api-key>
  1. Run: claude --model glm-4.7:cloud
  2. Error: 401 unauthorized

Environment:

  • OS: Windows 11 with WSL2 (Ubuntu 24.04)
  • Ollama version: 0.14.2
  • Claude Code version: v2.1.12

Expected behavior:
Should connect to cloud model successfully. for the link (https://docs.ollama.com/integrations/claude-code)

Additional context:
Tried both methods from https://docs.ollama.com/cloud documentation.
API key is valid and visible at ollama.com/settings/keys.

Relevant log output


OS

No response

GPU

No response

CPU

No response

Ollama version

No response

Originally created by @Semihocakli on GitHub (Jan 19, 2026). Original GitHub issue: https://github.com/ollama/ollama/issues/13776 Originally assigned to: @ParthSareen on GitHub. ### What is the issue? **Describe the bug** Getting 401 unauthorized error when trying to use cloud models with Claude Code. **Steps to reproduce:** 1. Created API key at https://ollama.com/settings/keys 2. Set environment variables: ```bash export ANTHROPIC_BASE_URL=https://ollama.com export ANTHROPIC_API_KEY=<my-api-key> ``` 3. Run: `claude --model glm-4.7:cloud` 4. Error: `401 unauthorized` **Environment:** - OS: Windows 11 with WSL2 (Ubuntu 24.04) - Ollama version: 0.14.2 - Claude Code version: v2.1.12 **Expected behavior:** Should connect to cloud model successfully. for the link (https://docs.ollama.com/integrations/claude-code) **Additional context:** Tried both methods from https://docs.ollama.com/cloud documentation. API key is valid and visible at ollama.com/settings/keys. ### Relevant log output ```shell ``` ### OS _No response_ ### GPU _No response_ ### CPU _No response_ ### Ollama version _No response_
GiteaMirror added the bug label 2026-04-29 09:22:40 -05:00
Author
Owner

@ParthSareen commented on GitHub (Jan 20, 2026):

Hi @Semihocakli can you make sure you're signed in by running ollama signin?

<!-- gh-comment-id:3770529390 --> @ParthSareen commented on GitHub (Jan 20, 2026): Hi @Semihocakli can you make sure you're signed in by running `ollama signin`?
Author
Owner

@wh-Cc commented on GitHub (Jan 20, 2026):

I'm encountering the same issue.

<!-- gh-comment-id:3771110399 --> @wh-Cc commented on GitHub (Jan 20, 2026): I'm encountering the same issue.
Author
Owner

@ALNY-AC commented on GitHub (Jan 20, 2026):

Image Image

Me too.

<!-- gh-comment-id:3772643474 --> @ALNY-AC commented on GitHub (Jan 20, 2026): <img width="375" height="42" alt="Image" src="https://github.com/user-attachments/assets/038b72b9-8f2c-44cd-b096-5b68b3b36256" /> <img width="763" height="233" alt="Image" src="https://github.com/user-attachments/assets/c2f69001-7c8b-4c95-8d21-8178d5355df2" /> Me too.
Author
Owner

@wh-Cc commented on GitHub (Jan 20, 2026):

这是来自QQ邮箱的假期自动回复邮件。
 
您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。

<!-- gh-comment-id:3772645754 --> @wh-Cc commented on GitHub (Jan 20, 2026): 这是来自QQ邮箱的假期自动回复邮件。   您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。
Author
Owner

@Semihocakli commented on GitHub (Jan 20, 2026):

SOLVED

Problem Description

Ollama installed on Windows was not accessible from WSL, even when using the Windows IP address. Despite various WSL configurations, the connection failed because Ollama requires specific setup to work across the WSL/Windows boundary.

Solution

Installing Ollama directly in WSL resolved the issue. This allows Claude Code to successfully communicate with Ollama's cloud models.


Steps to Reproduce the Solution (Ubuntu/WSL Terminal)

1. Update system and install dependencies

sudo apt update && sudo apt install -y zstd

2. Install Ollama in WSL

curl -fsSL https://ollama.com/install.sh | sh

3. Sign in to Ollama

ollama signin

This will open a browser window for authentication.

4. Start Ollama service

ollama serve

Keep this terminal window open, or run in background with ollama serve &

5. Pull a cloud model

ollama pull glm-4.7:cloud

Or any other cloud model from https://ollama.com/search?c=cloud

6. Verify installation

# Check model list
ollama list

# Test API endpoint
curl http://localhost:11434/api/tags

7. Set environment variables

export ANTHROPIC_BASE_URL=http://localhost:11434
export ANTHROPIC_API_KEY=ollama

8. Launch Claude Code with cloud model

claude --model glm-4.7:cloud

Why This Works

Running Ollama natively in WSL eliminates the cross-boundary communication issues between WSL and Windows. The localhost:11434 endpoint is now accessible directly within the same WSL environment where Claude Code is running.

Alternative Cloud Models

  • glm-4.7:cloud - High-performance cloud model
  • minimax-m2.1:cloud - Fast cloud model
  • qwen3-coder:480b - Large coding model

For the full list of cloud models, visit: https://ollama.com/search?c=cloud

<!-- gh-comment-id:3772696080 --> @Semihocakli commented on GitHub (Jan 20, 2026): ## ✅ SOLVED ### Problem Description Ollama installed on Windows was not accessible from WSL, even when using the Windows IP address. Despite various WSL configurations, the connection failed because Ollama requires specific setup to work across the WSL/Windows boundary. ### Solution Installing Ollama directly in WSL resolved the issue. This allows Claude Code to successfully communicate with Ollama's cloud models. --- ### Steps to Reproduce the Solution (Ubuntu/WSL Terminal) #### 1. Update system and install dependencies ```bash sudo apt update && sudo apt install -y zstd ``` #### 2. Install Ollama in WSL ```bash curl -fsSL https://ollama.com/install.sh | sh ``` #### 3. Sign in to Ollama ```bash ollama signin ``` This will open a browser window for authentication. #### 4. Start Ollama service ```bash ollama serve ``` Keep this terminal window open, or run in background with `ollama serve &` #### 5. Pull a cloud model ```bash ollama pull glm-4.7:cloud ``` Or any other cloud model from https://ollama.com/search?c=cloud #### 6. Verify installation ```bash # Check model list ollama list # Test API endpoint curl http://localhost:11434/api/tags ``` #### 7. Set environment variables ```bash export ANTHROPIC_BASE_URL=http://localhost:11434 export ANTHROPIC_API_KEY=ollama ``` #### 8. Launch Claude Code with cloud model ```bash claude --model glm-4.7:cloud ``` --- ### Why This Works Running Ollama natively in WSL eliminates the cross-boundary communication issues between WSL and Windows. The `localhost:11434` endpoint is now accessible directly within the same WSL environment where Claude Code is running. ### Alternative Cloud Models - `glm-4.7:cloud` - High-performance cloud model - `minimax-m2.1:cloud` - Fast cloud model - `qwen3-coder:480b` - Large coding model For the full list of cloud models, visit: https://ollama.com/search?c=cloud
Author
Owner

@eastrd commented on GitHub (Jan 21, 2026):

export ANTHROPIC_BASE_URL=http://localhost:11434 this would work but then you lose the ability to do web searches via Ollama Cloud, web search would always return 0 results

<!-- gh-comment-id:3777895229 --> @eastrd commented on GitHub (Jan 21, 2026): `export ANTHROPIC_BASE_URL=http://localhost:11434` this would work but then you lose the ability to do web searches via Ollama Cloud, web search would always return 0 results
Author
Owner

@hejianboo commented on GitHub (Jan 23, 2026):

I came across the same issue when I wanted to connect Ollama's cloud models

<!-- gh-comment-id:3791283740 --> @hejianboo commented on GitHub (Jan 23, 2026): I came across the same issue when I wanted to connect Ollama's cloud models
Author
Owner

@better319 commented on GitHub (Jan 24, 2026):

cannot use the glm cloud direct via api?
justlike https://ollama.com instead of localhost:11434

<!-- gh-comment-id:3795692660 --> @better319 commented on GitHub (Jan 24, 2026): cannot use the glm cloud direct via api? justlike https://ollama.com instead of localhost:11434
Author
Owner

@ParthSareen commented on GitHub (Jan 27, 2026):

@eastrd thanks for pointing that out. Let me see if I can add a fix for that.

<!-- gh-comment-id:3804219178 --> @ParthSareen commented on GitHub (Jan 27, 2026): @eastrd thanks for pointing that out. Let me see if I can add a fix for that.
Author
Owner

@eastrd commented on GitHub (Jan 27, 2026):

@eastrd thanks for pointing that out. Let me see if I can add a fix for that.

No worries and thank you for looking into this.

My current workaround is to wrap Ollama Cloud web search into a tool and expose that to Claude Code running Ollama Cloud, I know it is not ideal but it is working

<!-- gh-comment-id:3804230389 --> @eastrd commented on GitHub (Jan 27, 2026): > [@eastrd](https://github.com/eastrd) thanks for pointing that out. Let me see if I can add a fix for that. No worries and thank you for looking into this. My current workaround is to wrap Ollama Cloud web search into a tool and expose that to Claude Code running Ollama Cloud, I know it is not ideal but it is working
Author
Owner

@ParthSareen commented on GitHub (Mar 9, 2026):

IIUC this all should be addressed with ollama launch let me know if there anything else!

<!-- gh-comment-id:4026644339 --> @ParthSareen commented on GitHub (Mar 9, 2026): IIUC this all should be addressed with `ollama launch` let me know if there anything else!
Author
Owner

@wh-Cc commented on GitHub (Mar 9, 2026):

这是来自QQ邮箱的假期自动回复邮件。
 
您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。

<!-- gh-comment-id:4026648155 --> @wh-Cc commented on GitHub (Mar 9, 2026): 这是来自QQ邮箱的假期自动回复邮件。   您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#55541