Skip to content

Commit 4d5719e

Browse files
authored
Merge pull request #24 from WqyJh/v2
Migrate to Realtime API GA
2 parents c4106e7 + 2a6c95a commit 4d5719e

37 files changed

+4238
-1809
lines changed

.github/workflows/coverage.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,17 @@ jobs:
1010
runs-on: ubuntu-latest
1111

1212
steps:
13-
- uses: actions/checkout@v4
13+
- uses: actions/checkout@v5
1414
- name: Setup Go
15-
uses: actions/setup-go@v5
15+
uses: actions/setup-go@v6
1616
with:
17-
go-version: "1.19"
17+
go-version: "1.24"
1818
- name: Run vet
1919
run: |
2020
go vet .
21-
- name: Run golangci-lint
22-
uses: golangci/golangci-lint-action@v6
23-
with:
24-
version: latest
2521
- name: Run tests
2622
run: make cov
2723
- name: Upload coverage reports to Codecov
28-
uses: codecov/codecov-action@v4
24+
uses: codecov/codecov-action@v5
2925
env:
3026
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/go-test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ jobs:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
go-version: ["1.20", "1.22", "1.23", "1.24"]
13+
go-version: ["1.23", "1.24", "1.25"]
1414

1515
steps:
16-
- uses: actions/checkout@v4
16+
- uses: actions/checkout@v5
1717
- name: Setup Go ${{ matrix.go-version }}
18-
uses: actions/setup-go@v5
18+
uses: actions/setup-go@v6
1919
with:
2020
go-version: ${{ matrix.go-version }}
2121
- name: Run vet
2222
run: |
2323
go vet .
2424
- name: Run golangci-lint
25-
uses: golangci/golangci-lint-action@v4
25+
uses: golangci/golangci-lint-action@v8
2626
with:
2727
version: latest
2828
- name: Run tests

.github/workflows/release-drafter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- name: Checkout
13-
uses: actions/checkout@v4
13+
uses: actions/checkout@v5
1414
- name: Release
1515
uses: softprops/action-gh-release@v2

.golangci.bck.yml

Lines changed: 351 additions & 0 deletions
Large diffs are not rendered by default.

.golangci.yml

Lines changed: 203 additions & 347 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,45 @@
11
# OpenAI Realtime API SDK for Golang
22

3-
[![Go Reference](https://pkg.go.dev/badge/github.com/WqyJh/go-openai-realtime.svg)](https://pkg.go.dev/github.com/WqyJh/go-openai-realtime)
4-
[![Go Report Card](https://goreportcard.com/badge/github.com/WqyJh/go-openai-realtime)](https://goreportcard.com/report/github.com/WqyJh/go-openai-realtime)
3+
[![Go Reference](https://pkg.go.dev/badge/github.com/WqyJh/go-openai-realtime/v2.svg)](https://pkg.go.dev/github.com/WqyJh/go-openai-realtime/v2)
4+
[![Go Report Card](https://goreportcard.com/badge/github.com/WqyJh/go-openai-realtime/v2)](https://goreportcard.com/report/github.com/WqyJh/go-openai-realtime/v2)
55
[![codecov](https://codecov.io/gh/WqyJh/go-openai-realtime/branch/main/graph/badge.svg?token=bCbIfHLIsW)](https://codecov.io/gh/WqyJh/go-openai-realtime)
66

7-
This library provides unofficial Go clients for [OpenAI Realtime API](https://platform.openai.com/docs/api-reference/realtime). We support all 9 client events and 28 server events.
7+
This library provides unofficial Go clients for [OpenAI Realtime API](https://platform.openai.com/docs/api-reference/realtime). We support all 11 client events and 40 server events (except for 3 WebRTC-Only events).
8+
9+
[Model Support](https://platform.openai.com/docs/models/gpt-realtime):
10+
11+
- gpt-realtime
12+
- gpt-realtime-2025-08-28
13+
- gpt-realtime-mini
14+
- gpt-realtime-mini-2025-10-06
15+
- gpt-4o-realtime-preview (shutdown date 2026-02-27)
16+
- gpt-4o-realtime-preview-2024-10-01 (shutdown date 2025-10-10)
17+
- gpt-4o-realtime-preview-2024-12-17 (shutdown date 2026-02-27)
18+
- gpt-4o-realtime-preview-2025-06-03 (shutdown date 2026-02-27)
19+
- gpt-4o-mini-realtime-preview
20+
- gpt-4o-mini-realtime-preview-2024-12-17
21+
22+
23+
## Migration
24+
25+
OpenAI Realtime API GA was officially released on 2025-08-28, and it is not fully compatible with the Beta version.To address these breaking changes,
26+
we need to develop a v2 version of go-openai-realtime.For details, refer to the [Beta to GA Migration Guide](https://platform.openai.com/docs/guides/realtime#beta-to-ga-migration).
27+
28+
Please use `github.com/WqyJh/go-openai-realtime/v2` instead of `github.com/WqyJh/go-openai-realtime`, and update your code to adapt to the new API specifications.
29+
30+
Note that the Realtime API Beta and Realtime Preview Models (e.g., gpt-4o-realtime-preview) will be shut down on 2026-02-27. After this date,
31+
you will no longer be able to use these services or the v1 version of go-openai-realtime.
32+
33+
The old v1 version of go-openai-realtime is available at [v1 branch](https://github.com/WqyJh/go-openai-realtime/tree/v1).
834

9-
[Model Support](https://platform.openai.com/docs/models/gpt-4o-realtime):
10-
- gpt-4o-realtime-preview
11-
- gpt-4o-realtime-preview-2024-10-01
1235

1336
## Installation
1437

1538
```bash
16-
go get github.com/WqyJh/go-openai-realtime
39+
go get github.com/WqyJh/go-openai-realtime/v2
1740
```
1841

19-
Currently, go-openai-realtime requires Go version 1.19 or greater.
42+
Currently, go-openai-realtime requires Go version 1.22 or greater.
2043

2144
## Usage
2245

@@ -32,7 +55,7 @@ import (
3255
"log"
3356
"os"
3457

35-
openairt "github.com/WqyJh/go-openai-realtime"
58+
openairt "github.com/WqyJh/go-openai-realtime/v2"
3659
)
3760

3861
func main() {
@@ -52,8 +75,8 @@ Switch to another websocket dialer [gorilla/websocket](https://github.com/gorill
5275

5376
```go
5477
import (
55-
openairt "github.com/WqyJh/go-openai-realtime"
56-
gorilla "github.com/WqyJh/go-openai-realtime/contrib/ws-gorilla"
78+
openairt "github.com/WqyJh/go-openai-realtime/v2"
79+
gorilla "github.com/WqyJh/go-openai-realtime/v2/contrib/ws-gorilla"
5780
)
5881

5982
func main() {
@@ -74,14 +97,16 @@ func main() {
7497
```go
7598

7699
import (
77-
openairt "github.com/WqyJh/go-openai-realtime"
100+
openairt "github.com/WqyJh/go-openai-realtime/v2"
78101
)
79102

80103
func main() {
81104
err = conn.SendMessage(ctx, &openairt.SessionUpdateEvent{
82-
Session: openairt.ClientSession{
83-
Modalities: []openairt.Modality{openairt.ModalityText},
84-
},
105+
Session: openairt.SessionUnion{
106+
Realtime: &openairt.RealtimeSession{
107+
OutputModalities: []openairt.Modality{openairt.ModalityText},
108+
},
109+
},
85110
})
86111
}
87112
```
@@ -138,8 +163,8 @@ Based on the event type, you can get the event data by type assertion.
138163
// Teletype response
139164
responseDeltaHandler := func(ctx context.Context, event openairt.ServerEvent) {
140165
switch event.ServerEventType() {
141-
case openairt.ServerEventTypeResponseTextDelta:
142-
fmt.Printf(event.(openairt.ResponseTextDeltaEvent).Delta)
166+
case openairt.ServerEventTypeResponseOutputTextDelta:
167+
fmt.Printf(event.(openairt.ResponseOutputTextDeltaEvent).Delta)
143168
}
144169
}
145170
```

api.go

Lines changed: 17 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,65 +9,35 @@ import (
99
"net/http"
1010
)
1111

12-
type CreateSessionRequest struct {
13-
ClientSession
14-
15-
// The Realtime model used for this session.
16-
Model string `json:"model"`
17-
}
18-
1912
type ClientSecret struct {
2013
// Ephemeral key usable in client environments to authenticate connections to the Realtime API. Use this in client-side environments rather than a standard API token, which should only be used server-side.
2114
Value string `json:"value"`
2215
// Timestamp for when the token expires. Currently, all tokens expire after one minute.
2316
ExpiresAt int64 `json:"expires_at"`
2417
}
2518

26-
type CreateSessionResponse struct {
27-
ServerSession
19+
type ExpiresAfter struct {
20+
// The anchor point for the client secret expiration, meaning that seconds will be added to the created_at time of the client secret to produce an expiration timestamp. Only created_at is currently supported.
21+
Anchor string `json:"anchor,omitempty"`
2822

29-
// Ephemeral key returned by the API.
30-
ClientSecret ClientSecret `json:"client_secret"`
23+
// The number of seconds from the anchor point to the expiration. Select a value between 10 and 7200 (2 hours). This default to 600 seconds (10 minutes) if not specified.
24+
Seconds int `json:"seconds,omitempty"`
3125
}
3226

33-
// CreateTranscriptionSessionRequest is the request for creating a transcription session.
34-
type CreateTranscriptionSessionRequest struct {
35-
// The set of items to include in the transcription.
36-
Include []string `json:"include,omitempty"`
37-
// The format of input audio. Options are "pcm16", "g711_ulaw", or "g711_alaw".
38-
InputAudioFormat AudioFormat `json:"input_audio_format,omitempty"`
39-
// Configuration for input audio noise reduction.
40-
InputAudioNoiseReduction *InputAudioNoiseReduction `json:"input_audio_noise_reduction,omitempty"`
41-
// Configuration for input audio transcription.
42-
InputAudioTranscription *InputAudioTranscription `json:"input_audio_transcription,omitempty"`
43-
44-
// Attention: Keep this field empty! It's shocking that this field is documented but not supported.
45-
// You may get error of "Unknown parameter: 'modalities'." if this field is not empty.
46-
// Issue reported: https://community.openai.com/t/unknown-parameter-modalities-when-creating-transcriptionsessions/1150141/6
47-
// Docs: https://platform.openai.com/docs/api-reference/realtime-sessions/create-transcription#realtime-sessions-create-transcription-modalities
48-
// The set of modalities the model can respond with. To disable audio, set this to ["text"].
49-
Modalities []Modality `json:"modalities,omitempty"`
50-
51-
// Configuration for turn detection.
52-
TurnDetection *ClientTurnDetection `json:"turn_detection,omitempty"`
27+
type CreateClientSecretRequest struct {
28+
// Configuration for the client secret expiration. Expiration refers to the time after which a client secret will no longer be valid for creating sessions. The session itself may continue after that time once started. A secret can be used to create multiple sessions until it expires.
29+
ExpiresAfter *ExpiresAfter `json:"expires_after,omitempty"`
30+
31+
// Session configuration to use for the client secret. Choose either a realtime session or a transcription session.
32+
Session *SessionUnion `json:"session,omitempty"`
5333
}
5434

55-
// CreateTranscriptionSessionResponse is the response from creating a transcription session.
56-
type CreateTranscriptionSessionResponse struct {
57-
// The unique ID of the session.
58-
ID string `json:"id"`
59-
// The object type, must be "realtime.transcription_session".
60-
Object string `json:"object"`
61-
// The format of input audio.
62-
InputAudioFormat AudioFormat `json:"input_audio_format,omitempty"`
63-
// Configuration of the transcription model.
64-
InputAudioTranscription *InputAudioTranscription `json:"input_audio_transcription,omitempty"`
65-
// The set of modalities.
66-
Modalities []Modality `json:"modalities,omitempty"`
67-
// Configuration for turn detection.
68-
TurnDetection *ServerTurnDetection `json:"turn_detection,omitempty"`
35+
type CreateClientSecretResponse struct {
6936
// Ephemeral key returned by the API.
70-
ClientSecret ClientSecret `json:"client_secret"`
37+
ClientSecret
38+
39+
// Session configuration to use for the client secret. Choose either a realtime session or a transcription session.
40+
Session *SessionUnion `json:"session,omitempty"`
7141
}
7242

7343
type OpenAIError struct {
@@ -84,7 +54,7 @@ type ErrorResponse struct { //nolint:errname // this is a http error response
8454
}
8555

8656
func (e *ErrorResponse) Error() string {
87-
return e.OpenAIError.Message
57+
return e.Message
8858
}
8959

9060
type httpOption struct {

0 commit comments

Comments
 (0)