Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion agents/codelayer/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { LanguageModel, JSONValue } from 'ai'
import { createHash } from 'node:crypto'
import {
Agent,
CUSTOM_RESPONSES_PROVIDER,
doomLoop,
tarsPersona,
type AgentConfig,
Expand Down Expand Up @@ -218,7 +219,7 @@ export function buildProviderOptions(
fastMode: overrides.codex?.fastMode ?? false,
...overrides.codex,
}
const isCustomResponses = (model as { provider?: string }).provider === 'custom-openai-responses'
const isCustomResponses = (model as { provider?: string }).provider === CUSTOM_RESPONSES_PROVIDER
const openaiOptions = isCustomResponses
? (({ fastMode: _fastMode, serviceTier: _serviceTier, ...options }) => ({ ...options, forceReasoning: true }))(codexOptions)
: codexOptions
Expand Down
7 changes: 4 additions & 3 deletions agents/codelayer/src/providers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createAnthropic } from '@ai-sdk/anthropic'
import { createOpenAI } from '@ai-sdk/openai'
import type { LanguageModel } from 'ai'
import { CUSTOM_RESPONSES_PROVIDER } from '@humanlayer/agentlayer-core'
import { ensureFileAuthStore, type AuthInfo } from '@humanlayer/agentlayer-provider-auth'
import { createCopilotProvider } from '@humanlayer/agentlayer-provider-github-copilot'
import {
Expand Down Expand Up @@ -275,7 +276,7 @@ function reportCustomResponsesError(options: {
error: safeMessage,
errorName: error.name,
operation: options.operation,
provider: 'custom-openai-responses',
provider: CUSTOM_RESPONSES_PROVIDER,
statusCode,
},
})
Expand All @@ -302,7 +303,7 @@ export function createCustomCodexResponsesModel(options: {
return await captureResponseUsage(response, rawUsage)
}
return createOpenAI({
name: 'custom-openai-responses',
name: CUSTOM_RESPONSES_PROVIDER,
baseURL: override.baseURL,
apiKey: override.apiKey,
fetch: requestFetch as typeof globalThis.fetch,
Expand All @@ -312,7 +313,7 @@ export function createCustomCodexResponsesModel(options: {

return {
specificationVersion: modelMetadata.specificationVersion,
provider: 'custom-openai-responses',
provider: CUSTOM_RESPONSES_PROVIDER,
modelId: selectedModelId,
supportedUrls: modelMetadata.supportedUrls,
doGenerate: async (request) => {
Expand Down
1 change: 1 addition & 0 deletions packages/agentlayer-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export {
toolResultMessage,
userMessage,
} from './messages'
export { CUSTOM_RESPONSES_PROVIDER } from './models'
export { createOutputRenderer, type OutputRenderer, type OutputRendererOptions } from './output-renderer'
export { getPendingToolCalls } from './pending'
export * from './prompts'
Expand Down
16 changes: 14 additions & 2 deletions packages/agentlayer-core/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ export function getCodexContextWindow(modelId: string): number {
return CODEX_CONTEXT_WINDOWS[modelId as CodexModel] ?? CODEX_CONTEXT_WINDOWS['gpt-5.5']
}

/**
* Provider name for a user-supplied OpenAI-compatible Responses endpoint (Azure AI
* Foundry, or OpenAI direct). The models behind it are OpenAI catalog models, so the
* key must resolve to `openai` here — anything else silently costs nothing, because a
* pricing miss is reported as `undefined` rather than an error. CodeLayer builds the
* model with this exact name; import it from there rather than repeating the literal.
*/
export const CUSTOM_RESPONSES_PROVIDER = 'custom-openai-responses'

const PROVIDER_LIMIT_OVERRIDES: Record<string, Partial<ModelLimits>> = {}

function getProviderLimitOverride(modelKey: ModelKey): Partial<ModelLimits> | undefined {
Expand Down Expand Up @@ -108,8 +117,11 @@ export class ModelProvider {
// AI SDK provider keys include a suffix (e.g. "anthropic.messages", "openai.chat")
// but models.dev uses the base provider name (e.g. "anthropic", "openai")
const baseKey = rawProviderKey.split('.')[0]!
// Codex providers use custom names but their models are OpenAI models
const providerKey = baseKey.startsWith('codex') ? 'openai' : baseKey
// Codex providers use custom names but their models are OpenAI models. So is the model
// behind a custom Responses endpoint: CODELAYER_CODEX_MODEL renames it only on the wire,
// so modelId here is still the selected OpenAI catalog id.
const providerKey =
baseKey.startsWith('codex') || baseKey === CUSTOM_RESPONSES_PROVIDER ? 'openai' : baseKey

const provider = this.modelsData[providerKey]
if (!provider?.models) return undefined
Expand Down
15 changes: 14 additions & 1 deletion packages/agentlayer-core/test/models.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, test } from 'bun:test'
import { CODEX_CONTEXT_WINDOWS, type ModelKey, ModelProvider } from '../src/models'
import { CODEX_CONTEXT_WINDOWS, CUSTOM_RESPONSES_PROVIDER, type ModelKey, ModelProvider } from '../src/models'

describe('ModelProvider.getModelLimits', () => {
const provider = new ModelProvider()
Expand Down Expand Up @@ -35,6 +35,19 @@ describe('ModelProvider.getModelLimits', () => {
expect(limits?.output).toBe(128_000)
})

test('a custom Responses endpoint is priced as the OpenAI model it serves', () => {
// Regression: this key used to miss the catalog entirely, and a pricing miss is
// reported as `undefined`, so Azure AI Foundry sessions recorded tokens and no
// dollars at all — silently, and unrecoverably, since cost is frozen at ingest.
expect(provider.getModelPricing(`${CUSTOM_RESPONSES_PROVIDER}/gpt-5.6-sol`)).toMatchObject({
input: 5,
output: 30,
})

// The public Responses API, not the private Codex one, so it keeps the public window.
expect(provider.getModelLimits(`${CUSTOM_RESPONSES_PROVIDER}/gpt-5.6-sol`)?.context).toBe(1_050_000)
})

test('openai/gpt-5.6 keeps the public OpenAI API context window and pricing', () => {
const limits = provider.getModelLimits('openai/gpt-5.6-sol')

Expand Down
Loading