Skip to content
Merged
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
7 changes: 7 additions & 0 deletions .changeset/slimy-ways-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@tanstack/ai-anthropic': patch
'@tanstack/ai-gemini': patch
'@tanstack/ai-grok': patch
---

Add in opus 4.6 and enhance acceptable config options by providers
2 changes: 1 addition & 1 deletion packages/typescript/ai-anthropic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"test:types": "tsc"
},
"dependencies": {
"@anthropic-ai/sdk": "^0.71.0"
"@anthropic-ai/sdk": "^0.71.2"
},
"peerDependencies": {
"@tanstack/ai": "workspace:^",
Expand Down
3 changes: 2 additions & 1 deletion packages/typescript/ai-anthropic/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ export {
type AnthropicSummarizeConfig,
type AnthropicSummarizeProviderOptions,
} from './adapters/summarize'

export { ANTHROPIC_MODELS } from './model-meta'
// ============================================================================
// Type Exports
// ============================================================================

export type {
AnthropicChatModelProviderOptionsByName,
AnthropicModelInputModalitiesByName,
AnthropicChatModel,
} from './model-meta'
export type {
AnthropicTextMetadata,
Expand Down
89 changes: 65 additions & 24 deletions packages/typescript/ai-anthropic/src/model-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,50 @@ interface ModelMeta<
*/
messageCapabilities?: TMessageCapabilities
}
const CLAUDE_SONNET_4_5 = {
name: 'claude-sonnet-4-5',
id: 'claude-sonnet-4-5',

const CLAUDE_OPUS_4_6 = {
name: 'claude-opus-4-6',
id: 'claude-opus-4-6',
context_window: 200_000,
max_output_tokens: 64_000,
knowledge_cutoff: '2025-09-29',
max_output_tokens: 128_000,
knowledge_cutoff: '2025-05-01',
pricing: {
input: {
normal: 3,
normal: 5,
},
output: {
normal: 25,
},
},
supports: {
input: ['text', 'image', 'document'],
extended_thinking: true,
priority_tier: true,
},
} as const satisfies ModelMeta<
AnthropicContainerOptions &
AnthropicContextManagementOptions &
AnthropicMCPOptions &
AnthropicServiceTierOptions &
AnthropicStopSequencesOptions &
AnthropicThinkingOptions &
AnthropicToolChoiceOptions &
AnthropicSamplingOptions
>

const CLAUDE_OPUS_4_5 = {
name: 'claude-opus-4-5',
id: 'claude-opus-4-5',
context_window: 200_000,
max_output_tokens: 32_000,
knowledge_cutoff: '2025-11-01',
pricing: {
input: {
normal: 15,
},
output: {
normal: 75,
},
},
supports: {
input: ['text', 'image', 'document'],
Expand All @@ -76,18 +107,18 @@ const CLAUDE_SONNET_4_5 = {
AnthropicSamplingOptions
>

const CLAUDE_HAIKU_4_5 = {
name: 'claude-haiku-4-5',
id: 'claude-haiku-4-5',
const CLAUDE_SONNET_4_5 = {
name: 'claude-sonnet-4-5',
id: 'claude-sonnet-4-5',
context_window: 200_000,
max_output_tokens: 64_000,
knowledge_cutoff: '2025-10-01',
knowledge_cutoff: '2025-09-29',
pricing: {
input: {
normal: 1,
normal: 3,
},
output: {
normal: 5,
normal: 15,
},
},
supports: {
Expand All @@ -106,18 +137,18 @@ const CLAUDE_HAIKU_4_5 = {
AnthropicSamplingOptions
>

const CLAUDE_OPUS_4_1 = {
name: 'claude-opus-4-1',
id: 'claude-opus-4-1',
const CLAUDE_HAIKU_4_5 = {
name: 'claude-haiku-4-5',
id: 'claude-haiku-4-5',
context_window: 200_000,
max_output_tokens: 64_000,
knowledge_cutoff: '2025-08-05',
knowledge_cutoff: '2025-10-01',
pricing: {
input: {
normal: 15,
normal: 1,
},
output: {
normal: 75,
normal: 5,
},
},
supports: {
Expand All @@ -136,12 +167,12 @@ const CLAUDE_OPUS_4_1 = {
AnthropicSamplingOptions
>

const CLAUDE_OPUS_4_5 = {
name: 'claude-opus-4-5',
id: 'claude-opus-4-5',
const CLAUDE_OPUS_4_1 = {
name: 'claude-opus-4-1',
id: 'claude-opus-4-1',
context_window: 200_000,
max_output_tokens: 32_000,
knowledge_cutoff: '2025-11-01',
max_output_tokens: 64_000,
knowledge_cutoff: '2025-08-05',
pricing: {
input: {
normal: 15,
Expand Down Expand Up @@ -361,6 +392,7 @@ const CLAUDE_HAIKU_3 = {
: unknown */

export const ANTHROPIC_MODELS = [
CLAUDE_OPUS_4_6.id,
CLAUDE_OPUS_4_5.id,
CLAUDE_SONNET_4_5.id,
CLAUDE_HAIKU_4_5.id,
Expand All @@ -378,11 +410,19 @@ export const ANTHROPIC_MODELS = [
// const ANTHROPIC_VIDEO_MODELS = [] as const

/* type AnthropicModel = (typeof ANTHROPIC_MODELS)[number] */

export type AnthropicChatModel = (typeof ANTHROPIC_MODELS)[number]
// Manual type map for per-model provider options
// Models are differentiated by extended_thinking and priority_tier support
export type AnthropicChatModelProviderOptionsByName = {
// Models with both extended_thinking and priority_tier
[CLAUDE_OPUS_4_6.id]: AnthropicContainerOptions &
AnthropicContextManagementOptions &
AnthropicMCPOptions &
AnthropicServiceTierOptions &
AnthropicStopSequencesOptions &
AnthropicThinkingOptions &
AnthropicToolChoiceOptions &
AnthropicSamplingOptions
[CLAUDE_OPUS_4_5.id]: AnthropicContainerOptions &
AnthropicContextManagementOptions &
AnthropicMCPOptions &
Expand Down Expand Up @@ -470,6 +510,7 @@ export type AnthropicChatModelProviderOptionsByName = {
* @see https://docs.anthropic.com/claude/docs/pdf-support
*/
export type AnthropicModelInputModalitiesByName = {
[CLAUDE_OPUS_4_6.id]: typeof CLAUDE_OPUS_4_6.supports.input
[CLAUDE_OPUS_4_5.id]: typeof CLAUDE_OPUS_4_5.supports.input
[CLAUDE_SONNET_4_5.id]: typeof CLAUDE_SONNET_4_5.supports.input
[CLAUDE_HAIKU_4_5.id]: typeof CLAUDE_HAIKU_4_5.supports.input
Expand Down
4 changes: 3 additions & 1 deletion packages/typescript/ai-anthropic/src/utils/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Anthropic_SDK from '@anthropic-ai/sdk'
import type { ClientOptions } from '@anthropic-ai/sdk'

export interface AnthropicClientConfig {
export interface AnthropicClientConfig extends ClientOptions {
apiKey: string
}

Expand All @@ -11,6 +12,7 @@ export function createAnthropicClient(
config: AnthropicClientConfig,
): Anthropic_SDK {
return new Anthropic_SDK({
...config,
apiKey: config.apiKey,
})
}
Expand Down
25 changes: 11 additions & 14 deletions packages/typescript/ai-gemini/src/adapters/summarize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ import {
generateId,
getGeminiApiKeyFromEnv,
} from '../utils'

import type { GoogleGenAI } from '@google/genai'
import type { GeminiClientConfig } from '../utils'
import type { SummarizeAdapter } from '@tanstack/ai/adapters'
import type {
StreamChunk,
SummarizationOptions,
SummarizationResult,
} from '@tanstack/ai'

/**
* Configuration for Gemini summarize adapter
*/
export interface GeminiSummarizeConfig extends GeminiClientConfig {}
/**
* Available Gemini models for summarization
*/
Expand Down Expand Up @@ -66,15 +70,8 @@ export class GeminiSummarizeAdapter<

private client: GoogleGenAI

constructor(
apiKeyOrClient: string | GoogleGenAI,
model: TModel,
_options: GeminiSummarizeAdapterOptions = {},
) {
this.client =
typeof apiKeyOrClient === 'string'
? createGeminiClient({ apiKey: apiKeyOrClient })
: apiKeyOrClient
constructor(config: GeminiSummarizeConfig, model: TModel) {
this.client = createGeminiClient(config)
this.model = model
}

Expand Down Expand Up @@ -224,18 +221,18 @@ export class GeminiSummarizeAdapter<
export function createGeminiSummarize<TModel extends GeminiSummarizeModel>(
apiKey: string,
model: TModel,
options?: GeminiSummarizeAdapterOptions,
config?: Omit<GeminiSummarizeConfig, 'apiKey'>,
): GeminiSummarizeAdapter<TModel> {
return new GeminiSummarizeAdapter(apiKey, model, options)
return new GeminiSummarizeAdapter({ ...config, apiKey }, model)
}

/**
* Creates a Gemini summarize adapter with API key from environment and required model
*/
export function geminiSummarize<TModel extends GeminiSummarizeModel>(
model: TModel,
options?: GeminiSummarizeAdapterOptions,
config?: Omit<GeminiSummarizeConfig, 'apiKey'>,
): GeminiSummarizeAdapter<TModel> {
const apiKey = getGeminiApiKeyFromEnv()
return new GeminiSummarizeAdapter(apiKey, model, options)
return new GeminiSummarizeAdapter({ ...config, apiKey }, model)
}
4 changes: 3 additions & 1 deletion packages/typescript/ai-gemini/src/utils/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { GoogleGenAI } from '@google/genai'
import type { GoogleGenAIOptions } from '@google/genai'

export interface GeminiClientConfig {
export interface GeminiClientConfig extends GoogleGenAIOptions {
apiKey: string
}

Expand All @@ -9,6 +10,7 @@ export interface GeminiClientConfig {
*/
export function createGeminiClient(config: GeminiClientConfig): GoogleGenAI {
return new GoogleGenAI({
...config,
apiKey: config.apiKey,
})
}
Expand Down
5 changes: 1 addition & 4 deletions packages/typescript/ai-grok/src/adapters/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
validateNumberOfImages,
validatePrompt,
} from '../image/image-provider-options'
import type { GROK_IMAGE_MODELS } from '../model-meta'
import type { GrokImageModel } from '../model-meta'
import type {
GrokImageModelProviderOptionsByName,
GrokImageModelSizeByName,
Expand All @@ -24,9 +24,6 @@ import type { GrokClientConfig } from '../utils'
*/
export interface GrokImageConfig extends GrokClientConfig {}

/** Model type for Grok Image */
export type GrokImageModel = (typeof GROK_IMAGE_MODELS)[number]

/**
* Grok Image Generation Adapter
*
Expand Down
3 changes: 2 additions & 1 deletion packages/typescript/ai-grok/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export {
createGrokImage,
grokImage,
type GrokImageConfig,
type GrokImageModel,
} from './adapters/image'
export type {
GrokImageProviderOptions,
Expand All @@ -43,6 +42,8 @@ export type {
GrokModelInputModalitiesByName,
ResolveProviderOptions,
ResolveInputModalities,
GrokChatModel,
GrokImageModel,
} from './model-meta'
export { GROK_CHAT_MODELS, GROK_IMAGE_MODELS } from './model-meta'
export type {
Expand Down
3 changes: 3 additions & 0 deletions packages/typescript/ai-grok/src/model-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ export const GROK_CHAT_MODELS = [
*/
export const GROK_IMAGE_MODELS = [GROK_2_IMAGE.name] as const

export type GrokChatModel = (typeof GROK_CHAT_MODELS)[number]
export type GrokImageModel = (typeof GROK_IMAGE_MODELS)[number]

/**
* Type-only map from Grok chat model name to its supported input modalities.
* Used for type inference when constructing multimodal messages.
Expand Down
5 changes: 3 additions & 2 deletions packages/typescript/ai-grok/src/utils/client.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import OpenAI_SDK from 'openai'
import type { ClientOptions } from 'openai'

export interface GrokClientConfig {
export interface GrokClientConfig extends ClientOptions {
apiKey: string
baseURL?: string
}

/**
* Creates a Grok SDK client instance using OpenAI SDK with xAI's base URL
*/
export function createGrokClient(config: GrokClientConfig): OpenAI_SDK {
return new OpenAI_SDK({
...config,
apiKey: config.apiKey,
baseURL: config.baseURL || 'https://api.x.ai/v1',
})
Expand Down
Loading
Loading