swift-openai-api

2.0.0

OpenAI API client generated using Swift OpenAPI Generator
atacan/swift-openai-api

What's New

v2.0.0 - Major Update with Breaking Changes

2025-10-27T20:35:50Z

Breaking Changes

This major release includes significant updates to the OpenAPI specification and generated client code.

Key Changes

  • Enhanced RealtimeServerEvent schema with detailed mappings and discriminator updates
  • Updated OpenAPI spec descriptions and field definitions
  • Added new scripts for OpenAPI spec processing and validation
  • Fixed nullable type handling and JSON mapping issues

⚠️ Note: This release contains breaking changes. Please review the updated API before upgrading.

Full changelog: 1.0.0...2.0.0

Swift OpenAI API

This is a Swift package for the OpenAI public API. It is generated from the official OpenAI OpenAPI specification using Swift OpenAPI Generator.

Why not generate it yourself?

OpenAI's OpenAPI specification has some issues. Some of them are fixed in the download script with string replacements.

For example, duplicate models are removed, type mismatches are fixed.

Additions

  • The server-sent-events response type for chat completions is now supported
  • The original API document has only 200 status documented as response. We add all the possible error responses with decodable error message payload, so that you can know what the error is.

Usage

  • AuthenticationMiddleware is provided to add API key authentication.
  • Check out Tests

Installation

Add the following to your Package.swift file:

dependencies: [
    .package(url: "https://github.com/atacan/swift-openai-api", from: "0.1.0"),
],
targets: [
    .target(name: "YourTarget", dependencies: [
        .product(name: "OpenAIUrlSessionClient", package: "swift-openai-api"),
        // .product(name: "OpenAIAsyncHTTPClient", package: "swift-openai-api"),
    ]),
]

Notes

WebSocket

First incoming message is a transcription_session.created event.

{
    "type": "transcription_session.created",
    "event_id": "event_BkolR18obdJWg4a3bKuhW",
    "session": {
        "id": "sess_BkolRXnnaIXV7cV3lu7Bv",
        "object": "realtime.transcription_session",
        "expires_at": 1750499725,
        "input_audio_noise_reduction": null,
        "turn_detection": {
            "type": "server_vad",
            "threshold": 0.5,
            "prefix_padding_ms": 300,
            "silence_duration_ms": 200
        },
        "input_audio_format": "pcm16",
        "input_audio_transcription": null,
        "client_secret": null,
        "include": null
    }
}

RealtimeServerEvent.discriminator

Run the following to find the type value for each RealtimeServerEvent and use them to create the mapping in the overlay.json

yq '.components.schemas | .[] | select(key | test("RealtimeServerEvent.*")) | .properties.type.enum[]' openapi.yaml

Description

  • Swift Tools 6.0.0
View More Packages from this Author

Dependencies

Last updated: Mon Nov 17 2025 04:40:57 GMT-1000 (Hawaii-Aleutian Standard Time)