2025-01-04 15:54:48 +00:00
// Written by retoor@molodetz.nl
2025-01-27 18:06:59 +00:00
// This source code declares a constant character pointer variable that retrieves an API key from environment variables or falls back to a hardcoded key if not found.
2025-01-04 15:54:48 +00:00
2025-01-27 18:06:59 +00:00
// Uses standard library functions from stdlib.h and stdio.h to manage environment variables and output error messages.
2025-01-04 15:54:48 +00:00
// MIT License
2025-01-27 18:06:59 +00:00
2025-01-27 17:57:21 +00:00
# ifndef R_AUTH_H
# define R_AUTH_H
2025-01-04 15:54:48 +00:00
# include <stdlib.h>
2025-01-26 01:54:45 +00:00
# include <stdio.h>
2025-01-04 15:54:48 +00:00
2025-01-27 18:06:59 +00:00
const char * resolve_api_key ( ) {
static char * api_key = NULL ;
# ifndef FREE_VERSION
2025-01-05 21:59:51 +00:00
api_key = getenv ( " R_KEY " ) ;
2025-01-27 18:06:59 +00:00
if ( api_key ) {
2025-01-04 15:54:48 +00:00
return api_key ;
}
api_key = getenv ( " OPENAI_API_KEY " ) ;
2025-01-27 18:06:59 +00:00
if ( api_key ) {
2025-01-04 15:54:48 +00:00
return api_key ;
}
2025-01-04 16:04:14 +00:00
fprintf ( stderr , " \n There is no API key configured in environment. \n " ) ;
2025-01-05 21:59:51 +00:00
exit ( 1 ) ;
2025-01-27 18:06:59 +00:00
# endif
2025-01-05 21:59:51 +00:00
api_key = " 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 " ;
return api_key ;
2025-01-26 01:54:45 +00:00
}
2025-01-27 17:57:21 +00:00
2025-01-27 18:06:59 +00:00
# endif