Alpaca icon indicating copy to clipboard operation
Alpaca copied to clipboard

"Invalid bearer token" when using Anthropic API

Open woongzeyi opened this issue 8 months ago • 5 comments

Describe the bug

When using Anthropic API with the API key correctly added, below error message appears:

Error code: 401 - {'type': 'error', 'error': {'type': 'authentication_error', 'message': 'Invalid bearer token'}}

My API key has been tested to work in other places.

Expected behavior

The newly added Anthropic instance should work.

Screenshots

Image

Debugging information

$ flatpak run com.jeffser.Alpaca
/app/lib/python3.12/site-packages/pydbus/registration.py:130: DeprecationWarning: Gio.DBusConnection.register_object is deprecated
  ids = [bus.con.register_object(path, interface, wrapper.call_method, None, None) for interface in interfaces]
INFO	[main.py | main] Alpaca version: 6.0.3
MESA-INTEL: warning: ../src/intel/vulkan/anv_formats.c:802: FINISHME: support YUV colorspace with DRM format modifiers
MESA-INTEL: warning: ../src/intel/vulkan/anv_formats.c:834: FINISHME: support more multi-planar formats with DRM modifiers
INFO	[_client.py | _send_single_request] HTTP Request: GET https://api.anthropic.com/v1/models "HTTP/1.1 401 Unauthorized"
ERROR	[instance_manager.py | get_local_models] Error code: 401 - {'type': 'error', 'error': {'type': 'authentication_error', 'message': 'Invalid bearer token'}}

woongzeyi avatar Apr 17 '25 08:04 woongzeyi

Same exact problem here

$ flatpak info com.jeffser.Alpaca

Alpaca - Chat with AI models

          ID: com.jeffser.Alpaca
         Ref: app/com.jeffser.Alpaca/x86_64/stable
        Arch: x86_64
      Branch: stable
     Version: 6.0.3
     License: GPL-3.0-or-later
      Origin: flathub
  Collection: org.flathub.Stable
Installation: system
   Installed: 1.8 GB
     Runtime: org.gnome.Platform/x86_64/48
         Sdk: org.gnome.Sdk/x86_64/48

      Commit: 894f83ac5717079472783d457ab6ccc1afd935e1e9eb6e16c4547864…
      Parent: 883e5b074f29edfaaee11901f902648ba533d26c535f9b4a6a2010cc…
     Subject: Bug Fixes (6.0.3) (49346850)
        Date: 2025-04-14 02:00:51 +0000

DavidHoenisch avatar Apr 20 '25 01:04 DavidHoenisch

I think I found the issue. Calls are to anthropic do not contain the expected headers. Currently, alpaca uses the Authorization: Bearer some-api-key method. However, account to the anthropic docs, the expected header is x-api-key some-api-key.

I am working on a fix, will see if I can get the patch merged.

DavidHoenisch avatar Apr 20 '25 02:04 DavidHoenisch

Alpaca does not use Authorization: Bearer API explicitly, most instances including Anthropic are managed using OpenAI's libraries

Jeffser avatar Apr 21 '25 22:04 Jeffser

I probably will just remove compatibility with Anthropic

Jeffser avatar Apr 21 '25 22:04 Jeffser

As in removing Anthropic as an option completely? That would be a pity... it's quite a big provider.

mags0ft avatar Apr 27 '25 23:04 mags0ft

Hi everyone, I didn't end up removing Anthropic and instead waited to see if they would support OpenAI's sdk directly.

It seems like they have been supporting it for quite a bit so I'm going to close this issue, if there are still problems please tell me and I'll see what I can do.

Jeffser avatar Sep 08 '25 18:09 Jeffser

Still persists.

42lux avatar Sep 15 '25 23:09 42lux

Same here

samu04072013 avatar Oct 03 '25 22:10 samu04072013

same

jaredmontoya avatar Oct 27 '25 14:10 jaredmontoya