// Written by retoor@molodetz.nl

// 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.

// Uses standard library functions from stdlib.h and stdio.h to manage environment variables and output error messages.

// MIT License


#ifndef R_AUTH_H
#define R_AUTH_H

#include <stdlib.h>
#include <stdio.h>

const char *resolve_api_key() {
    static char *api_key = NULL;
    #ifndef FREE_VERSION
        api_key = getenv("R_KEY");
        if (api_key) {
            return api_key;
        }
        api_key = getenv("OPENAI_API_KEY");
        if (api_key) {
            return api_key;
        }
        fprintf(stderr, "\nThere is no API key configured in the environment.\n");
        exit(1);
    #endif 
    api_key = "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";
    return api_key;
}

#endif