2025-01-04 16:54:48 +01:00
|
|
|
// Written by retoor@molodetz.nl
|
|
|
|
|
2025-03-16 07:36:13 +01:00
|
|
|
// This source code retrieves an API key from environment variables or defaults to a hardcoded key if none are found.
|
2025-01-04 16:54:48 +01:00
|
|
|
|
2025-03-16 07:36:13 +01:00
|
|
|
// Uses the C standard library functions from stdlib.h for environment management and stdio.h for error handling.
|
2025-01-04 16:54:48 +01:00
|
|
|
|
|
|
|
// MIT License
|
|
|
|
|
2025-01-27 18:57:21 +01:00
|
|
|
#ifndef R_AUTH_H
|
|
|
|
#define R_AUTH_H
|
2025-03-03 17:06:05 +01:00
|
|
|
|
2025-01-04 16:54:48 +01:00
|
|
|
#include <stdlib.h>
|
2025-01-26 02:54:45 +01:00
|
|
|
#include <stdio.h>
|
2025-01-04 16:54:48 +01:00
|
|
|
|
2025-03-19 21:45:07 +01:00
|
|
|
enum AUTH_TYPE {
|
|
|
|
AUTH_TYPE_API_KEY,
|
|
|
|
AUTH_TYPE_FREE
|
|
|
|
};
|
|
|
|
|
|
|
|
int auth_type = AUTH_TYPE_FREE;
|
|
|
|
|
2025-01-27 19:06:59 +01:00
|
|
|
const char *resolve_api_key() {
|
|
|
|
static char *api_key = NULL;
|
2025-03-16 22:46:09 +01:00
|
|
|
api_key = getenv("R_KEY");
|
|
|
|
if (api_key) {
|
|
|
|
return api_key;
|
|
|
|
}
|
|
|
|
api_key = getenv("OPENAI_API_KEY");
|
|
|
|
if (api_key) {
|
2025-03-19 21:45:07 +01:00
|
|
|
auth_type = AUTH_TYPE_API_KEY;
|
2025-03-16 22:46:09 +01:00
|
|
|
return api_key;
|
|
|
|
}
|
2025-01-05 22:59:51 +01:00
|
|
|
api_key = "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";
|
|
|
|
return api_key;
|
2025-01-26 02:54:45 +01:00
|
|
|
}
|
2025-01-27 18:57:21 +01:00
|
|
|
|
2025-03-16 22:46:09 +01:00
|
|
|
#endif
|
|
|
|
|