Skip to content

Migrate OpenAI backends from Chat Completions API to Responses API #84

@NakaokaRei

Description

@NakaokaRei

Summary

OpenAI has released the Responses API as the successor to the Chat Completions API. We should migrate OpenAIBackend (and OpenAIVisionBackend if applicable) to use the new API.

Current State

Both backends make direct URLSession requests to /v1/chat/completions with:

  • messages array (system + user roles)
  • response_format with json_schema for Structured Outputs
  • Response parsing via choices[0].message.content

Relevant files:

  • Sources/SwiftAutoGUI/OpenAIBackend.swift
  • Sources/SwiftAutoGUI/OpenAIVisionBackend.swift (shares schema and parsing logic)

Proposed Changes

Migrate to POST /v1/responses with:

Chat Completions Responses API
messages: [{role, content}] instructions + input
response_format.json_schema text.format
choices[0].message.content output array
/v1/chat/completions /v1/responses

Benefits

  • Lower costs due to improved cache utilization
  • previous_response_id for stateful conversation management
  • Built-in tools (web search, code interpreter, etc.) available for future use
  • Better reasoning model integration

Notes

  • The Chat Completions API is not deprecated yet, so this is not urgent
  • No SDK dependency change needed — we use raw URLSession calls
  • baseURL parameter should be updated to default to the new endpoint path

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions