$ErrorActionPreference = "Stop" Add-Type -AssemblyName System.Security $documents = if ($env:CODEX_DOCUMENTS) { $env:CODEX_DOCUMENTS } else { Join-Path $env:USERPROFILE "Documents" } $configDir = Join-Path $documents "Codex\.shared\image-gen-custom" New-Item -ItemType Directory -Force -Path $configDir | Out-Null $baseUrl = Read-Host "OpenAI-compatible API base URL" if ([string]::IsNullOrWhiteSpace($baseUrl)) { throw "API base URL cannot be empty." } [IO.File]::WriteAllText((Join-Path $configDir "base_url.txt"), $baseUrl.Trim().TrimEnd("/"), [Text.UTF8Encoding]::new($false)) Write-Host "API base URL stored in the local configuration." $apiKey = Read-Host "OpenAI-compatible API key" if ([string]::IsNullOrWhiteSpace($apiKey)) { throw "API key cannot be empty." } $plain = [Text.Encoding]::UTF8.GetBytes($apiKey.Trim()) $protected = [System.Security.Cryptography.ProtectedData]::Protect( $plain, $null, [System.Security.Cryptography.DataProtectionScope]::LocalMachine ) [Convert]::ToBase64String($protected) | Set-Content -LiteralPath (Join-Path $configDir "api_key.dpapi") -Encoding ascii Write-Host "API key stored in a Windows DPAPI-protected local file."