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
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,34 @@ export function toAnthropic(
throw new Error("Logit bias is not supported");
}

// Map response_format to Anthropic's output_config.format
// OpenAI uses `response_format: { type: "json_schema", json_schema: { schema, name } }`
// Anthropic uses `output_config: { format: { type: "json_schema", json_schema: { schema, name } } }`
// Note: Anthropic does not support `strict` (OpenAI-specific), so it is omitted.
if (
openAIBody.response_format &&
typeof openAIBody.response_format === "object" &&
"type" in openAIBody.response_format &&
openAIBody.response_format.type === "json_schema" &&
"json_schema" in openAIBody.response_format
) {
const jsonSchema = (openAIBody.response_format as any).json_schema;
if (jsonSchema?.schema) {
antBody.output_config = {
format: {
type: "json_schema",
json_schema: {
schema: jsonSchema.schema,
...(jsonSchema.name && { name: jsonSchema.name }),
...(jsonSchema.description && {
description: jsonSchema.description,
}),
},
},
};
}
}

// Map context_editing to Anthropic's context_management
if (openAIBody.context_editing?.enabled) {
antBody.context_management = mapContextEditing(openAIBody.context_editing);
Expand Down
16 changes: 16 additions & 0 deletions packages/llm-mapper/transform/types/anthropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ export interface AnthropicRequestBody {
* @see https://docs.anthropic.com/en/docs/build-with-claude/context-editing
*/
context_management?: AnthropicContextManagement;
/**
* Structured output configuration for JSON schema-constrained responses.
* @see https://docs.anthropic.com/en/docs/build-with-claude/structured-output
*/
output_config?: AnthropicOutputConfig;
}

export interface AnthropicOutputConfig {
format: {
type: "json_schema";
json_schema: {
schema: Record<string, unknown>;
name?: string;
description?: string;
};
};
}

export type AnthropicThinkingConfig = {
Expand Down