Immich_auth.ClientAuthenticated Immich client with session persistence and profile support.
This module provides a high-level client that wraps the generated Immich module with authentication support. Sessions are stored in profile-specific directories.
API Key (recommended for CLI):
let t = Client.login_api_key ~sw ~env
~server_url:"https://immich.example.com"
~api_key:"your-api-key"
~key_name:(Some "cli")
() in
let albums = Immich.Album.get_all_albums (Client.client t) ()Password (for interactive use):
let t = Client.login_password ~sw ~env
~server_url:"https://immich.example.com"
~email:"user@example.com"
~password:"secret"
() in
... match Session.load fs () with
| Some session ->
let t = Client.resume ~sw ~env ~session () in
...
| None ->
Fmt.epr "Not logged in@."val login_api_key :
sw:Eio.Switch.t ->
env:
< clock : _ Eio.Time.clock
; net : _ Eio.Net.t
; fs : Eio.Fs.dir_ty Eio.Path.t.. > ->
?requests_config:Requests.Cmd.config ->
?profile:string ->
server_url:string ->
api_key:string ->
?key_name:string ->
unit ->
tlogin_api_key ~sw ~env ?requests_config ?profile ~server_url ~api_key ?key_name () authenticates using an API key. The API key is sent in the x-api-key header for all requests.
The server_url can be either the full API URL (e.g., https://example.com/api) or the base server URL (e.g., https://example.com). If the base URL is provided, the client automatically discovers the API endpoint via .well-known/immich.
val login_password :
sw:Eio.Switch.t ->
env:
< clock : _ Eio.Time.clock
; net : _ Eio.Net.t
; fs : Eio.Fs.dir_ty Eio.Path.t.. > ->
?requests_config:Requests.Cmd.config ->
?profile:string ->
server_url:string ->
email:string ->
password:string ->
unit ->
tlogin_password ~sw ~env ?requests_config ?profile ~server_url ~email ~password () authenticates using email and password. Returns a JWT access token.
val resume :
sw:Eio.Switch.t ->
env:
< clock : _ Eio.Time.clock
; net : _ Eio.Net.t
; fs : Eio.Fs.dir_ty Eio.Path.t.. > ->
?requests_config:Requests.Cmd.config ->
?profile:string ->
session:Session.t ->
unit ->
tresume ~sw ~env ?requests_config ?profile ~session () resumes from a saved session.
val logout : t -> unitlogout t clears the session from disk.
val profile : t -> string optionprofile t returns the current profile name, if set.
val fs : t -> Eio.Fs.dir_ty Eio.Path.tfs t returns the filesystem capability.
val is_valid : t -> boolis_valid t returns true if the session is still valid by calling the validate endpoint.
val resolve_api_url : session:Requests.t -> string -> stringresolve_api_url ~session base_url resolves the actual API URL.
If base_url already ends with /api, returns it unchanged. Otherwise, tries to fetch <base_url>/.well-known/immich to discover the API endpoint. Falls back to <base_url>/api if discovery fails.
This function is called automatically by login_api_key and login_password, but is exposed for advanced use cases.