on main help sign in
feat: add responses API support
commit4f7489717b6e400ef7b504767d150258bd439b47 authorkujtimiihoxha <kujtimii.h@gmail.com> dateFri 17 Oct 2025, 18:02 (1 year ago) parentd2c6789
3 files changed+45−8
internal/agent/agent.go+6 internal/agent/coordinator.go+15−3 internal/message/content.go+24−5
internal/agent/agent.go+6
@@ -12,6 +12,7 @@ import (
1212
1313 "charm.land/fantasy"
1414 "charm.land/fantasy/providers/anthropic"
15+ "charm.land/fantasy/providers/openai"
1516 "github.com/charmbracelet/catwalk/pkg/catwalk"
1617 "github.com/charmbracelet/crush/internal/agent/tools"
1718 "github.com/charmbracelet/crush/internal/config"
@@ -241,6 +242,11 @@ func (a *sessionAgent) Run(ctx context.Context, call SessionAgentCall) (*fantasy
241242 currentAssistant.AppendReasoningSignature(reasoning.Signature)
242243 }
243244 }
245+ if openaiData, ok := reasoning.ProviderMetadata[openai.Name]; ok {
246+ if reasoning, ok := openaiData.(*openai.ResponsesReasoningMetadata); ok {
247+ currentAssistant.SetReasoningResponsesData(reasoning)
248+ }
249+ }
244250 currentAssistant.FinishThinking()
245251 return a.messages.Update(genCtx, *currentAssistant)
246252 },
internal/agent/coordinator.go+15−3
@@ -176,9 +176,20 @@ func getProviderOptions(model Model, tp catwalk.Type) fantasy.ProviderOptions {
176176 if !hasReasoningEffort && model.ModelCfg.ReasoningEffort != "" {
177177 mergedOptions["reasoning_effort"] = model.ModelCfg.ReasoningEffort
178178 }
179− parsed, err := openai.ParseOptions(mergedOptions)
180− if err == nil {
181− options[openai.Name] = parsed
179+ if openai.IsResponsesModel(model.CatwalkCfg.ID) {
180+ if openai.IsResponsesReasoningModel(model.CatwalkCfg.ID) {
181+ mergedOptions["reasoning_summary"] = "auto"
182+ mergedOptions["include"] = []openai.IncludeType{openai.IncludeReasoningEncryptedContent}
183+ }
184+ parsed, err := openai.ParseResponsesOptions(mergedOptions)
185+ if err == nil {
186+ options[openai.Name] = parsed
187+ }
188+ } else {
189+ parsed, err := openai.ParseOptions(mergedOptions)
190+ if err == nil {
191+ options[openai.Name] = parsed
192+ }
182193 }
183194 case anthropic.Name:
184195 _, hasThink := mergedOptions["thinking"]
@@ -433,6 +444,7 @@ func (c *coordinator) buildAnthropicProvider(baseURL, apiKey string, headers map
433444func (c *coordinator) buildOpenaiProvider(baseURL, apiKey string, headers map[string]string) fantasy.Provider {
434445 opts := []openai.Option{
435446 openai.WithAPIKey(apiKey),
447+ openai.WithUseResponsesAPI(),
436448 }
437449 if c.cfg.Options.Debug {
438450 httpClient := log.NewHTTPClient()
internal/message/content.go+24−5
@@ -9,6 +9,7 @@ import (
99
1010 "charm.land/fantasy"
1111 "charm.land/fantasy/providers/anthropic"
12+ "charm.land/fantasy/providers/openai"
1213 "github.com/charmbracelet/catwalk/pkg/catwalk"
1314)
1415
@@ -40,10 +41,11 @@ type ContentPart interface {
4041}
4142
4243type ReasoningContent struct {
43− Thinking string `json:"thinking"`
44− Signature string `json:"signature"`
45− StartedAt int64 `json:"started_at,omitempty"`
46− FinishedAt int64 `json:"finished_at,omitempty"`
44+ Thinking string `json:"thinking"`
45+ Signature string `json:"signature"`
46+ ResponsesData *openai.ResponsesReasoningMetadata `json:"responses_data"`
47+ StartedAt int64 `json:"started_at,omitempty"`
48+ FinishedAt int64 `json:"finished_at,omitempty"`
4749}
4850
4951func (tc ReasoningContent) String() string {
@@ -272,6 +274,20 @@ func (m *Message) AppendReasoningSignature(signature string) {
272274 m.Parts = append(m.Parts, ReasoningContent{Signature: signature})
273275}
274276
277+func (m *Message) SetReasoningResponsesData(data *openai.ResponsesReasoningMetadata) {
278+ for i, part := range m.Parts {
279+ if c, ok := part.(ReasoningContent); ok {
280+ m.Parts[i] = ReasoningContent{
281+ Thinking: c.Thinking,
282+ ResponsesData: data,
283+ StartedAt: c.StartedAt,
284+ FinishedAt: c.FinishedAt,
285+ }
286+ return
287+ }
288+ }
289+}
290+
275291func (m *Message) FinishThinking() {
276292 for i, part := range m.Parts {
277293 if c, ok := part.(ReasoningContent); ok {
@@ -420,10 +436,13 @@ func (m *Message) ToAIMessage() []fantasy.Message {
420436 if reasoning.Thinking != "" {
421437 reasoningPart := fantasy.ReasoningPart{Text: reasoning.Thinking, ProviderOptions: fantasy.ProviderOptions{}}
422438 if reasoning.Signature != "" {
423− reasoningPart.ProviderOptions["anthropic"] = &anthropic.ReasoningOptionMetadata{
439+ reasoningPart.ProviderOptions[anthropic.Name] = &anthropic.ReasoningOptionMetadata{
424440 Signature: reasoning.Signature,
425441 }
426442 }
443+ if reasoning.ResponsesData != nil {
444+ reasoningPart.ProviderOptions[openai.Name] = reasoning.ResponsesData
445+ }
427446 parts = append(parts, reasoningPart)
428447 }
429448 for _, call := range m.ToolCalls() {