[CLI] Error 401 when using API key non-admin user #2031

Closed
opened 2026-02-05 04:46:58 +03:00 by OVERLORD · 5 comments
Owner

Originally created by @klaasch on GitHub (Jan 20, 2024).

Originally assigned to: @etnoy on GitHub.

The bug

When trying to upload the photos of my wife via CLI, using the API key generated by her non-admin profile, I get error 401 "Request failed". Its seems like an authentication issue. Everything works fine if I use the API key from the admin profile.

# immich login-key http://192.168.1.16:2283/api REDACTED
Executing API key auth flow...
/usr/src/app/node_modules/@immich/cli/dist/src/services/session.service.js:44
            throw new login_error_1.LoginError(`Failed to connect to server ${instanceUrl}: ${error.message}`);
                  ^

LoginError: Failed to connect to server http://192.168.1.16:2283/api: Request failed with status code 401
    at /usr/src/app/node_modules/@immich/cli/dist/src/services/session.service.js:44:19
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async SessionService.keyLogin (/usr/src/app/node_modules/@immich/cli/dist/src/services/session.service.js:43:36)
    at async LoginKey.run (/usr/src/app/node_modules/@immich/cli/dist/src/commands/login/key.js:7:9)
    at async Command.<anonymous> (/usr/src/app/node_modules/@immich/cli/dist/src/index.js:57:5)

Node.js v20.11.0

The OS that Immich Server is running on

Debian 12 (Bookworm) on Raspberry Pi5

Version of Immich Server

2.0.6 (immich -V) / opencontiners.image.version = v1.91.4

Version of Immich Mobile App

1.92.1

Platform with the issue

  • Server
  • Web
  • Mobile

Your docker-compose.yml content

version: "3.8"

#
# WARNING: Make sure to use the docker-compose.yml of the current release:
#
# https://github.com/immich-app/immich/releases/latest/download/docker-compose.yml
#
# The compose file on main may not be compatible with the latest release.
#

name: immich

services:
  immich-server:
    container_name: immich_server
    image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}
    command: [ "start.sh", "immich" ]
    volumes:
      - ${UPLOAD_LOCATION}:/usr/src/app/upload
      - /etc/localtime:/etc/localtime:ro
    env_file:
      - .env
    ports:
      - 2283:3001
    depends_on:
      - redis
      - database
    restart: always

  immich-microservices:
    container_name: immich_microservices
    image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}
    # extends:
    #   file: hwaccel.yml
    #   service: hwaccel
    command: [ "start.sh", "microservices" ]
    volumes:
      - ${UPLOAD_LOCATION}:/usr/src/app/upload
      - /etc/localtime:/etc/localtime:ro
    env_file:
      - .env
    depends_on:
      - redis
      - database
    restart: always

  immich-machine-learning:
    container_name: immich_machine_learning
    image: ghcr.io/immich-app/immich-machine-learning:${IMMICH_VERSION:-release}
    volumes:

Your .env content

# You can find documentation for all the supported env variables at https://immich>

# The location where your uploaded files are stored
UPLOAD_LOCATION=./library

# The Immich version to use. You can pin this to a specific version like "v1.71.0"
IMMICH_VERSION=release

# Connection secret for postgres. You should change it to a random password
DB_PASSWORD=REDACTED

# The values below this line do not need to be changed
###################################################################################
DB_HOSTNAME=immich_postgres
DB_USERNAME=postgres
DB_DATABASE_NAME=immich

REDIS_HOSTNAME=immich_redis

Reproduction steps

1. Login to docker container: docker exec -it immich_server sh
2. Go to Android App and enable API key of non-admin user, copy this key.
3. Go back to your docker container, and paste:
immich login-key http://192.168.1.16:2283/api APIKEY_HERE

Result = request failed with status code 401.

Additional information

  • This command also fails for non-admin users: immich login-key http://127.0.0.1:3001/api APIKEY_HERE
  • The non-admin API key is 1 character longer then the admin API key (42 vs 41 chars)
Originally created by @klaasch on GitHub (Jan 20, 2024). Originally assigned to: @etnoy on GitHub. ### The bug When trying to upload the photos of my wife via CLI, using the API key generated by her non-admin profile, I get error 401 "Request failed". Its seems like an authentication issue. Everything works fine if I use the API key from the admin profile. ``` # immich login-key http://192.168.1.16:2283/api REDACTED Executing API key auth flow... /usr/src/app/node_modules/@immich/cli/dist/src/services/session.service.js:44 throw new login_error_1.LoginError(`Failed to connect to server ${instanceUrl}: ${error.message}`); ^ LoginError: Failed to connect to server http://192.168.1.16:2283/api: Request failed with status code 401 at /usr/src/app/node_modules/@immich/cli/dist/src/services/session.service.js:44:19 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async SessionService.keyLogin (/usr/src/app/node_modules/@immich/cli/dist/src/services/session.service.js:43:36) at async LoginKey.run (/usr/src/app/node_modules/@immich/cli/dist/src/commands/login/key.js:7:9) at async Command.<anonymous> (/usr/src/app/node_modules/@immich/cli/dist/src/index.js:57:5) Node.js v20.11.0 ``` ### The OS that Immich Server is running on Debian 12 (Bookworm) on Raspberry Pi5 ### Version of Immich Server 2.0.6 (immich -V) / opencontiners.image.version = v1.91.4 ### Version of Immich Mobile App 1.92.1 ### Platform with the issue - [X] Server - [ ] Web - [ ] Mobile ### Your docker-compose.yml content ```YAML version: "3.8" # # WARNING: Make sure to use the docker-compose.yml of the current release: # # https://github.com/immich-app/immich/releases/latest/download/docker-compose.yml # # The compose file on main may not be compatible with the latest release. # name: immich services: immich-server: container_name: immich_server image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release} command: [ "start.sh", "immich" ] volumes: - ${UPLOAD_LOCATION}:/usr/src/app/upload - /etc/localtime:/etc/localtime:ro env_file: - .env ports: - 2283:3001 depends_on: - redis - database restart: always immich-microservices: container_name: immich_microservices image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release} # extends: # file: hwaccel.yml # service: hwaccel command: [ "start.sh", "microservices" ] volumes: - ${UPLOAD_LOCATION}:/usr/src/app/upload - /etc/localtime:/etc/localtime:ro env_file: - .env depends_on: - redis - database restart: always immich-machine-learning: container_name: immich_machine_learning image: ghcr.io/immich-app/immich-machine-learning:${IMMICH_VERSION:-release} volumes: ``` ### Your .env content ```Shell # You can find documentation for all the supported env variables at https://immich> # The location where your uploaded files are stored UPLOAD_LOCATION=./library # The Immich version to use. You can pin this to a specific version like "v1.71.0" IMMICH_VERSION=release # Connection secret for postgres. You should change it to a random password DB_PASSWORD=REDACTED # The values below this line do not need to be changed ################################################################################### DB_HOSTNAME=immich_postgres DB_USERNAME=postgres DB_DATABASE_NAME=immich REDIS_HOSTNAME=immich_redis ``` ### Reproduction steps ```bash 1. Login to docker container: docker exec -it immich_server sh 2. Go to Android App and enable API key of non-admin user, copy this key. 3. Go back to your docker container, and paste: immich login-key http://192.168.1.16:2283/api APIKEY_HERE Result = request failed with status code 401. ``` ### Additional information - This command also fails for non-admin users: immich login-key http://127.0.0.1:3001/api APIKEY_HERE - The non-admin API key is 1 character longer then the admin API key (42 vs 41 chars)
OVERLORD added the cli label 2026-02-05 04:46:58 +03:00
Author
Owner

@jrasm91 commented on GitHub (Jan 21, 2024):

Can you enclose the API key in single quotes?

@jrasm91 commented on GitHub (Jan 21, 2024): Can you enclose the API key in single quotes?
Author
Owner

@klaasch commented on GitHub (Jan 21, 2024):

Can you enclose the API key in single quotes?

Thanks for the suggestion. This only works for the admin API key. The non-admin API key generates a 401.

Is there maybe a character too much in the non-Admin API key? I have 42 chars, and only 41 chars in the admin API key. Removing the first or the last character doesn't let me login though.

@klaasch commented on GitHub (Jan 21, 2024): > Can you enclose the API key in single quotes? Thanks for the suggestion. This only works for the admin API key. The non-admin API key generates a 401. Is there maybe a character too much in the non-Admin API key? I have 42 chars, and only 41 chars in the admin API key. Removing the first or the last character doesn't let me login though.
Author
Owner

@klaasch commented on GitHub (Jan 21, 2024):

Just "solved" the problem with the following workaround:
-Created another user, and a new API key --> worked
-Deleted the other user
-Deleted API key of my wife her account
-Recreated API of my wife her account --> success!

I don't think there is anything wrong with the Immich code, maybe I mistyped something somewhere or messed up stuff with a wrong command. Thanks for diving into this problem though and the suggestions!

@klaasch commented on GitHub (Jan 21, 2024): Just "solved" the problem with the following workaround: -Created another user, and a new API key --> worked -Deleted the other user -Deleted API key of my wife her account -Recreated API of my wife her account --> success! I don't think there is anything wrong with the Immich code, maybe I mistyped something somewhere or messed up stuff with a wrong command. Thanks for diving into this problem though and the suggestions!
Author
Owner

@jrasm91 commented on GitHub (Jan 22, 2024):

Api keys can contain characters that mean other things in bash, so you can try escaping them or deleting and regenerating the API key again.

@jrasm91 commented on GitHub (Jan 22, 2024): Api keys can contain characters that mean other things in bash, so you can try escaping them or deleting and regenerating the API key again.
Author
Owner

@mariozhivago commented on GitHub (Aug 20, 2024):

i tried everything and wont work . any idea?

@mariozhivago commented on GitHub (Aug 20, 2024): i tried everything and wont work . any idea?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: immich-app/immich#2031