v0.3.65 9ef467d

openai_responses.go RawHistoryFolder

1package provider
2
3// OpenAI Responses API client (api.openai.com/v1/responses).
4//
5// Strategy: reuse the existing codexClient (which already speaks the
6// Responses wire format) via a header-rewriting RoundTripper. The codex
7// client always sends `chatgpt-account-id` and `openai-beta`; the public
8// Responses API on api.openai.com accepts but doesn't require those —
9// we strip the account-id header on its way out so the request looks
10// like a normal authenticated OpenAI call.
11//
12// This is a separate provider from `openai` (which is Chat Completions);
13// users opt in by passing `--provider openai-responses` or by picking a
14// model whose catalog entry tags it under that provider id.
15//
16// Auth: API key via Authorization: Bearer (set by codexClient itself).
17// Different from openai-codex, which uses OAuth subscription tokens.
18
19import (
20	"net/http"
21	"strings"
22)
23
24const openaiResponsesDefaultBaseURL = "https://api.openai.com/v1/responses"
25
26// openaiResponsesTransport rewrites headers so the codex client (which
27// is designed for chatgpt.com OAuth tokens) can target the public
28// OpenAI Responses API with a normal API key.
29type openaiResponsesTransport struct {
30	inner http.RoundTripper
31}
32
33func (t *openaiResponsesTransport) RoundTrip(req *http.Request) (*http.Response, error) {
34	clone := req.Clone(req.Context())
35	// The codex client always sets chatgpt-account-id; api.openai.com
36	// doesn't need it and may reject the OAuth identity headers, so
37	// strip them.
38	clone.Header.Del("chatgpt-account-id")
39	clone.Header.Del("openai-beta")
40	clone.Header.Del("originator")
41	// Keep Authorization: Bearer <key> as set by the codex client.
42	return t.inner.RoundTrip(clone)
43}
44
45// NewOpenAIResponses returns an OpenAI Responses-API client (API-key
46// flow). Uses the same wire format as the ChatGPT Codex backend but
47// with the public api.openai.com endpoint and standard Bearer auth.
48//
49// baseURL may be empty; defaults to https://api.openai.com/v1/responses.
50func NewOpenAIResponses(apiKey, baseURL string) Client {
51	return NewOpenAIResponsesNamed(apiKey, baseURL, "openai-responses")
52}
53
54// NewOpenAIResponsesNamed returns a public OpenAI Responses-API client
55// reporting the supplied provider name. This lets the `openai` provider
56// route Responses-only preview models without changing the visible provider.
57func NewOpenAIResponsesNamed(apiKey, baseURL, name string) Client {
58	baseURL = responsesURL(baseURL)
59	httpClient := &http.Client{
60		Transport: &openaiResponsesTransport{inner: http.DefaultTransport},
61		Timeout:   0,
62	}
63	inner := &codexClient{
64		token:        apiKey,
65		accountID:    "", // unused; transport strips the header
66		baseURL:      strings.TrimRight(baseURL, "/"),
67		errorLabel:   "openai",
68		providerName: name,
69		http:         httpClient,
70	}
71	return &renamedClient{inner: inner, name: name}
72}
73
74// responsesURL accepts either an API root or a complete Responses endpoint.
75// Catalog model entries generally carry API roots, while explicit overrides
76// may already include /responses.
77func responsesURL(baseURL string) string {
78	baseURL = strings.TrimRight(baseURL, "/")
79	if baseURL == "" {
80		return openaiResponsesDefaultBaseURL
81	}
82	if strings.HasSuffix(baseURL, "/responses") {
83		return baseURL
84	}
85	if versionSegmentSuffix.MatchString(baseURL) {
86		return baseURL + "/responses"
87	}
88	return baseURL + "/v1/responses"
89}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 476

↑↓ moveenter openesc close