Repository navigation
feat(gateways): add Requesty gateway #2241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Thibaultjaigu
wants to merge
4
commits into
Twigpine:main
Choose a base branch
from
Thibaultjaigu:add-requesty-provider
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1a81202
feat(gateways): add Requesty hybrid gateway
Thibaultjaigu 757d449
test(gateways): cover Requesty model mapping and credential boundary
Thibaultjaigu 39419fc
docs: add Requesty gateway setup
Thibaultjaigu fcbefd9
test(env): cover loading REQUESTY_API_KEY from provider env files
Thibaultjaigu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import { describe, expect, test } from 'bun:test' | ||
| import requesty, { mapRequestyModel } from './requesty.js' | ||
|
|
||
| describe('requesty gateway live model mapping', () => { | ||
| test('uses hybrid discovery against the public models list', () => { | ||
| expect(requesty.catalog?.source).toBe('hybrid') | ||
| expect(requesty.catalog?.discovery).toEqual( | ||
| expect.objectContaining({ | ||
| kind: 'openai-compatible', | ||
| requiresAuth: false, | ||
| }), | ||
| ) | ||
| expect(requesty.catalog?.discovery?.mapModel).toBe(mapRequestyModel) | ||
| }) | ||
|
|
||
| test('maps Requesty model fields into catalog entries', () => { | ||
| expect( | ||
| mapRequestyModel({ | ||
| id: 'anthropic/claude-sonnet-4-6', | ||
| object: 'model', | ||
| api: 'chat', | ||
| context_window: 1000000, | ||
| max_output_tokens: 64000, | ||
| supports_tool_calling: true, | ||
| supports_reasoning: true, | ||
| supports_vision: true, | ||
| input_price: 0.000003, | ||
| }), | ||
| ).toEqual({ | ||
| id: 'anthropic/claude-sonnet-4-6', | ||
| apiName: 'anthropic/claude-sonnet-4-6', | ||
| label: 'anthropic/claude-sonnet-4-6', | ||
| contextWindow: 1000000, | ||
| maxOutputTokens: 64000, | ||
| capabilities: { | ||
| supportsFunctionCalling: true, | ||
| supportsReasoning: true, | ||
| }, | ||
| }) | ||
|
|
||
| expect( | ||
| mapRequestyModel({ | ||
| id: 'xai/grok-4.6', | ||
| api: 'chat', | ||
| context_window: 256000, | ||
| max_output_tokens: 0, | ||
| supports_tool_calling: false, | ||
| supports_reasoning: false, | ||
| }), | ||
| ).toEqual({ | ||
| id: 'xai/grok-4.6', | ||
| apiName: 'xai/grok-4.6', | ||
| label: 'xai/grok-4.6', | ||
| contextWindow: 256000, | ||
| }) | ||
| }) | ||
|
|
||
| test('filters non-chat and non-coding models', () => { | ||
| expect( | ||
| mapRequestyModel({ | ||
| id: 'openai/text-embedding-3-small', | ||
| api: 'embedding', | ||
| }), | ||
| ).toBeNull() | ||
|
|
||
| expect( | ||
| mapRequestyModel({ | ||
| id: 'vendor/some-model', | ||
| api: 'image', | ||
| }), | ||
| ).toBeNull() | ||
|
|
||
| expect(mapRequestyModel({ id: 'openai/text-embedding-3-large' })).toBeNull() | ||
| expect(mapRequestyModel({})).toBeNull() | ||
| expect(mapRequestyModel({ id: ' ' })).toBeNull() | ||
| expect(mapRequestyModel(null)).toBeNull() | ||
| expect(mapRequestyModel('openai/gpt-5-mini')).toBeNull() | ||
| }) | ||
|
|
||
| test('drops model ids carrying control or ANSI escape characters', () => { | ||
| expect( | ||
| mapRequestyModel({ id: 'openai/gpt-5-mini\u001b[31m', api: 'chat' }), | ||
| ).toBeNull() | ||
| expect( | ||
| mapRequestyModel({ id: 'openai/gpt\u0007-5-mini', api: 'chat' }), | ||
| ).toBeNull() | ||
| expect( | ||
| mapRequestyModel({ id: 'openai/gpt-5-mini\u009b', api: 'chat' }), | ||
| ).toBeNull() | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| import { defineGateway } from '../define.js' | ||
| import type { ModelCatalogEntry } from '../descriptors.js' | ||
| import { | ||
| firstPositiveNumber, | ||
| getTrimmedString, | ||
| isKnownNonCodingModelId, | ||
| isRecord, | ||
| } from '../modelMapping.js' | ||
|
|
||
| // Model ids are rendered in the model picker. Drop anything carrying control | ||
| // characters (including ESC for ANSI sequences) instead of trying to clean it. | ||
| // eslint-disable-next-line no-control-regex | ||
| const CONTROL_CHARACTER_PATTERN = /[\u0000-\u001f\u007f-\u009f]/ | ||
|
|
||
| /** | ||
| * Map Requesty's public GET /v1/models payload into a catalog entry. | ||
| * Requesty reports `context_window`, `max_output_tokens` and boolean | ||
| * `supports_*` flags instead of OpenRouter's `context_length` and | ||
| * `supported_parameters`. | ||
| */ | ||
| export function mapRequestyModel(raw: unknown): ModelCatalogEntry | null { | ||
| if (!isRecord(raw)) { | ||
| return null | ||
| } | ||
|
|
||
| const id = getTrimmedString(raw, 'id') | ||
| if ( | ||
| !id || | ||
| CONTROL_CHARACTER_PATTERN.test(id) || | ||
| isKnownNonCodingModelId(id) | ||
| ) { | ||
| return null | ||
| } | ||
|
|
||
| const api = getTrimmedString(raw, 'api') | ||
| if (api && api !== 'chat') { | ||
| return null | ||
| } | ||
|
|
||
| const toolCall = raw.supports_tool_calling === true | ||
| const reasoning = raw.supports_reasoning === true | ||
| const contextWindow = firstPositiveNumber(raw.context_window) | ||
| const maxOutputTokens = firstPositiveNumber(raw.max_output_tokens) | ||
|
|
||
| return { | ||
| id, | ||
| apiName: id, | ||
| label: id, | ||
| ...(contextWindow ? { contextWindow } : {}), | ||
| ...(maxOutputTokens ? { maxOutputTokens } : {}), | ||
| ...(toolCall || reasoning | ||
| ? { | ||
| capabilities: { | ||
| ...(toolCall ? { supportsFunctionCalling: true } : {}), | ||
| ...(reasoning ? { supportsReasoning: true } : {}), | ||
| }, | ||
| } | ||
| : {}), | ||
| } | ||
| } | ||
|
|
||
| export default defineGateway({ | ||
| id: 'requesty', | ||
| label: 'Requesty', | ||
| category: 'aggregating', | ||
| defaultBaseUrl: 'https://router.requesty.ai/v1', | ||
| defaultModel: 'openai/gpt-5-mini', | ||
| supportsModelRouting: true, | ||
| setup: { | ||
| requiresAuth: true, | ||
| authMode: 'api-key', | ||
| credentialEnvVars: ['REQUESTY_API_KEY'], | ||
| }, | ||
| startup: { | ||
| probeReadiness: 'openai-compatible-models', | ||
| }, | ||
| transportConfig: { | ||
| kind: 'openai-compatible', | ||
| openaiShim: { | ||
| supportsAuthHeaders: true, | ||
| }, | ||
| }, | ||
| preset: { | ||
| id: 'requesty', | ||
| description: 'Requesty OpenAI-compatible gateway', | ||
| apiKeyEnvVars: ['REQUESTY_API_KEY'], | ||
| vendorId: 'openai', | ||
| }, | ||
| validation: { | ||
| kind: 'credential-env', | ||
| routing: { | ||
| matchDefaultBaseUrl: true, | ||
| matchBaseUrlHosts: [ | ||
| 'router.requesty.ai', | ||
| 'router.eu.requesty.ai', | ||
| 'router.us.requesty.ai', | ||
| 'router.ap.requesty.ai', | ||
| ], | ||
| }, | ||
| credentialEnvVars: ['REQUESTY_API_KEY', 'OPENAI_API_KEYS', 'OPENAI_API_KEY'], | ||
| missingCredentialMessage: | ||
| 'Set REQUESTY_API_KEY or OPENAI_API_KEYS / OPENAI_API_KEY for the Requesty gateway.', | ||
| }, | ||
| catalog: { | ||
| source: 'hybrid', | ||
| discovery: { | ||
| kind: 'openai-compatible', | ||
| // The public model list works without a key; inference still needs one. | ||
| requiresAuth: false, | ||
| mapModel: mapRequestyModel, | ||
| }, | ||
| discoveryCacheTtl: '1d', | ||
| discoveryRefreshMode: 'background-if-stale', | ||
| allowManualRefresh: true, | ||
| models: [ | ||
| { id: 'requesty-gpt-5-mini', apiName: 'openai/gpt-5-mini', label: 'GPT-5 Mini (via Requesty)', modelDescriptorId: 'gpt-5-mini' }, | ||
| { id: 'requesty-claude-sonnet-4-6', apiName: 'anthropic/claude-sonnet-4-6', label: 'Claude Sonnet 4.6 (via Requesty)', modelDescriptorId: 'claude-sonnet-4-6' }, | ||
| { id: 'requesty-grok-4.6', apiName: 'xai/grok-4.6', label: 'Grok 4.6 (via Requesty)', modelDescriptorId: 'grok-4.6' }, | ||
| ], | ||
| }, | ||
| usage: { supported: false }, | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Remove the colon from the EU base URL.
If a user copies this URL as the
OPENAI_BASE_URLvalue, the value ends in/v1:instead of/v1. The exact Requesty URL check will not selectREQUESTY_API_KEY, so an EU setup withoutOPENAI_API_KEYwill fail authentication. Put the explanatory colon outside the copyable URL.As per path instructions, keep setup guidance accurate. The PR objective specifies exact HTTPS
/v1URL matching.Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents
Source: Path instructions