Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down