@shop-os/modelkit 0.2.10 → 0.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -371,17 +371,36 @@ type ProviderKeys = Partial<Record<ProviderKeyName, string>> & {
371
371
  higgsfieldSecret?: string;
372
372
  /** Bedrock runtime credentials for Anthropic models when routing.anthropic = "bedrock". */
373
373
  aws?: {
374
- accessKeyId: string;
375
- secretAccessKey: string;
374
+ /** Bedrock region. Must serve the chosen inference profile (us-east-1 for "us"). */
376
375
  region: string;
376
+ accessKeyId?: string;
377
+ secretAccessKey?: string;
377
378
  sessionToken?: string;
379
+ /** Bedrock API key (AWS_BEARER_TOKEN_BEDROCK). Wins over SigV4. */
380
+ apiKey?: string;
381
+ /** For ECS task roles and other chains. The kit has no AWS SDK dependency; the app passes e.g. defaultProvider(). */
382
+ credentialProvider?: () => PromiseLike<{
383
+ accessKeyId: string;
384
+ secretAccessKey: string;
385
+ sessionToken?: string;
386
+ }>;
378
387
  };
379
388
  };
389
+ /** Key names a call can require, including the Bedrock credentials object. */
390
+ type RequiredKeyName = ProviderKeyName | "aws";
391
+ /** True when region is set AND (apiKey OR credentialProvider OR both static keys). */
392
+ declare function hasAwsCredentials(aws: ProviderKeys["aws"]): aws is NonNullable<ProviderKeys["aws"]>;
380
393
  interface Routing {
381
394
  /** Text models: direct provider or the Cloudflare AI Gateway. */
382
395
  text?: "direct" | "cloudflare";
383
- /** Anthropic chat via Bedrock (us. prefixed ids) or the Anthropic API. */
396
+ /**
397
+ * Anthropic chat via Bedrock or the Anthropic API. Default "direct". A row's
398
+ * `providerOptions.modelkit.transport` wins over this. When the chosen transport has
399
+ * no credentials and the other one has, the kit uses the other one and warns.
400
+ */
384
401
  anthropic?: "direct" | "bedrock";
402
+ /** Inference profile prefix for Bedrock ids. Default "us". */
403
+ bedrockProfile?: "us" | "global" | "eu" | "jp" | "au";
385
404
  /** fal from geo-blocked regions goes through the Cloudflare passthrough. */
386
405
  fal?: "direct" | "cloudflare-passthrough";
387
406
  cloudflare?: {
@@ -559,7 +578,7 @@ declare const ADAPTER_KEYS: Record<AdapterId, ProviderKeyName[]>;
559
578
  * enterprise tier; otherwise the pro keys are used. Mirrors trigger-workflows
560
579
  * enterprise-keys.ts, extended to Ark and Prodia.
561
580
  */
562
- declare function resolveKeys(config: ModelKitConfig, names: ProviderKeyName[], tier?: "pro" | "enterprise"): ProviderKeys;
581
+ declare function resolveKeys(config: ModelKitConfig, names: RequiredKeyName[], tier?: "pro" | "enterprise"): ProviderKeys;
563
582
  /** Build a ProviderKeys map from env with the given prefix ("" for pro, "ENTERPRISE_" for enterprise). */
564
583
  declare function keysFromEnv(env: NodeJS.ProcessEnv, prefix?: string): ProviderKeys;
565
584
 
@@ -588,11 +607,16 @@ declare function pollUntil<T>(check: () => Promise<T | undefined>, opts: {
588
607
  maxIntervalMs?: number;
589
608
  }): Promise<T>;
590
609
 
610
+ declare const ANTHROPIC_TRANSPORTS: readonly ["direct", "bedrock"];
611
+ type AnthropicTransport = (typeof ANTHROPIC_TRANSPORTS)[number];
612
+
591
613
  /** Everything an adapter needs for one call. Resolved by the core before dispatch. */
592
614
  interface AdapterContext {
593
615
  model: CatalogModel;
594
616
  keys: ProviderKeys;
595
617
  routing: Routing;
618
+ /** Resolved transport of an Anthropic text row (see anthropic-transport.ts); unset means direct. */
619
+ anthropicTransport?: AnthropicTransport;
596
620
  endpoints?: AdapterEndpoints;
597
621
  fetch: typeof fetch;
598
622
  logger: Pick<Console, "debug" | "info" | "warn" | "error">;
@@ -689,6 +713,8 @@ interface ModelKit extends TextMethods {
689
713
  generateVideo(req: VideoCallOptions, call?: CallContext): Promise<VideoCallJob>;
690
714
  /** AI SDK LanguageModel for chat models. Pair with the catalog's providerOptions. */
691
715
  languageModel(modelId: string, call?: CallContext): LanguageModelHandle;
716
+ /** Usage-event `provider` for a catalog model, without building it: "bedrock" on Bedrock, else the vendor. */
717
+ usageProvider(modelId: string, call?: CallContext): string;
692
718
  /** Generate music or a soundtrack. Blocks until the provider returns audio. */
693
719
  generateAudio(req: AudioRequest, call?: CallContext): Promise<AudioResult>;
694
720
  /**
@@ -708,6 +734,8 @@ interface LanguageModelHandle {
708
734
  model: LanguageModelV3;
709
735
  providerOptions: ProviderOptions;
710
736
  catalog: CatalogModel;
737
+ /** Usage-event `provider`: "bedrock" on Bedrock, else the vendor. */
738
+ usageProvider: string;
711
739
  }
712
740
  type AdapterRegistry = Partial<Record<AdapterId, Adapter>>;
713
741
  declare function createModelKit(config: ModelKitConfig, adapters: AdapterRegistry): ModelKit;
@@ -782,4 +810,4 @@ declare function describeThrown(cause: unknown): ThrownErrorInfo;
782
810
  /** Add the AI SDK `GeneratedFile` accessors to adapter image bytes. base64 is computed on first read. */
783
811
  declare function toGeneratedImage(image: ImageBytes): GeneratedImage;
784
812
 
785
- export { ADAPTER_IDS, ADAPTER_KEYS, type Adapter, type AdapterContext, type AdapterEndpoints, type AdapterId, type AdapterRegistry, type AiTextProviderOptions, type AspectRatio, type AudioRequest, type AudioResult, type CallContext, Catalog, type CatalogAuth, type CatalogCache, type CatalogCapabilities, type CatalogDisplay, type CatalogEnvelope, type CatalogModel, CatalogModelSchema, type CatalogOrigin, CatalogSchema, type CatalogSource, type CatalogTextModel, DEFAULT_ADAPTERS, type DefaultObjectOutput, type Exposure, ExposureSchema, type GeneratedImage, type ImageBytes, type ImageCallOptions, type ImageCallResult, type ImageQuality, type ImageRequest, type ImageResult, type ImageSafetySetting, type ImageSize, type JsonObject, JsonObjectSchema, type JsonPrimitive, type JsonValue, JsonValueSchema, type LanguageModelHandle, type Lifecycle, type LiveCatalogState, MODELS, type MediaPart, type MediaRef, type ModelConstraints, type ModelKit, type ModelKitConfig, ModelKitError, type ModelKitErrorCode, type ModelKitErrorInit, type ModelType, type ModelkitGenerateObjectOptions, type ModelkitGenerateTextOptions, type ModelkitStreamObjectOptions, type ModelkitStreamTextOptions, type ObjectOutput, type ObjectResult, type OnUnsupported, type OutputFormat, type PricingKind, type PrimeCatalogResult, type ProviderErrorBody, type ProviderKeyName, type ProviderKeys, type ProviderOptionValue, type ProviderOptions, type ReferenceLimits, type RequiredInput, type ResolveResult, type Routing, SURFACES, type SupportedOption, type Surface, SurfaceSchema, type TextMethods, type TextModelInstance, type UpscaleOptions, type UsageEvent, type UsageModality, type UsageUnit, type VideoCallJob, type VideoCallOptions, type VideoJob, type VideoModel, type VideoRequest, type VideoResolution, type VideoResult, type Warning, aiSdkTextAdapter, arkAdapter, aspectRatioToSize, classifyHttpError, compareCatalogOrder, createDefaultModelKit, createModelKit, describe, describeThrown, generateImage as experimental_generateImage, falAdapter, fileCatalogCache, generateAudio, generateImage, generateObject, generateText, generateVideo, googleGenaiAdapter, googleImageAdapter, higgsfieldAdapter, isListed, isListedOn, isModelKitError, keysFromEnv, languageModel, liveCatalog, liveState, mergeTextProviderOptions, nearestAspectRatio, normalizeExposure, openaiImageAdapter, passthroughTextModel, pollUntil, prepareMediaPart, primeCatalog, prodiaAdapter, readErrorBody, replicateAdapter, resetLiveCatalog, resolveAudioOptions, resolveImageOptions, resolveKeys, resolveVideoOptions, shouldRetry, sleep, sortCatalogRows, streamObject, streamText, textUsageEvent, toGeneratedImage, withRetry, xaiVideoAdapter };
813
+ export { ADAPTER_IDS, ADAPTER_KEYS, type Adapter, type AdapterContext, type AdapterEndpoints, type AdapterId, type AdapterRegistry, type AiTextProviderOptions, type AspectRatio, type AudioRequest, type AudioResult, type CallContext, Catalog, type CatalogAuth, type CatalogCache, type CatalogCapabilities, type CatalogDisplay, type CatalogEnvelope, type CatalogModel, CatalogModelSchema, type CatalogOrigin, CatalogSchema, type CatalogSource, type CatalogTextModel, DEFAULT_ADAPTERS, type DefaultObjectOutput, type Exposure, ExposureSchema, type GeneratedImage, type ImageBytes, type ImageCallOptions, type ImageCallResult, type ImageQuality, type ImageRequest, type ImageResult, type ImageSafetySetting, type ImageSize, type JsonObject, JsonObjectSchema, type JsonPrimitive, type JsonValue, JsonValueSchema, type LanguageModelHandle, type Lifecycle, type LiveCatalogState, MODELS, type MediaPart, type MediaRef, type ModelConstraints, type ModelKit, type ModelKitConfig, ModelKitError, type ModelKitErrorCode, type ModelKitErrorInit, type ModelType, type ModelkitGenerateObjectOptions, type ModelkitGenerateTextOptions, type ModelkitStreamObjectOptions, type ModelkitStreamTextOptions, type ObjectOutput, type ObjectResult, type OnUnsupported, type OutputFormat, type PricingKind, type PrimeCatalogResult, type ProviderErrorBody, type ProviderKeyName, type ProviderKeys, type ProviderOptionValue, type ProviderOptions, type ReferenceLimits, type RequiredInput, type RequiredKeyName, type ResolveResult, type Routing, SURFACES, type SupportedOption, type Surface, SurfaceSchema, type TextMethods, type TextModelInstance, type UpscaleOptions, type UsageEvent, type UsageModality, type UsageUnit, type VideoCallJob, type VideoCallOptions, type VideoJob, type VideoModel, type VideoRequest, type VideoResolution, type VideoResult, type Warning, aiSdkTextAdapter, arkAdapter, aspectRatioToSize, classifyHttpError, compareCatalogOrder, createDefaultModelKit, createModelKit, describe, describeThrown, generateImage as experimental_generateImage, falAdapter, fileCatalogCache, generateAudio, generateImage, generateObject, generateText, generateVideo, googleGenaiAdapter, googleImageAdapter, hasAwsCredentials, higgsfieldAdapter, isListed, isListedOn, isModelKitError, keysFromEnv, languageModel, liveCatalog, liveState, mergeTextProviderOptions, nearestAspectRatio, normalizeExposure, openaiImageAdapter, passthroughTextModel, pollUntil, prepareMediaPart, primeCatalog, prodiaAdapter, readErrorBody, replicateAdapter, resetLiveCatalog, resolveAudioOptions, resolveImageOptions, resolveKeys, resolveVideoOptions, shouldRetry, sleep, sortCatalogRows, streamObject, streamText, textUsageEvent, toGeneratedImage, withRetry, xaiVideoAdapter };
package/dist/index.d.ts CHANGED
@@ -371,17 +371,36 @@ type ProviderKeys = Partial<Record<ProviderKeyName, string>> & {
371
371
  higgsfieldSecret?: string;
372
372
  /** Bedrock runtime credentials for Anthropic models when routing.anthropic = "bedrock". */
373
373
  aws?: {
374
- accessKeyId: string;
375
- secretAccessKey: string;
374
+ /** Bedrock region. Must serve the chosen inference profile (us-east-1 for "us"). */
376
375
  region: string;
376
+ accessKeyId?: string;
377
+ secretAccessKey?: string;
377
378
  sessionToken?: string;
379
+ /** Bedrock API key (AWS_BEARER_TOKEN_BEDROCK). Wins over SigV4. */
380
+ apiKey?: string;
381
+ /** For ECS task roles and other chains. The kit has no AWS SDK dependency; the app passes e.g. defaultProvider(). */
382
+ credentialProvider?: () => PromiseLike<{
383
+ accessKeyId: string;
384
+ secretAccessKey: string;
385
+ sessionToken?: string;
386
+ }>;
378
387
  };
379
388
  };
389
+ /** Key names a call can require, including the Bedrock credentials object. */
390
+ type RequiredKeyName = ProviderKeyName | "aws";
391
+ /** True when region is set AND (apiKey OR credentialProvider OR both static keys). */
392
+ declare function hasAwsCredentials(aws: ProviderKeys["aws"]): aws is NonNullable<ProviderKeys["aws"]>;
380
393
  interface Routing {
381
394
  /** Text models: direct provider or the Cloudflare AI Gateway. */
382
395
  text?: "direct" | "cloudflare";
383
- /** Anthropic chat via Bedrock (us. prefixed ids) or the Anthropic API. */
396
+ /**
397
+ * Anthropic chat via Bedrock or the Anthropic API. Default "direct". A row's
398
+ * `providerOptions.modelkit.transport` wins over this. When the chosen transport has
399
+ * no credentials and the other one has, the kit uses the other one and warns.
400
+ */
384
401
  anthropic?: "direct" | "bedrock";
402
+ /** Inference profile prefix for Bedrock ids. Default "us". */
403
+ bedrockProfile?: "us" | "global" | "eu" | "jp" | "au";
385
404
  /** fal from geo-blocked regions goes through the Cloudflare passthrough. */
386
405
  fal?: "direct" | "cloudflare-passthrough";
387
406
  cloudflare?: {
@@ -559,7 +578,7 @@ declare const ADAPTER_KEYS: Record<AdapterId, ProviderKeyName[]>;
559
578
  * enterprise tier; otherwise the pro keys are used. Mirrors trigger-workflows
560
579
  * enterprise-keys.ts, extended to Ark and Prodia.
561
580
  */
562
- declare function resolveKeys(config: ModelKitConfig, names: ProviderKeyName[], tier?: "pro" | "enterprise"): ProviderKeys;
581
+ declare function resolveKeys(config: ModelKitConfig, names: RequiredKeyName[], tier?: "pro" | "enterprise"): ProviderKeys;
563
582
  /** Build a ProviderKeys map from env with the given prefix ("" for pro, "ENTERPRISE_" for enterprise). */
564
583
  declare function keysFromEnv(env: NodeJS.ProcessEnv, prefix?: string): ProviderKeys;
565
584
 
@@ -588,11 +607,16 @@ declare function pollUntil<T>(check: () => Promise<T | undefined>, opts: {
588
607
  maxIntervalMs?: number;
589
608
  }): Promise<T>;
590
609
 
610
+ declare const ANTHROPIC_TRANSPORTS: readonly ["direct", "bedrock"];
611
+ type AnthropicTransport = (typeof ANTHROPIC_TRANSPORTS)[number];
612
+
591
613
  /** Everything an adapter needs for one call. Resolved by the core before dispatch. */
592
614
  interface AdapterContext {
593
615
  model: CatalogModel;
594
616
  keys: ProviderKeys;
595
617
  routing: Routing;
618
+ /** Resolved transport of an Anthropic text row (see anthropic-transport.ts); unset means direct. */
619
+ anthropicTransport?: AnthropicTransport;
596
620
  endpoints?: AdapterEndpoints;
597
621
  fetch: typeof fetch;
598
622
  logger: Pick<Console, "debug" | "info" | "warn" | "error">;
@@ -689,6 +713,8 @@ interface ModelKit extends TextMethods {
689
713
  generateVideo(req: VideoCallOptions, call?: CallContext): Promise<VideoCallJob>;
690
714
  /** AI SDK LanguageModel for chat models. Pair with the catalog's providerOptions. */
691
715
  languageModel(modelId: string, call?: CallContext): LanguageModelHandle;
716
+ /** Usage-event `provider` for a catalog model, without building it: "bedrock" on Bedrock, else the vendor. */
717
+ usageProvider(modelId: string, call?: CallContext): string;
692
718
  /** Generate music or a soundtrack. Blocks until the provider returns audio. */
693
719
  generateAudio(req: AudioRequest, call?: CallContext): Promise<AudioResult>;
694
720
  /**
@@ -708,6 +734,8 @@ interface LanguageModelHandle {
708
734
  model: LanguageModelV3;
709
735
  providerOptions: ProviderOptions;
710
736
  catalog: CatalogModel;
737
+ /** Usage-event `provider`: "bedrock" on Bedrock, else the vendor. */
738
+ usageProvider: string;
711
739
  }
712
740
  type AdapterRegistry = Partial<Record<AdapterId, Adapter>>;
713
741
  declare function createModelKit(config: ModelKitConfig, adapters: AdapterRegistry): ModelKit;
@@ -782,4 +810,4 @@ declare function describeThrown(cause: unknown): ThrownErrorInfo;
782
810
  /** Add the AI SDK `GeneratedFile` accessors to adapter image bytes. base64 is computed on first read. */
783
811
  declare function toGeneratedImage(image: ImageBytes): GeneratedImage;
784
812
 
785
- export { ADAPTER_IDS, ADAPTER_KEYS, type Adapter, type AdapterContext, type AdapterEndpoints, type AdapterId, type AdapterRegistry, type AiTextProviderOptions, type AspectRatio, type AudioRequest, type AudioResult, type CallContext, Catalog, type CatalogAuth, type CatalogCache, type CatalogCapabilities, type CatalogDisplay, type CatalogEnvelope, type CatalogModel, CatalogModelSchema, type CatalogOrigin, CatalogSchema, type CatalogSource, type CatalogTextModel, DEFAULT_ADAPTERS, type DefaultObjectOutput, type Exposure, ExposureSchema, type GeneratedImage, type ImageBytes, type ImageCallOptions, type ImageCallResult, type ImageQuality, type ImageRequest, type ImageResult, type ImageSafetySetting, type ImageSize, type JsonObject, JsonObjectSchema, type JsonPrimitive, type JsonValue, JsonValueSchema, type LanguageModelHandle, type Lifecycle, type LiveCatalogState, MODELS, type MediaPart, type MediaRef, type ModelConstraints, type ModelKit, type ModelKitConfig, ModelKitError, type ModelKitErrorCode, type ModelKitErrorInit, type ModelType, type ModelkitGenerateObjectOptions, type ModelkitGenerateTextOptions, type ModelkitStreamObjectOptions, type ModelkitStreamTextOptions, type ObjectOutput, type ObjectResult, type OnUnsupported, type OutputFormat, type PricingKind, type PrimeCatalogResult, type ProviderErrorBody, type ProviderKeyName, type ProviderKeys, type ProviderOptionValue, type ProviderOptions, type ReferenceLimits, type RequiredInput, type ResolveResult, type Routing, SURFACES, type SupportedOption, type Surface, SurfaceSchema, type TextMethods, type TextModelInstance, type UpscaleOptions, type UsageEvent, type UsageModality, type UsageUnit, type VideoCallJob, type VideoCallOptions, type VideoJob, type VideoModel, type VideoRequest, type VideoResolution, type VideoResult, type Warning, aiSdkTextAdapter, arkAdapter, aspectRatioToSize, classifyHttpError, compareCatalogOrder, createDefaultModelKit, createModelKit, describe, describeThrown, generateImage as experimental_generateImage, falAdapter, fileCatalogCache, generateAudio, generateImage, generateObject, generateText, generateVideo, googleGenaiAdapter, googleImageAdapter, higgsfieldAdapter, isListed, isListedOn, isModelKitError, keysFromEnv, languageModel, liveCatalog, liveState, mergeTextProviderOptions, nearestAspectRatio, normalizeExposure, openaiImageAdapter, passthroughTextModel, pollUntil, prepareMediaPart, primeCatalog, prodiaAdapter, readErrorBody, replicateAdapter, resetLiveCatalog, resolveAudioOptions, resolveImageOptions, resolveKeys, resolveVideoOptions, shouldRetry, sleep, sortCatalogRows, streamObject, streamText, textUsageEvent, toGeneratedImage, withRetry, xaiVideoAdapter };
813
+ export { ADAPTER_IDS, ADAPTER_KEYS, type Adapter, type AdapterContext, type AdapterEndpoints, type AdapterId, type AdapterRegistry, type AiTextProviderOptions, type AspectRatio, type AudioRequest, type AudioResult, type CallContext, Catalog, type CatalogAuth, type CatalogCache, type CatalogCapabilities, type CatalogDisplay, type CatalogEnvelope, type CatalogModel, CatalogModelSchema, type CatalogOrigin, CatalogSchema, type CatalogSource, type CatalogTextModel, DEFAULT_ADAPTERS, type DefaultObjectOutput, type Exposure, ExposureSchema, type GeneratedImage, type ImageBytes, type ImageCallOptions, type ImageCallResult, type ImageQuality, type ImageRequest, type ImageResult, type ImageSafetySetting, type ImageSize, type JsonObject, JsonObjectSchema, type JsonPrimitive, type JsonValue, JsonValueSchema, type LanguageModelHandle, type Lifecycle, type LiveCatalogState, MODELS, type MediaPart, type MediaRef, type ModelConstraints, type ModelKit, type ModelKitConfig, ModelKitError, type ModelKitErrorCode, type ModelKitErrorInit, type ModelType, type ModelkitGenerateObjectOptions, type ModelkitGenerateTextOptions, type ModelkitStreamObjectOptions, type ModelkitStreamTextOptions, type ObjectOutput, type ObjectResult, type OnUnsupported, type OutputFormat, type PricingKind, type PrimeCatalogResult, type ProviderErrorBody, type ProviderKeyName, type ProviderKeys, type ProviderOptionValue, type ProviderOptions, type ReferenceLimits, type RequiredInput, type RequiredKeyName, type ResolveResult, type Routing, SURFACES, type SupportedOption, type Surface, SurfaceSchema, type TextMethods, type TextModelInstance, type UpscaleOptions, type UsageEvent, type UsageModality, type UsageUnit, type VideoCallJob, type VideoCallOptions, type VideoJob, type VideoModel, type VideoRequest, type VideoResolution, type VideoResult, type Warning, aiSdkTextAdapter, arkAdapter, aspectRatioToSize, classifyHttpError, compareCatalogOrder, createDefaultModelKit, createModelKit, describe, describeThrown, generateImage as experimental_generateImage, falAdapter, fileCatalogCache, generateAudio, generateImage, generateObject, generateText, generateVideo, googleGenaiAdapter, googleImageAdapter, hasAwsCredentials, higgsfieldAdapter, isListed, isListedOn, isModelKitError, keysFromEnv, languageModel, liveCatalog, liveState, mergeTextProviderOptions, nearestAspectRatio, normalizeExposure, openaiImageAdapter, passthroughTextModel, pollUntil, prepareMediaPart, primeCatalog, prodiaAdapter, readErrorBody, replicateAdapter, resetLiveCatalog, resolveAudioOptions, resolveImageOptions, resolveKeys, resolveVideoOptions, shouldRetry, sleep, sortCatalogRows, streamObject, streamText, textUsageEvent, toGeneratedImage, withRetry, xaiVideoAdapter };
package/dist/index.js CHANGED
@@ -1,6 +1,14 @@
1
1
  // src/index.ts
2
2
  export * from "ai";
3
3
 
4
+ // src/types.ts
5
+ function hasAwsCredentials(aws) {
6
+ if (!aws || !aws.region) return false;
7
+ if (aws.apiKey) return true;
8
+ if (aws.credentialProvider) return true;
9
+ return Boolean(aws.accessKeyId && aws.secretAccessKey);
10
+ }
11
+
4
12
  // src/errors.ts
5
13
  var ModelKitError = class extends Error {
6
14
  code;
@@ -2037,7 +2045,18 @@ var CatalogModelSchemaBase = z.looseObject({
2037
2045
  });
2038
2046
  }
2039
2047
  });
2040
- var CatalogModelSchema = CatalogModelSchemaBase;
2048
+ var CatalogModelSchema = CatalogModelSchemaBase.superRefine(
2049
+ (row, ctx) => {
2050
+ const transport = row.providerOptions?.["modelkit"]?.["transport"];
2051
+ if (transport !== void 0 && transport !== "direct" && transport !== "bedrock") {
2052
+ ctx.addIssue({
2053
+ code: "custom",
2054
+ path: ["providerOptions", "modelkit", "transport"],
2055
+ message: 'transport must be "direct" or "bedrock"'
2056
+ });
2057
+ }
2058
+ }
2059
+ );
2041
2060
  var CatalogSchema = z.array(CatalogModelSchemaBase).superRefine((rows, ctx) => {
2042
2061
  const seenIds = /* @__PURE__ */ new Map();
2043
2062
  rows.forEach((row, index) => {
@@ -2642,9 +2661,12 @@ var ADAPTER_KEYS = {
2642
2661
  function hasAll(keys, names) {
2643
2662
  if (!keys) return false;
2644
2663
  return names.every(
2645
- (n) => Boolean(keys[n]) && (n !== "higgsfield" || Boolean(keys.higgsfieldSecret))
2664
+ (n) => n === "aws" ? hasAwsCredentials(keys.aws) : Boolean(keys[n]) && (n !== "higgsfield" || Boolean(keys.higgsfieldSecret))
2646
2665
  );
2647
2666
  }
2667
+ function hasKey(keys, name) {
2668
+ return hasAll(keys, [name]);
2669
+ }
2648
2670
  function missingEnterpriseKeys(config, names) {
2649
2671
  return names.filter((name) => !hasAll(config.keys.enterprise, [name]));
2650
2672
  }
@@ -2681,6 +2703,22 @@ function keysFromEnv(env, prefix = "") {
2681
2703
  set("higgsfield", pick("HIGGSFIELD_API_KEY"));
2682
2704
  set("higgsfieldSecret", pick("HIGGSFIELD_API_SECRET"));
2683
2705
  set("cloudflare", pick("CLOUDFLARE_AI_GATEWAY_TOKEN", "CF_AIG_TOKEN"));
2706
+ const bearer = pick("AWS_BEARER_TOKEN_BEDROCK");
2707
+ const accessKeyId = pick("AWS_ACCESS_KEY_ID");
2708
+ const secretAccessKey = pick("AWS_SECRET_ACCESS_KEY");
2709
+ if (bearer || accessKeyId && secretAccessKey) {
2710
+ const aws = {
2711
+ region: env[`${prefix}BEDROCK_REGION`] || "us-east-1"
2712
+ };
2713
+ if (accessKeyId && secretAccessKey) {
2714
+ aws.accessKeyId = accessKeyId;
2715
+ aws.secretAccessKey = secretAccessKey;
2716
+ }
2717
+ const sessionToken = pick("AWS_SESSION_TOKEN");
2718
+ if (sessionToken) aws.sessionToken = sessionToken;
2719
+ if (bearer) aws.apiKey = bearer;
2720
+ keys.aws = aws;
2721
+ }
2684
2722
  return keys;
2685
2723
  }
2686
2724
 
@@ -3016,6 +3054,7 @@ function toGeneratedImage(image) {
3016
3054
  }
3017
3055
 
3018
3056
  // src/adapters/ai-sdk-text.ts
3057
+ import { createBedrockAnthropic } from "@ai-sdk/amazon-bedrock/anthropic";
3019
3058
  import { createAnthropic } from "@ai-sdk/anthropic";
3020
3059
  import { createGoogleGenerativeAI } from "@ai-sdk/google";
3021
3060
  import { createOpenAI } from "@ai-sdk/openai";
@@ -3067,16 +3106,47 @@ function detectTextProvider(modelId) {
3067
3106
  message: `ai-sdk-text cannot detect a provider for "${modelId}". Set providerOptions.provider to one of ${TEXT_PROVIDERS.join(", ")}.`
3068
3107
  });
3069
3108
  }
3070
- function textKeyName(model, _routing) {
3071
- return textProviderOf(model);
3109
+ function textKeyName(model, transport) {
3110
+ const provider = textProviderOf(model);
3111
+ return provider === "anthropic" && transport === "bedrock" ? "aws" : provider;
3072
3112
  }
3073
3113
  function textProviderOf(model) {
3074
3114
  const explicit = model.providerOptions?.["modelkit"]?.["provider"];
3075
3115
  return isTextProvider(explicit) ? explicit : detectTextProvider(model.providerModelId);
3076
3116
  }
3077
- function textUsesCloudflareGateway(model, routing) {
3117
+ function textUsesCloudflareGateway(model, routing, transport) {
3078
3118
  if (routing.text !== "cloudflare") return false;
3079
- return GATEWAY_SLUGS[textProviderOf(model)] !== void 0;
3119
+ const provider = textProviderOf(model);
3120
+ if (provider === "anthropic" && transport === "bedrock") return false;
3121
+ return GATEWAY_SLUGS[provider] !== void 0;
3122
+ }
3123
+ var BEDROCK_DATED_MODEL_IDS = {
3124
+ "claude-haiku-4-5": "anthropic.claude-haiku-4-5-20251001-v1:0",
3125
+ "claude-haiku-4-5-20251001": "anthropic.claude-haiku-4-5-20251001-v1:0",
3126
+ "claude-sonnet-4-5": "anthropic.claude-sonnet-4-5-20250929-v1:0",
3127
+ "claude-sonnet-4-5-20250929": "anthropic.claude-sonnet-4-5-20250929-v1:0"
3128
+ };
3129
+ var BEDROCK_PROFILE_PREFIXES = ["us.", "global.", "eu.", "jp.", "au.", "apac."];
3130
+ function toBedrockModelId(model, routing) {
3131
+ const profile = routing.bedrockProfile ?? "us";
3132
+ const override = model.providerOptions?.["modelkit"]?.["bedrockModelId"];
3133
+ if (typeof override === "string" && override.length > 0) {
3134
+ if (BEDROCK_PROFILE_PREFIXES.some((prefix) => override.startsWith(prefix))) return override;
3135
+ if (override.startsWith("anthropic.")) return `${profile}.${override}`;
3136
+ return override;
3137
+ }
3138
+ const id = model.providerModelId;
3139
+ if (BEDROCK_PROFILE_PREFIXES.some((prefix) => id.startsWith(prefix))) return id;
3140
+ const dated = BEDROCK_DATED_MODEL_IDS[id];
3141
+ if (dated) return `${profile}.${dated}`;
3142
+ if (id.startsWith("claude-")) return `${profile}.anthropic.${id}`;
3143
+ throw new ModelKitError({
3144
+ code: "unsupported_option",
3145
+ message: `No Bedrock model id for "${id}". Set providerOptions.modelkit.bedrockModelId on the catalog row.`,
3146
+ provider: "ai-sdk-text",
3147
+ model: model.id,
3148
+ retryable: false
3149
+ });
3080
3150
  }
3081
3151
  function nativeClientFor(provider) {
3082
3152
  switch (provider) {
@@ -3101,14 +3171,14 @@ function nativeClientFor(provider) {
3101
3171
  function resolveTextRoute(ctx) {
3102
3172
  const provider = textProviderOf(ctx.model);
3103
3173
  const mode = ctx.routing.text ?? "direct";
3104
- if (provider === "anthropic" && ctx.routing.anthropic === "bedrock") {
3105
- throw new ModelKitError({
3106
- code: "unsupported_option",
3107
- message: "ai-sdk-text has no Bedrock transport (@ai-sdk/amazon-bedrock is not installed). Pass the Bedrock model through catalogOverride with providerOptions.bedrockModel and resolve it outside the SDK.",
3108
- provider: "ai-sdk-text",
3109
- model: ctx.model.id,
3110
- retryable: false
3111
- });
3174
+ if (provider === "anthropic" && ctx.anthropicTransport === "bedrock") {
3175
+ return {
3176
+ provider,
3177
+ client: "bedrock-anthropic",
3178
+ modelId: toBedrockModelId(ctx.model, ctx.routing),
3179
+ keyName: "aws",
3180
+ canonicalModelId: ctx.model.id
3181
+ };
3112
3182
  }
3113
3183
  const compatBase = OPENAI_COMPATIBLE_BASE_URLS[provider];
3114
3184
  const route2 = {
@@ -3152,6 +3222,70 @@ function missingKey(ctx, name) {
3152
3222
  retryable: false
3153
3223
  });
3154
3224
  }
3225
+ function bedrockMiddleware(ctx, canonicalModelId) {
3226
+ let warned = false;
3227
+ return {
3228
+ specificationVersion: "v3",
3229
+ transformParams: async ({ params }) => {
3230
+ const anthropic = params.providerOptions?.["anthropic"];
3231
+ if (typeof anthropic !== "object" || anthropic === null || !("cacheControl" in anthropic))
3232
+ return params;
3233
+ if (!warned) {
3234
+ warned = true;
3235
+ ctx.logger.warn(
3236
+ `[modelkit] ${canonicalModelId} drops call-level providerOptions.anthropic.cacheControl: not supported on Bedrock, use message-level cacheControl`
3237
+ );
3238
+ }
3239
+ const { cacheControl: _dropped, ...rest } = anthropic;
3240
+ return {
3241
+ ...params,
3242
+ providerOptions: { ...params.providerOptions, anthropic: rest }
3243
+ };
3244
+ },
3245
+ // Bedrock echoes its own id for dated models (anthropic.claude-haiku-4-5-20251001-v1:0),
3246
+ // and consumers bill on response.modelId.
3247
+ wrapGenerate: async ({ doGenerate }) => {
3248
+ const result = await doGenerate();
3249
+ if (!result.response) return result;
3250
+ return { ...result, response: { ...result.response, modelId: canonicalModelId } };
3251
+ },
3252
+ wrapStream: async ({ doStream }) => {
3253
+ const result = await doStream();
3254
+ return {
3255
+ ...result,
3256
+ stream: result.stream.pipeThrough(
3257
+ new TransformStream({
3258
+ transform(part, controller) {
3259
+ controller.enqueue(
3260
+ part.type === "response-metadata" && part.modelId !== void 0 ? { ...part, modelId: canonicalModelId } : part
3261
+ );
3262
+ }
3263
+ })
3264
+ )
3265
+ };
3266
+ }
3267
+ };
3268
+ }
3269
+ function bedrockLanguageModel(ctx, route2) {
3270
+ const aws = ctx.keys.aws;
3271
+ if (!hasAwsCredentials(aws)) throw missingKey(ctx, "aws");
3272
+ const canonical = route2.canonicalModelId ?? ctx.model.id;
3273
+ const inner = createBedrockAnthropic({
3274
+ region: aws.region,
3275
+ fetch: ctx.fetch,
3276
+ ...aws.apiKey ? { apiKey: aws.apiKey } : aws.credentialProvider ? { credentialProvider: aws.credentialProvider } : aws.accessKeyId !== void 0 && aws.secretAccessKey !== void 0 ? {
3277
+ accessKeyId: aws.accessKeyId,
3278
+ secretAccessKey: aws.secretAccessKey,
3279
+ ...aws.sessionToken !== void 0 ? { sessionToken: aws.sessionToken } : {}
3280
+ } : {}
3281
+ })(route2.modelId);
3282
+ return wrapLanguageModel({
3283
+ model: inner,
3284
+ middleware: bedrockMiddleware(ctx, canonical),
3285
+ modelId: canonical,
3286
+ providerId: "anthropic.messages"
3287
+ });
3288
+ }
3155
3289
  function minimaxDefaults(params) {
3156
3290
  return params.responseFormat?.type === "json" ? { reasoning_split: true, thinking: { type: "disabled" } } : { reasoning_split: true };
3157
3291
  }
@@ -3190,8 +3324,11 @@ var aiSdkTextAdapter = {
3190
3324
  id: "ai-sdk-text",
3191
3325
  languageModel(ctx) {
3192
3326
  const route2 = resolveTextRoute(ctx);
3193
- const apiKey = ctx.keys[route2.keyName];
3194
- if (!apiKey) throw missingKey(ctx, route2.keyName);
3327
+ if (route2.client === "bedrock-anthropic") return bedrockLanguageModel(ctx, route2);
3328
+ const { keyName } = route2;
3329
+ if (keyName === "aws") throw missingKey(ctx, keyName);
3330
+ const apiKey = ctx.keys[keyName];
3331
+ if (!apiKey) throw missingKey(ctx, keyName);
3195
3332
  const settings = { apiKey, fetch: ctx.fetch };
3196
3333
  if (route2.baseURL !== void 0) settings.baseURL = route2.baseURL;
3197
3334
  if (route2.headers !== void 0) settings.headers = route2.headers;
@@ -3230,14 +3367,47 @@ var aiSdkTextAdapter = {
3230
3367
  }
3231
3368
  };
3232
3369
 
3370
+ // src/anthropic-transport.ts
3371
+ var ANTHROPIC_TRANSPORTS = ["direct", "bedrock"];
3372
+ function isAnthropicTransport(value) {
3373
+ return ANTHROPIC_TRANSPORTS.some((transport) => transport === value);
3374
+ }
3375
+ function preferredAnthropicTransport(model, routing) {
3376
+ const row = model.providerOptions?.["modelkit"]?.["transport"];
3377
+ if (isAnthropicTransport(row)) return row;
3378
+ return routing.anthropic ?? "direct";
3379
+ }
3380
+ function resolveAnthropicTransport(model, config, tier, warn) {
3381
+ if (model.adapter !== "ai-sdk-text" || textProviderOf(model) !== "anthropic") return void 0;
3382
+ const rowValue = model.providerOptions?.["modelkit"]?.["transport"];
3383
+ if (rowValue !== void 0 && !isAnthropicTransport(rowValue))
3384
+ warn(
3385
+ `[modelkit] ${model.id} has an unknown providerOptions.modelkit.transport "${String(rowValue)}"; ignoring it`
3386
+ );
3387
+ const preferred = preferredAnthropicTransport(model, config.routing ?? {});
3388
+ const usable = (transport) => {
3389
+ const name = transport === "bedrock" ? "aws" : "anthropic";
3390
+ return hasKey(config.keys.pro, name) || tier === "enterprise" && hasKey(config.keys.enterprise, name);
3391
+ };
3392
+ if (usable(preferred)) return preferred;
3393
+ const other = preferred === "bedrock" ? "direct" : "bedrock";
3394
+ if (!usable(other)) return preferred;
3395
+ warn(`[modelkit] ${model.id}: no credentials for the ${preferred} transport; using ${other}`);
3396
+ return other;
3397
+ }
3398
+ var BEDROCK_USAGE_PROVIDER = "bedrock";
3399
+ function textUsageProvider(model, transport) {
3400
+ return transport === "bedrock" ? BEDROCK_USAGE_PROVIDER : textProviderOf(model);
3401
+ }
3402
+
3233
3403
  // src/client.ts
3234
- function requiredKeys(model, config) {
3404
+ function requiredKeys(model, config, transport) {
3235
3405
  if (model.adapter === "fal" && config.routing?.fal === "cloudflare-passthrough")
3236
3406
  return ["cloudflare"];
3237
3407
  if (model.adapter === "ai-sdk-text") {
3238
3408
  const routing = config.routing ?? {};
3239
- const names = [textKeyName(model, routing)];
3240
- if (textUsesCloudflareGateway(model, routing)) names.push("cloudflare");
3409
+ const names = [textKeyName(model, transport)];
3410
+ if (textUsesCloudflareGateway(model, routing, transport)) names.push("cloudflare");
3241
3411
  return names;
3242
3412
  }
3243
3413
  return ADAPTER_KEYS[model.adapter];
@@ -3324,6 +3494,12 @@ function createModelKit(config, adapters) {
3324
3494
  const catalog = config.catalogOverride ? liveCatalog.withOverrides(config.catalogOverride) : liveCatalog;
3325
3495
  const logger = config.logger ?? console;
3326
3496
  const fetchImpl = config.fetch ?? globalThis.fetch;
3497
+ const transportWarnings = /* @__PURE__ */ new Set();
3498
+ function warnOnce(message) {
3499
+ if (transportWarnings.has(message)) return;
3500
+ transportWarnings.add(message);
3501
+ logger.warn(message);
3502
+ }
3327
3503
  function context(model, call, warnings) {
3328
3504
  const adapter = adapters[model.adapter];
3329
3505
  if (!adapter)
@@ -3332,7 +3508,8 @@ function createModelKit(config, adapters) {
3332
3508
  message: `No adapter registered for ${model.adapter}`,
3333
3509
  model: model.id
3334
3510
  });
3335
- const names = requiredKeys(model, config);
3511
+ const transport = resolveAnthropicTransport(model, config, call.tier, warnOnce);
3512
+ const names = requiredKeys(model, config, transport);
3336
3513
  if (call.tier === "enterprise") {
3337
3514
  const missing = missingEnterpriseKeys(config, names);
3338
3515
  if (missing.length > 0)
@@ -3351,6 +3528,7 @@ function createModelKit(config, adapters) {
3351
3528
  call,
3352
3529
  warnings
3353
3530
  };
3531
+ if (transport) ctx.anthropicTransport = transport;
3354
3532
  if (config.endpoints) ctx.endpoints = config.endpoints;
3355
3533
  if (call.signal) ctx.signal = call.signal;
3356
3534
  return { adapter, ctx };
@@ -3391,7 +3569,7 @@ function createModelKit(config, adapters) {
3391
3569
  return {
3392
3570
  entry,
3393
3571
  languageModel: adapter.languageModel(ctx),
3394
- provider: textProviderOf(entry)
3572
+ provider: textUsageProvider(entry, ctx.anthropicTransport)
3395
3573
  };
3396
3574
  }
3397
3575
  async function passthroughImage(req, call) {
@@ -3685,12 +3863,12 @@ function createModelKit(config, adapters) {
3685
3863
  async prepareMediaPart(modelId, ref, mediaType, call = {}) {
3686
3864
  const model = catalog.require(modelId);
3687
3865
  const { adapter, ctx } = context(model, call, []);
3688
- const fileStore = model.adapter === "ai-sdk-text" && textKeyName(model, config.routing ?? {}) === "google" ? adapters["google-genai"] : adapter;
3866
+ const fileStore = model.adapter === "ai-sdk-text" && textKeyName(model) === "google" ? adapters["google-genai"] : adapter;
3689
3867
  if (fileStore?.prepareMediaPart) return fileStore.prepareMediaPart(ref, mediaType, ctx);
3690
3868
  return "url" in ref ? { type: "file", data: ref.url, mediaType } : { type: "file", data: ref.bytes, mediaType };
3691
3869
  },
3692
3870
  languageModel(modelId, call = {}) {
3693
- const { entry, languageModel: model } = textTarget(modelId, call);
3871
+ const { entry, languageModel: model, provider } = textTarget(modelId, call);
3694
3872
  if (model.specificationVersion !== "v3")
3695
3873
  throw new ModelKitError({
3696
3874
  code: "unsupported_option",
@@ -3700,9 +3878,18 @@ function createModelKit(config, adapters) {
3700
3878
  return {
3701
3879
  model,
3702
3880
  providerOptions: withoutModelkit(entry.providerOptions),
3703
- catalog: entry
3881
+ catalog: entry,
3882
+ usageProvider: provider
3704
3883
  };
3705
3884
  },
3885
+ usageProvider(modelId, call = {}) {
3886
+ const entry = catalog.require(modelId);
3887
+ if (entry.type !== "text") return entry.adapter;
3888
+ return textUsageProvider(
3889
+ entry,
3890
+ resolveAnthropicTransport(entry, config, call.tier, warnOnce)
3891
+ );
3892
+ },
3706
3893
  async generateText(options, call = {}) {
3707
3894
  const target = textTarget(options.model, call);
3708
3895
  const steps = createTextSteps(
@@ -7478,6 +7665,7 @@ export {
7478
7665
  generateVideo,
7479
7666
  googleGenaiAdapter,
7480
7667
  googleImageAdapter,
7668
+ hasAwsCredentials,
7481
7669
  higgsfieldAdapter,
7482
7670
  isListed,
7483
7671
  isListedOn,