Files

22 lines
535 B
C#

namespace backend.Realtime;
public class OpenAIKeyProvider
{
private readonly string? _key;
public OpenAIKeyProvider(IConfiguration cfg)
{
_key = cfg["OPENAI_API_KEY"] ?? cfg["OpenAI:ApiKey"];
}
public bool HasKey => !string.IsNullOrWhiteSpace(_key);
public string GetRequired()
{
if (string.IsNullOrWhiteSpace(_key))
throw new InvalidOperationException(
"OPENAI_API_KEY is not configured. Set the env var on the Coolify app.");
return _key!;
}
}