From e5d8948969d061c88cee69cd66678096dc38cb46 Mon Sep 17 00:00:00 2001 From: cerebrixos <248534569+cerebrixos@users.noreply.github.com> Date: Thu, 4 Jun 2026 13:37:08 -0400 Subject: [PATCH] document OpenAI-compatible base URL configuration --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index f9401f6b..eb8bf583 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,22 @@ This SDK is more focused on working with OpenAI Platform, but also works with ot Use `.relaxed` parsing option on Configuration, or see more details on the topic [here](#support-for-other-providers) +If you need to switch between OpenAI and another OpenAI-compatible endpoint in different environments, you can build the configuration from `OPENAI_BASE_URL`: + +```swift +let baseURL = URL(string: ProcessInfo.processInfo.environment["OPENAI_BASE_URL"] ?? "https://api.openai.com/v1")! + +let configuration = OpenAI.Configuration( + token: ProcessInfo.processInfo.environment["OPENAI_API_KEY"], + host: baseURL.host ?? "api.openai.com", + port: baseURL.port ?? 443, + scheme: baseURL.scheme ?? "https", + basePath: baseURL.path.isEmpty ? "/v1" : baseURL.path, + parsingOptions: .relaxed +) +let openAI = OpenAI(configuration: configuration) +``` + ### Cancelling requests For Swift Concurrency calls, you can simply cancel the calling task, and corresponding underlying `URLSessionDataTask` would get cancelled automatically.