Skip to content

Commit 91a7bc2

Browse files
authored
fix: forward reasoning_content for RequiresReasoningPassback providers (#133)
* feat: add Reflection AI API provider * fix: support Reflection tool calls and OpenAI-compatible is_error * feat: add ReflectionCompat with reasoning passback * fix: Reflection only accepts store=false * fix: forward reasoning_content for RequiresReasoningPassback providers (reflection) * style: gofmt formatting fix * docs: fix markdown table formatting
1 parent b2a7881 commit 91a7bc2

16 files changed

Lines changed: 95 additions & 18 deletions

‎.env.example‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ ZAI_API_KEY=
3232
STEP_API_KEY=
3333
OPENGATEWAY_API_KEY=
3434
FIREWORKS_API_KEY=
35-
35+
REFLECTION_API_KEY=
3636
# Default model overrides
3737
OPENAI_MODEL=gpt-4o
3838
ANTHROPIC_MODEL=claude-sonnet-4-5

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ When starting any new work (feature, fix, refactor, chore), always create a feat
88

99
## Design Principles
1010

11-
- **Model-agnostic** — single interface for the 28 provider gateways in
11+
- **Model-agnostic** — single interface for the 29 provider gateways in
1212
`catalog/registry/providers.go` (see README "Supported Providers")
1313
- **Host-neutral engine** — Relay owns provider routing, transport, caching,
1414
retry/fallback, and normalized telemetry; hosts own product UX and semantics

‎README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ ANTHROPIC_API_KEY=sk-... go run ./examples/basic/
210210

211211
## Supported Providers
212212

213-
28 provider gateways in `catalog/registry/providers.go` (reflect `/config` uses the same list), listed in registry `SortOrder`. `catalog/registry/docs_test.go` fails when this table, the count, or `.env.example` drift from the registry.
213+
29 provider gateways in `catalog/registry/providers.go` (reflect `/config` uses the same list), listed in registry `SortOrder`. `catalog/registry/docs_test.go` fails when this table, the count, or `.env.example` drift from the registry.
214214

215215
| Provider | ID | Env variable |
216216
|---|---|---|
@@ -242,6 +242,7 @@ ANTHROPIC_API_KEY=sk-... go run ./examples/basic/
242242
| **StepFun** | `stepfun` | `STEP_API_KEY` (+ region `global` / `cn`) |
243243
| **OpenGateway** | `opengateway` | `OPENGATEWAY_API_KEY` |
244244
| **Fireworks AI** | `fireworks` | `FIREWORKS_API_KEY` |
245+
| **Reflection AI** | `reflection` | `REFLECTION_API_KEY` |
245246

246247
Runtime auto-detection uses a separate priority order (`config.APIProviderDetectionOrder`) when no deployment is pinned.
247248

‎catalog/live/fetchers.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ var Registry = map[string]FetchFunc{
8989
"groq": FetchGroq,
9090
"clinepass": FetchClinePass,
9191
"stepfun": FetchStepFun,
92+
"reflection": FetchReflection,
9293
}
9394

9495
// Fetch runs a registered live fetcher.

‎catalog/live/fetchers_providers.go‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,3 +1212,22 @@ func enrichStepFunEntry(e Entry) Entry {
12121212
}
12131213
return e
12141214
}
1215+
1216+
// FetchReflection lists models from the Reflection AI OpenAI-compatible API.
1217+
func FetchReflection(env map[string]string) ([]Entry, error) {
1218+
entries, err := fetchOpenAICompatModels(
1219+
context.Background(),
1220+
envOr(env, "REFLECTION_BASE_URL", "https://api.reflection.ai/openai/v1"),
1221+
env["REFLECTION_API_KEY"], "Bearer",
1222+
)
1223+
if err != nil {
1224+
return nil, err
1225+
}
1226+
for i := range entries {
1227+
entries[i].ThinkingEnabled = true
1228+
entries[i].Features = appendUnique(entries[i].Features, "tools")
1229+
entries[i].Features = appendUnique(entries[i].Features, "structured_output")
1230+
entries[i].Features = appendUnique(entries[i].Features, "thinking:enabled")
1231+
}
1232+
return entries, nil
1233+
}

‎catalog/provider_live_parity_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
func TestAllProviders_LiveFetchParity(t *testing.T) {
1212
t.Parallel()
1313
specs := registry.All()
14-
if len(specs) != 28 {
15-
t.Fatalf("expected 28 providers, got %d", len(specs))
14+
if len(specs) != 29 {
15+
t.Fatalf("expected 29 providers, got %d", len(specs))
1616
}
1717
for _, spec := range specs {
1818
t.Run(spec.ProviderID, func(t *testing.T) {

‎catalog/registry/provider_spec_test.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99

1010
func TestAllProviders_Count(t *testing.T) {
1111
t.Parallel()
12-
if n := len(registry.All()); n != 28 {
13-
t.Fatalf("expected 28 providers, got %d", n)
12+
if n := len(registry.All()); n != 29 {
13+
t.Fatalf("expected 29 providers, got %d", n)
1414
}
1515
}
1616

@@ -39,7 +39,7 @@ func TestProviderSpecs_AgnesOpenAIOnlyLongCatOpenAIPrimary(t *testing.T) {
3939
func TestLiveFetcherKeys_AllProviders(t *testing.T) {
4040
t.Parallel()
4141
keys := registry.LiveFetcherKeys()
42-
if len(keys) != 28 {
42+
if len(keys) != 29 {
4343
t.Fatalf("expected 28 live fetcher keys, got %d", len(keys))
4444
}
4545
}

‎catalog/registry/providers.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,15 @@ func providerSpecs() []ProviderSpec {
269269
ProtocolID: "openai-chat-completions", AdapterID: "fireworks", RuntimeProfileKey: "fireworks",
270270
DNSHost: "api.fireworks.ai",
271271
},
272+
{
273+
ProviderID: "reflection", DisplayName: "Reflection AI", DeploymentID: "reflection-direct", SortOrder: 29, ChatPreference: 29,
274+
RequiresKey: true, CredentialEnv: "REFLECTION_API_KEY",
275+
BaseURLEnv: []string{"REFLECTION_BASE_URL"},
276+
ProbeKind: ProbeOpenAIModels, ProbeBaseURL: "https://api.reflection.ai/openai/v1",
277+
LiveFetcherKey: "reflection", LiveCatalogKey: "reflection",
278+
ProtocolID: "openai-chat-completions", AdapterID: "openai", RuntimeProfileKey: "reflection",
279+
DNSHost: "api.reflection.ai",
280+
},
272281

273282
// ── Niche ─────────────────────────────────────────────────────────
274283
{

‎config/config_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ func TestNormalizeOllamaOpenAIBaseURL(t *testing.T) {
9494

9595
func TestProviderDetectionOrder(t *testing.T) {
9696
t.Parallel()
97-
if len(APIProviderDetectionOrder) != 28 {
98-
t.Errorf("expected 28 providers in detection order, got %d", len(APIProviderDetectionOrder))
97+
if len(APIProviderDetectionOrder) != 29 {
98+
t.Errorf("expected 29 providers in detection order, got %d", len(APIProviderDetectionOrder))
9999
}
100100
if APIProviderDetectionOrder[0] != ProviderAnthropic {
101101
t.Error("expected anthropic first in detection order")

‎config/profiles.go‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const (
3434
ProviderGroq APIProvider = "groq"
3535
ProviderClinePass APIProvider = "clinepass"
3636
ProviderStepFun APIProvider = "stepfun"
37+
ProviderReflection APIProvider = "reflection"
3738
)
3839

3940
// RuntimeProviderProfile defines how a provider is detected and configured at runtime.
@@ -251,13 +252,20 @@ var (
251252
BaseURLEnv: []string{"STEP_BASE_URL"},
252253
APIKeys: []APIKeyDef{{Env: "STEP_API_KEY", Source: "stepfun"}},
253254
}
255+
ReflectionRuntimeProfile = RuntimeProviderProfile{
256+
Mode: "openai", DefaultBaseURL: DefaultReflectionOpenAIBaseURL,
257+
DetectionEnv: []string{"REFLECTION_API_KEY"},
258+
ModelEnv: []string{"REFLECTION_MODEL", "OPENAI_MODEL"},
259+
BaseURLEnv: []string{"REFLECTION_BASE_URL"},
260+
APIKeys: []APIKeyDef{{Env: "REFLECTION_API_KEY", Source: "reflection"}},
261+
}
254262
)
255263

256264
// APIProviderDetectionOrder is the priority order for provider detection.
257265
var APIProviderDetectionOrder = []APIProvider{
258266
ProviderAnthropic, ProviderConcentrate, ProviderAgnes, ProviderLongCat, ProviderFireworks, ProviderOpenRouter, ProviderGrok, ProviderGemini,
259267
ProviderVertex, ProviderBedrock, ProviderZAICoding, ProviderZAIPayg, ProviderCanopyWave, ProviderDeepSeek, ProviderPoolside, ProviderGroq, ProviderClinePass, ProviderAzure, ProviderOpenAI, ProviderOpenCodeGo,
260-
ProviderKimi, ProviderXiaomiMimoPayg, ProviderXiaomiMimoTokenPlan, ProviderMiniMaxTokenPlan, ProviderMiniMaxPayg, ProviderOllama, ProviderStepFun, ProviderOpenGateway,
268+
ProviderKimi, ProviderXiaomiMimoPayg, ProviderXiaomiMimoTokenPlan, ProviderMiniMaxTokenPlan, ProviderMiniMaxPayg, ProviderOllama, ProviderStepFun, ProviderOpenGateway, ProviderReflection,
261269
}
262270

263271
// ProviderModelEnvKeys maps each provider to its model env var keys.
@@ -288,6 +296,7 @@ var ProviderModelEnvKeys = map[APIProvider][]string{
288296
ProviderStepFun: StepFunRuntimeProfile.ModelEnv,
289297
ProviderOpenGateway: OpenGatewayRuntimeProfile.ModelEnv,
290298
ProviderFireworks: FireworksRuntimeProfile.ModelEnv,
299+
ProviderReflection: ReflectionRuntimeProfile.ModelEnv,
291300
}
292301

293302
const (
@@ -297,7 +306,7 @@ const (
297306

298307
// OpenAICompatibleRuntimeProfileOrder is the detection order for runtime profiles.
299308
var OpenAICompatibleRuntimeProfileOrder = []string{
300-
"concentrate", "agnes", "longcat", "fireworks", "openrouter", "grok", "gemini", "anthropic", "zai_coding", "zai_payg", "canopywave", "deepseek", "poolside", "groq", "clinepass", "openai", "opencodego", "kimi", "xiaomi_mimo_payg", "xiaomi_mimo_token_plan", "minimax_token_plan", "minimax_payg", "stepfun", "opengateway",
309+
"concentrate", "agnes", "longcat", "fireworks", "openrouter", "grok", "gemini", "anthropic", "zai_coding", "zai_payg", "canopywave", "deepseek", "poolside", "groq", "clinepass", "openai", "opencodego", "kimi", "xiaomi_mimo_payg", "xiaomi_mimo_token_plan", "minimax_token_plan", "minimax_payg", "stepfun", "opengateway", "reflection",
301310
}
302311

303312
// OpenAICompatibleRuntimeProfiles maps profile key to its runtime profile.
@@ -326,6 +335,7 @@ var OpenAICompatibleRuntimeProfiles = map[string]RuntimeProviderProfile{
326335
"minimax_token_plan": MiniMaxTokenPlanRuntimeProfile,
327336
"minimax_payg": MiniMaxPaygRuntimeProfile,
328337
"stepfun": StepFunRuntimeProfile,
338+
"reflection": ReflectionRuntimeProfile,
329339
}
330340

331341
// RuntimeProviderProfiles maps provider/profile keys to runtime detection profiles.
@@ -357,6 +367,7 @@ var RuntimeProviderProfiles = map[string]RuntimeProviderProfile{
357367
"minimax_token_plan": MiniMaxTokenPlanRuntimeProfile,
358368
"minimax_payg": MiniMaxPaygRuntimeProfile,
359369
"stepfun": StepFunRuntimeProfile,
370+
"reflection": ReflectionRuntimeProfile,
360371
"ollama": OllamaRuntimeProfile,
361372
}
362373

0 commit comments

Comments
 (0)