@anyway-sh/node-server-sdk 0.22.9 → 0.22.11

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.mjs CHANGED
@@ -66,7 +66,7 @@ class PromptNotFoundError extends TraceloopError {
66
66
  }
67
67
  }
68
68
 
69
- var version = "0.22.9";
69
+ var version = "0.22.11";
70
70
 
71
71
  /**
72
72
  * Base class for handling annotation operations with the Traceloop API.
@@ -3238,6 +3238,10 @@ function parseKeyPairsIntoRecord(keyPairs) {
3238
3238
  }
3239
3239
 
3240
3240
  const ALL_INSTRUMENTATION_LIBRARIES = "all";
3241
+ let _pricingCalculator = null;
3242
+ const setPricingCalculator = (calculator) => {
3243
+ _pricingCalculator = calculator;
3244
+ };
3241
3245
  const spanAgentNames = new Map();
3242
3246
  const SPAN_AGENT_NAME_TTL = 5 * 60 * 1000;
3243
3247
  const AI_TELEMETRY_METADATA_AGENT = "ai.telemetry.metadata.agent";
@@ -3387,13 +3391,9 @@ const ensureSpanCompatibility = (span) => {
3387
3391
  const onSpanEnd = (originalOnEnd, instrumentationLibraries) => {
3388
3392
  return (span) => {
3389
3393
  var _a, _b, _c;
3390
- const libName = ((_a = span.instrumentationScope) === null || _a === void 0 ? void 0 : _a.name) ||
3391
- ((_b = span.instrumentationLibrary) === null || _b === void 0 ? void 0 : _b.name) ||
3392
- "unknown";
3393
- console.log(`[Anyway Debug] onSpanEnd: span="${span.name}" lib="${libName}"`);
3394
3394
  if (instrumentationLibraries &&
3395
- !instrumentationLibraries.includes(libName)) {
3396
- console.log(`[Anyway Debug] Dropping span="${span.name}" - lib="${libName}" not in allowed list`);
3395
+ !instrumentationLibraries.includes(((_a = span.instrumentationScope) === null || _a === void 0 ? void 0 : _a.name) ||
3396
+ ((_b = span.instrumentationLibrary) === null || _b === void 0 ? void 0 : _b.name))) {
3397
3397
  return;
3398
3398
  }
3399
3399
  transformAiSdkSpanAttributes(span);
@@ -3419,8 +3419,10 @@ const onSpanEnd = (originalOnEnd, instrumentationLibraries) => {
3419
3419
  if (Math.random() < 0.01) {
3420
3420
  cleanupExpiredSpanAgentNames();
3421
3421
  }
3422
+ if (_pricingCalculator) {
3423
+ _pricingCalculator.addCostAttributes(span);
3424
+ }
3422
3425
  const compatibleSpan = ensureSpanCompatibility(span);
3423
- console.log(`[Anyway Debug] Span queued for export: "${span.name}" lib="${libName}"`);
3424
3426
  originalOnEnd(compatibleSpan);
3425
3427
  };
3426
3428
  };
@@ -3706,19 +3708,6 @@ const startTracing = (options) => {
3706
3708
  url: `${baseUrl}/v1/traces`,
3707
3709
  headers,
3708
3710
  }));
3709
- // [Anyway Debug] Wrap exporter to log outgoing calls
3710
- const origExport = traceExporter.export.bind(traceExporter);
3711
- traceExporter.export = (spans, resultCallback) => {
3712
- var _a, _b;
3713
- console.log(`[Anyway Debug] Exporting ${spans.length} span(s) to ${baseUrl}/v1/traces`);
3714
- for (const s of spans) {
3715
- console.log(`[Anyway Debug] - ${s.name} (${((_a = s.instrumentationLibrary) === null || _a === void 0 ? void 0 : _a.name) || ((_b = s.instrumentationScope) === null || _b === void 0 ? void 0 : _b.name) || "unknown"})`);
3716
- }
3717
- return origExport(spans, (result) => {
3718
- console.log(`[Anyway Debug] Export result: code=${result.code}${result.error ? ` error=${result.error.message}` : ""}`);
3719
- resultCallback(result);
3720
- });
3721
- };
3722
3711
  _spanProcessor = createSpanProcessor({
3723
3712
  apiKey: options.apiKey,
3724
3713
  baseUrl: options.baseUrl,
@@ -3856,6 +3845,674 @@ const initializeRegistry = (options) => {
3856
3845
  });
3857
3846
  };
3858
3847
 
3848
+ const DATE_SUFFIX_PATTERN = /-\d{4}-\d{2}-\d{2}$/;
3849
+ const DATE_COMPACT_SUFFIX_PATTERN = /-\d{8}$/;
3850
+ class PricingCalculator {
3851
+ constructor(pricingData) {
3852
+ var _a;
3853
+ this.chatModels = (_a = pricingData.chat) !== null && _a !== void 0 ? _a : {};
3854
+ }
3855
+ findPricing(modelName) {
3856
+ if (!modelName)
3857
+ return null;
3858
+ const models = this.chatModels;
3859
+ // 1. Exact match
3860
+ if (models[modelName]) {
3861
+ return this.normalize(models[modelName]);
3862
+ }
3863
+ // 2. Strip date suffix and retry
3864
+ let stripped = modelName.replace(DATE_SUFFIX_PATTERN, "");
3865
+ stripped = stripped.replace(DATE_COMPACT_SUFFIX_PATTERN, "");
3866
+ if (stripped !== modelName && models[stripped]) {
3867
+ return this.normalize(models[stripped]);
3868
+ }
3869
+ // 3. Prefix match (longest wins)
3870
+ let bestMatch = null;
3871
+ let bestLen = 0;
3872
+ for (const baseModel of Object.keys(models)) {
3873
+ if (modelName.startsWith(baseModel) && baseModel.length > bestLen) {
3874
+ bestMatch = baseModel;
3875
+ bestLen = baseModel.length;
3876
+ }
3877
+ }
3878
+ if (bestMatch) {
3879
+ return this.normalize(models[bestMatch]);
3880
+ }
3881
+ return null;
3882
+ }
3883
+ addCostAttributes(span) {
3884
+ const attrs = span.attributes;
3885
+ if (!attrs)
3886
+ return;
3887
+ const model = attrs[ATTR_GEN_AI_RESPONSE_MODEL] ||
3888
+ attrs[ATTR_GEN_AI_REQUEST_MODEL];
3889
+ if (!model)
3890
+ return;
3891
+ const inputTokens = attrs[ATTR_GEN_AI_USAGE_INPUT_TOKENS];
3892
+ const outputTokens = attrs[ATTR_GEN_AI_USAGE_OUTPUT_TOKENS];
3893
+ if (inputTokens == null && outputTokens == null)
3894
+ return;
3895
+ const pricing = this.findPricing(model);
3896
+ if (!pricing)
3897
+ return;
3898
+ const inputCost = (inputTokens !== null && inputTokens !== void 0 ? inputTokens : 0) * pricing.inputCostPerToken;
3899
+ const outputCost = (outputTokens !== null && outputTokens !== void 0 ? outputTokens : 0) * pricing.outputCostPerToken;
3900
+ span.attributes["gen_ai.usage.input_cost"] = inputCost;
3901
+ span.attributes["gen_ai.usage.output_cost"] = outputCost;
3902
+ span.attributes["gen_ai.usage.cost"] = inputCost + outputCost;
3903
+ }
3904
+ normalize(pricing) {
3905
+ var _a, _b;
3906
+ return {
3907
+ inputCostPerToken: ((_a = pricing.promptPrice) !== null && _a !== void 0 ? _a : 0) / 1000,
3908
+ outputCostPerToken: ((_b = pricing.completionPrice) !== null && _b !== void 0 ? _b : 0) / 1000,
3909
+ };
3910
+ }
3911
+ }
3912
+
3913
+ var embeddings = {
3914
+ "text-embedding-ada-002": 0.0001,
3915
+ "text-embedding-3-small": 0.00002,
3916
+ "text-embedding-3-large": 0.00013,
3917
+ ada: 0.0001,
3918
+ "ada-v2": 0.0001,
3919
+ "text-ada-001": 0.0001,
3920
+ "azure_text-embedding-ada-002": 0.0001,
3921
+ "azure_text-embedding-3-small": 0.00002,
3922
+ "azure_text-embedding-3-large": 0.00013,
3923
+ azure_ada: 0.0001,
3924
+ "azure_ada-v2": 0.0001,
3925
+ "azure_text-ada-001": 0.0001,
3926
+ "embed-english-v3.0": 0.0001,
3927
+ "embed-multilingual-v3.0": 0.0001,
3928
+ "embed-english-light-v3.0": 0.0001,
3929
+ "embed-multilingual-light-v3.0": 0.0001,
3930
+ "embed-english-v2.0": 0.0001,
3931
+ "embed-english-light-v2.0": 0.0001,
3932
+ "embed-multilingual-v2.0": 0.0001,
3933
+ "mistral-embed": 0.0001,
3934
+ "amazon.titan-embed-text-v1": 0.0001,
3935
+ "amazon.titan-embed-text-v2": 0.00002,
3936
+ "textembedding-gecko": 0.0001,
3937
+ "textembedding-gecko@001": 0.0001,
3938
+ "textembedding-gecko@002": 0.0001,
3939
+ "textembedding-gecko@003": 0.0001
3940
+ };
3941
+ var images = {
3942
+ "dall-e-3": {
3943
+ standard: {
3944
+ "1024x1024": 0.04,
3945
+ "1024x1792": 0.02,
3946
+ "1792x1024": 0.08
3947
+ },
3948
+ hd: {
3949
+ "1024x1024": 0.08,
3950
+ "1024x1792": 0.12,
3951
+ "1792x1024": 0.12
3952
+ }
3953
+ },
3954
+ "azure_dall-e-3": {
3955
+ standard: {
3956
+ "1024x1024": 0.04,
3957
+ "1024x1792": 0.02,
3958
+ "1792x1024": 0.08
3959
+ },
3960
+ hd: {
3961
+ "1024x1024": 0.08,
3962
+ "1024x1792": 0.12,
3963
+ "1792x1024": 0.12
3964
+ }
3965
+ },
3966
+ "dall-e-2": {
3967
+ standard: {
3968
+ "1024x1024": 0.02,
3969
+ "512x512": 0.018,
3970
+ "256x256": 0.016
3971
+ }
3972
+ },
3973
+ "black-forest-labs/FLUX.1-dev": {
3974
+ standard: {
3975
+ "1000000": 0.025
3976
+ }
3977
+ },
3978
+ "black-forest-labs/FLUX.1-canny": {
3979
+ standard: {
3980
+ "1000000": 0.025
3981
+ }
3982
+ },
3983
+ "black-forest-labs/FLUX.1-depth": {
3984
+ standard: {
3985
+ "1000000": 0.025
3986
+ }
3987
+ },
3988
+ "black-forest-labs/FLUX.1-redux": {
3989
+ standard: {
3990
+ "1000000": 0.025
3991
+ }
3992
+ },
3993
+ "black-forest-labs/FLUX.1-schnell": {
3994
+ standard: {
3995
+ "1000000": 0.0027
3996
+ }
3997
+ },
3998
+ "black-forest-labs/FLUX.1-pro": {
3999
+ standard: {
4000
+ "1000000": 0.04
4001
+ }
4002
+ },
4003
+ "black-forest-labs/FLUX.1.1-pro": {
4004
+ standard: {
4005
+ "1000000": 0.05
4006
+ }
4007
+ },
4008
+ "stabilityai/stable-diffusion-xl-base-1.0": {
4009
+ standard: {
4010
+ "512X512": 0.001,
4011
+ "1024x1024": 0.01
4012
+ }
4013
+ },
4014
+ "amazon.titan-image-generator-v1": {
4015
+ standard: {
4016
+ "512x512": 0.008,
4017
+ "1024x1024": 0.01
4018
+ },
4019
+ premium: {
4020
+ "512x512": 0.01,
4021
+ "1024x1024": 0.012
4022
+ }
4023
+ }
4024
+ };
4025
+ var audio = {
4026
+ "tts-1": 0.015,
4027
+ "tts-1-hd": 0.03,
4028
+ eleven_multilingual_v2: 0.24,
4029
+ eleven_multilingual_v1: 0.24,
4030
+ eleven_monolingual_v1: 0.24,
4031
+ eleven_english_v1: 0.24,
4032
+ eleven_turbo_v2: 0.24,
4033
+ eleven_english_sts_v2: 0.24,
4034
+ eleven_multilingual_sts_v2: 0.24,
4035
+ best: 0.00010277777,
4036
+ nano: 0.00003333333
4037
+ };
4038
+ var chat = {
4039
+ "gpt-4.1-nano-2025-04-14": {
4040
+ promptPrice: 0.0001,
4041
+ completionPrice: 0.0004
4042
+ },
4043
+ "gpt-4.1-nano": {
4044
+ promptPrice: 0.0001,
4045
+ completionPrice: 0.0004
4046
+ },
4047
+ "gpt-4.1-mini-2025-04-14": {
4048
+ promptPrice: 0.0004,
4049
+ completionPrice: 0.0016
4050
+ },
4051
+ "gpt-4.1-mini": {
4052
+ promptPrice: 0.0004,
4053
+ completionPrice: 0.0016
4054
+ },
4055
+ "gpt-4.1-2025-04-14": {
4056
+ promptPrice: 0.002,
4057
+ completionPrice: 0.008
4058
+ },
4059
+ "gpt-4.1": {
4060
+ promptPrice: 0.002,
4061
+ completionPrice: 0.008
4062
+ },
4063
+ "gpt-4o": {
4064
+ promptPrice: 0.0005,
4065
+ completionPrice: 0.0015
4066
+ },
4067
+ "gpt-4o-2024-08-06": {
4068
+ promptPrice: 0.0025,
4069
+ completionPrice: 0.01
4070
+ },
4071
+ "gpt-4o-2024-05-13": {
4072
+ promptPrice: 0.005,
4073
+ completionPrice: 0.015
4074
+ },
4075
+ "gpt-4o-mini": {
4076
+ promptPrice: 0.00015,
4077
+ completionPrice: 0.0006
4078
+ },
4079
+ "gpt-4o-mini-2024-07-18": {
4080
+ promptPrice: 0.00015,
4081
+ completionPrice: 0.0006
4082
+ },
4083
+ "o1-mini": {
4084
+ promptPrice: 0.003,
4085
+ completionPrice: 0.012
4086
+ },
4087
+ "o1-mini-2024-09-12": {
4088
+ promptPrice: 0.003,
4089
+ completionPrice: 0.012
4090
+ },
4091
+ "o1-preview": {
4092
+ promptPrice: 0.015,
4093
+ completionPrice: 0.06
4094
+ },
4095
+ "o1-preview-2024-09-12": {
4096
+ promptPrice: 0.015,
4097
+ completionPrice: 0.06
4098
+ },
4099
+ "gpt-3.5-turbo": {
4100
+ promptPrice: 0.0005,
4101
+ completionPrice: 0.0015
4102
+ },
4103
+ "gpt-3.5-turbo-0125": {
4104
+ promptPrice: 0.0005,
4105
+ completionPrice: 0.0015
4106
+ },
4107
+ "azure_gpt-35-turbo": {
4108
+ promptPrice: 0.0005,
4109
+ completionPrice: 0.0015
4110
+ },
4111
+ "azure_gpt-35-turbo-16k": {
4112
+ promptPrice: 0.0005,
4113
+ completionPrice: 0.0015
4114
+ },
4115
+ "azure_gpt-35-turbo-instruct": {
4116
+ promptPrice: 0.0015,
4117
+ completionPrice: 0.002
4118
+ },
4119
+ "gpt-4": {
4120
+ promptPrice: 0.03,
4121
+ completionPrice: 0.06
4122
+ },
4123
+ "gpt-4-turbo": {
4124
+ promptPrice: 0.01,
4125
+ completionPrice: 0.03
4126
+ },
4127
+ "gpt-4-32k": {
4128
+ promptPrice: 0.06,
4129
+ completionPrice: 0.12
4130
+ },
4131
+ "gpt-4-1106-preview": {
4132
+ promptPrice: 0.01,
4133
+ completionPrice: 0.03
4134
+ },
4135
+ "gpt-4-0125-preview": {
4136
+ promptPrice: 0.01,
4137
+ completionPrice: 0.03
4138
+ },
4139
+ "gpt-4-preview": {
4140
+ promptPrice: 0.01,
4141
+ completionPrice: 0.03
4142
+ },
4143
+ "gpt-4-1106-vision-preview": {
4144
+ promptPrice: 0.01,
4145
+ completionPrice: 0.03
4146
+ },
4147
+ "gpt-4-vision-preview": {
4148
+ promptPrice: 0.01,
4149
+ completionPrice: 0.03
4150
+ },
4151
+ "azure_gpt-4": {
4152
+ promptPrice: 0.03,
4153
+ completionPrice: 0.06
4154
+ },
4155
+ "azure_gpt-4-32k": {
4156
+ promptPrice: 0.06,
4157
+ completionPrice: 0.12
4158
+ },
4159
+ "claude-3-opus-20240229": {
4160
+ promptPrice: 0.015,
4161
+ completionPrice: 0.075
4162
+ },
4163
+ "claude-3-sonnet-20240229": {
4164
+ promptPrice: 0.003,
4165
+ completionPrice: 0.015
4166
+ },
4167
+ "claude-3-haiku-20240307": {
4168
+ promptPrice: 0.00025,
4169
+ completionPrice: 0.00125
4170
+ },
4171
+ command: {
4172
+ promptPrice: 0.001,
4173
+ completionPrice: 0.002
4174
+ },
4175
+ "command-nightly": {
4176
+ promptPrice: 0.001,
4177
+ completionPrice: 0.002
4178
+ },
4179
+ "command-light": {
4180
+ promptPrice: 0.0003,
4181
+ completionPrice: 0.0006
4182
+ },
4183
+ "command-light-nightly": {
4184
+ promptPrice: 0.0003,
4185
+ completionPrice: 0.0006
4186
+ },
4187
+ "open-mistral-7b": {
4188
+ promptPrice: 0.00025,
4189
+ completionPrice: 0.00025
4190
+ },
4191
+ "open-mixtral-8x7b": {
4192
+ promptPrice: 0.0007,
4193
+ completionPrice: 0.0007
4194
+ },
4195
+ "mistral-small-latest": {
4196
+ promptPrice: 0.002,
4197
+ completionPrice: 0.006
4198
+ },
4199
+ "mistral-medium-latest": {
4200
+ promptPrice: 0.0027,
4201
+ completionPrice: 0.0081
4202
+ },
4203
+ "mistral-large-latest": {
4204
+ promptPrice: 0.008,
4205
+ completionPrice: 0.024
4206
+ },
4207
+ "amazon.titan-text-express-v1": {
4208
+ promptPrice: 0.0008,
4209
+ completionPrice: 0.0016
4210
+ },
4211
+ "amazon.titan-text-lite-v1": {
4212
+ promptPrice: 0.0003,
4213
+ completionPrice: 0.0004
4214
+ },
4215
+ "mistral.mistral-7b-instruct-v0:2": {
4216
+ promptPrice: 0.00015,
4217
+ completionPrice: 0.0002
4218
+ },
4219
+ "mistral.mixtral-8x7b-instruct-v0:1": {
4220
+ promptPrice: 0.00045,
4221
+ completionPrice: 0.0007
4222
+ },
4223
+ "mistral.mistral-large-2402-v1:0": {
4224
+ promptPrice: 0.008,
4225
+ completionPrice: 0.024
4226
+ },
4227
+ "anthropic.claude-3-haiku-20240307-v1:0": {
4228
+ promptPrice: 0.00025,
4229
+ completionPrice: 0.00125
4230
+ },
4231
+ "anthropic.claude-v2": {
4232
+ promptPrice: 0.008,
4233
+ completionPrice: 0.024
4234
+ },
4235
+ "anthropic.claude-3-sonnet-20240229-v1:0": {
4236
+ promptPrice: 0.003,
4237
+ completionPrice: 0.015
4238
+ },
4239
+ "anthropic.claude-3-opus-20240229-v1:0": {
4240
+ promptPrice: 0.015,
4241
+ completionPrice: 0.075
4242
+ },
4243
+ "meta.llama3-8b-instruct-v1:0": {
4244
+ promptPrice: 0.0004,
4245
+ completionPrice: 0.0006
4246
+ },
4247
+ "meta.llama3-70b-instruct-v1:0": {
4248
+ promptPrice: 0.00265,
4249
+ completionPrice: 0.0035
4250
+ },
4251
+ "meta.llama2-13b-chat-v1": {
4252
+ promptPrice: 0.00075,
4253
+ completionPrice: 0.001
4254
+ },
4255
+ "meta.llama2-70b-chat-v1": {
4256
+ promptPrice: 0.00195,
4257
+ completionPrice: 0.00256
4258
+ },
4259
+ "cohere.command-text-v14": {
4260
+ promptPrice: 0.0015,
4261
+ completionPrice: 0.002
4262
+ },
4263
+ "cohere.command-light-text-v14": {
4264
+ promptPrice: 0.0003,
4265
+ completionPrice: 0.0006
4266
+ },
4267
+ "ai21.j2-mid-v1": {
4268
+ promptPrice: 0.0125,
4269
+ completionPrice: 0.0125
4270
+ },
4271
+ "ai21.j2-ultra-v1": {
4272
+ promptPrice: 0.0188,
4273
+ completionPrice: 0.0188
4274
+ },
4275
+ "gemini-1.0-pro": {
4276
+ promptPrice: 0.0005,
4277
+ completionPrice: 0.0015
4278
+ },
4279
+ "gemini-1.5-flash": {
4280
+ promptPrice: 0.000075,
4281
+ completionPrice: 0.0003
4282
+ },
4283
+ "gemini-1.5-pro": {
4284
+ promptPrice: 0.00125,
4285
+ completionPrice: 0.005
4286
+ },
4287
+ "gemini-1.0-pro-002": {
4288
+ promptPrice: 0.0005,
4289
+ completionPrice: 0.0015
4290
+ },
4291
+ "gemini-1.0-pro-001": {
4292
+ promptPrice: 0.0005,
4293
+ completionPrice: 0.0015
4294
+ },
4295
+ "gemini-1.5-pro-preview-0409": {
4296
+ promptPrice: 0.005,
4297
+ completionPrice: 0.015
4298
+ },
4299
+ "gemini-1.5-pro-preview-0514": {
4300
+ promptPrice: 0.005,
4301
+ completionPrice: 0.015
4302
+ },
4303
+ "gemini-1.5-flash-preview-0514": {
4304
+ promptPrice: 0.0005,
4305
+ completionPrice: 0.0015
4306
+ },
4307
+ "gemini-2.0-flash": {
4308
+ promptPrice: 0.0001,
4309
+ completionPrice: 0.0004
4310
+ },
4311
+ "gemini-2.0-flash-lite": {
4312
+ promptPrice: 0.000075,
4313
+ completionPrice: 0.0003
4314
+ },
4315
+ "gemini-2.5-flash": {
4316
+ promptPrice: 0.0003,
4317
+ completionPrice: 0.0025
4318
+ },
4319
+ "gemini-2.5-flash-preview": {
4320
+ promptPrice: 0.0003,
4321
+ completionPrice: 0.0025
4322
+ },
4323
+ "gemini-2.5-flash-lite": {
4324
+ promptPrice: 0.0001,
4325
+ completionPrice: 0.0004
4326
+ },
4327
+ "gemini-2.5-flash-lite-preview": {
4328
+ promptPrice: 0.0001,
4329
+ completionPrice: 0.0004
4330
+ },
4331
+ "gemini-2.5-pro": {
4332
+ promptPrice: 0.00125,
4333
+ completionPrice: 0.01
4334
+ },
4335
+ "text-bison": {
4336
+ promptPrice: 0.001,
4337
+ completionPrice: 0.002
4338
+ },
4339
+ "text-bison@002": {
4340
+ promptPrice: 0.001,
4341
+ completionPrice: 0.002
4342
+ },
4343
+ "text-bison-32k": {
4344
+ promptPrice: 0.001,
4345
+ completionPrice: 0.002
4346
+ },
4347
+ "text-bison-32k@002": {
4348
+ promptPrice: 0.001,
4349
+ completionPrice: 0.002
4350
+ },
4351
+ "text-unicorn": {
4352
+ promptPrice: 0.01,
4353
+ completionPrice: 0.03
4354
+ },
4355
+ "text-unicorn@001": {
4356
+ promptPrice: 0.01,
4357
+ completionPrice: 0.03
4358
+ },
4359
+ "chat-bison": {
4360
+ promptPrice: 0.001,
4361
+ completionPrice: 0.002
4362
+ },
4363
+ "chat-bison@002": {
4364
+ promptPrice: 0.001,
4365
+ completionPrice: 0.002
4366
+ },
4367
+ "chat-bison-32k": {
4368
+ promptPrice: 0.001,
4369
+ completionPrice: 0.002
4370
+ },
4371
+ "chat-bison-32k@002": {
4372
+ promptPrice: 0.001,
4373
+ completionPrice: 0.002
4374
+ },
4375
+ "llama3-8b-8192": {
4376
+ promptPrice: 0.00005,
4377
+ completionPrice: 0.0001
4378
+ },
4379
+ "llama3-70b-8192": {
4380
+ promptPrice: 0.00059,
4381
+ completionPrice: 0.00079
4382
+ },
4383
+ "mixtral-8x7b-32768": {
4384
+ promptPrice: 0.00024,
4385
+ completionPrice: 0.00024
4386
+ },
4387
+ "gemma-7b-it": {
4388
+ promptPrice: 0.0001,
4389
+ completionPrice: 0.0001
4390
+ },
4391
+ "reka-core": {
4392
+ promptPrice: 0.002,
4393
+ completionPrice: 0.002
4394
+ },
4395
+ "reka-core-20240415": {
4396
+ promptPrice: 0.002,
4397
+ completionPrice: 0.002
4398
+ },
4399
+ "reka-core-20240501": {
4400
+ promptPrice: 0.002,
4401
+ completionPrice: 0.002
4402
+ },
4403
+ "reka-flash": {
4404
+ promptPrice: 0.0002,
4405
+ completionPrice: 0.0008
4406
+ },
4407
+ "reka-flash-20240226": {
4408
+ promptPrice: 0.0002,
4409
+ completionPrice: 0.0008
4410
+ },
4411
+ "reka-edge": {
4412
+ promptPrice: 0.0001,
4413
+ completionPrice: 0.0001
4414
+ },
4415
+ "reka-edge-20240208": {
4416
+ promptPrice: 0.0001,
4417
+ completionPrice: 0.0001
4418
+ },
4419
+ "reka-spark": {
4420
+ promptPrice: 0.00005,
4421
+ completionPrice: 0.00005
4422
+ },
4423
+ "grok-beta": {
4424
+ promptPrice: 0.0005,
4425
+ completionPrice: 0.0015
4426
+ },
4427
+ "grok-vision-beta": {
4428
+ promptPrice: 0.0005,
4429
+ completionPrice: 0.0015
4430
+ },
4431
+ "jamba-1.5-mini": {
4432
+ promptPrice: 0.0002,
4433
+ completionPrice: 0.0004
4434
+ },
4435
+ "jamba-1.5-large": {
4436
+ promptPrice: 0.002,
4437
+ completionPrice: 0.008
4438
+ },
4439
+ "meta-llama/Llama-3.3-70B-Instruct-Turbo": {
4440
+ promptPrice: 0.00088,
4441
+ completionPrice: 0.00088
4442
+ },
4443
+ "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo-vLLM-json": {
4444
+ promptPrice: 0.00088,
4445
+ completionPrice: 0.00088
4446
+ },
4447
+ "meta-llama/Meta-Llama-3.1-405B-Instruct-Lite-Pro-lora": {
4448
+ promptPrice: 0.00088,
4449
+ completionPrice: 0.00088
4450
+ },
4451
+ "meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo": {
4452
+ promptPrice: 0.00088,
4453
+ completionPrice: 0.00088
4454
+ },
4455
+ "Qwen/QwQ-32B-Preview": {
4456
+ promptPrice: 0.0012,
4457
+ completionPrice: 0.0012
4458
+ },
4459
+ "codellama/CodeLlama-34b-Instruct-hf": {
4460
+ promptPrice: 0.0008,
4461
+ completionPrice: 0.0008
4462
+ },
4463
+ "databricks/dbrx-instruct": {
4464
+ promptPrice: 0.0012,
4465
+ completionPrice: 0.0012
4466
+ },
4467
+ "deepseek-ai/deepseek-llm-67b-chat": {
4468
+ promptPrice: 0.0009,
4469
+ completionPrice: 0.0009
4470
+ },
4471
+ "google/gemma-2b-it": {
4472
+ promptPrice: 0.0001,
4473
+ completionPrice: 0.0001
4474
+ },
4475
+ "google/gemma-2-27b-it": {
4476
+ promptPrice: 0.0008,
4477
+ completionPrice: 0.0008
4478
+ },
4479
+ "google/gemma-2-9b-it": {
4480
+ promptPrice: 0.0003,
4481
+ completionPrice: 0.0003
4482
+ },
4483
+ "Gryphe/MythoMax-L2-13b-Lite": {
4484
+ promptPrice: 0.0003,
4485
+ completionPrice: 0.0003
4486
+ },
4487
+ "nvidia/Llama-3.1-Nemotron-70B-Instruct-HF": {
4488
+ promptPrice: 0.0088,
4489
+ completionPrice: 0.0088
4490
+ },
4491
+ "deepseek-chat": {
4492
+ promptPrice: 0.00014,
4493
+ completionPrice: 0.00028
4494
+ },
4495
+ "deepseek-reasoner": {
4496
+ promptPrice: 0.00055,
4497
+ completionPrice: 0.00219
4498
+ }
4499
+ };
4500
+ var defaultPricing = {
4501
+ embeddings: embeddings,
4502
+ images: images,
4503
+ audio: audio,
4504
+ chat: chat
4505
+ };
4506
+
4507
+ function loadPricing(pricingJsonPath) {
4508
+ if (pricingJsonPath) {
4509
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
4510
+ const fs = require("fs");
4511
+ return JSON.parse(fs.readFileSync(pricingJsonPath, "utf-8"));
4512
+ }
4513
+ return defaultPricing;
4514
+ }
4515
+
3859
4516
  let _configuration;
3860
4517
  let _client;
3861
4518
  /**
@@ -3918,15 +4575,21 @@ const initialize = (options = {}) => {
3918
4575
  if (!options.silenceInitializationMessage) {
3919
4576
  console.log(`Traceloop exporting traces to ${_configuration.exporter ? "a custom exporter" : _configuration.baseUrl}`);
3920
4577
  }
3921
- console.log(`[Anyway Debug] Trace endpoint: ${_configuration.baseUrl}/v1/traces`);
3922
- console.log(`[Anyway Debug] API key present: ${!!_configuration.apiKey}`);
3923
- console.log(`[Anyway Debug] Using custom exporter: ${!!_configuration.exporter}`);
3924
4578
  if (options.tracingEnabled === undefined || options.tracingEnabled) {
3925
4579
  if (options.logLevel) {
3926
4580
  diag.setLogger(new DiagConsoleLogger(), logLevelToOtelLogLevel(options.logLevel));
3927
4581
  }
3928
4582
  startTracing(_configuration);
3929
4583
  }
4584
+ if (options.pricingEnabled !== false) {
4585
+ try {
4586
+ const pricingData = loadPricing(options.pricingJsonPath);
4587
+ setPricingCalculator(new PricingCalculator(pricingData));
4588
+ }
4589
+ catch (e) {
4590
+ console.warn(`[Traceloop] Failed to initialize pricing: ${e.message}`);
4591
+ }
4592
+ }
3930
4593
  initializeRegistry(_configuration);
3931
4594
  if (options.apiKey) {
3932
4595
  _client = new TraceloopClient({
@@ -4399,5 +5062,5 @@ var AssociationProperty;
4399
5062
  AssociationProperty["SESSION_ID"] = "session_id";
4400
5063
  })(AssociationProperty || (AssociationProperty = {}));
4401
5064
 
4402
- export { ALL_INSTRUMENTATION_LIBRARIES, ArgumentNotProvidedError, AssociationProperty, Attachment, AttachmentReference, AttachmentUploader, Column, Dataset, Datasets, Evaluator, EvaluatorMadeByTraceloop, Experiment, ExternalAttachment, ImageUploader, InitializationError, LLMSpan, NotInitializedError, PromptNotFoundError, Row, SEVERITY, TraceloopClient, TraceloopError, VectorSpan, agent, attachment, conversation, createEvaluator, createSpanProcessor, forceFlush, getAvailableEvaluatorSlugs, getClient, getEvaluatorSchemaInfo, getPrompt, getTraceloopTracer, initialize, isAnyAttachment, isAttachment, isAttachmentReference, isExternalAttachment, reportCustomMetric, task, tool, traceloopInstrumentationLibraries, validateEvaluatorInput, waitForInitialization, withAgent, withAssociationProperties, withConversation, withLLMCall, withTask, withTool, withVectorDBCall, withWorkflow, workflow };
5065
+ export { ALL_INSTRUMENTATION_LIBRARIES, ArgumentNotProvidedError, AssociationProperty, Attachment, AttachmentReference, AttachmentUploader, Column, Dataset, Datasets, Evaluator, EvaluatorMadeByTraceloop, Experiment, ExternalAttachment, ImageUploader, InitializationError, LLMSpan, NotInitializedError, PromptNotFoundError, Row, SEVERITY, TraceloopClient, TraceloopError, VectorSpan, agent, attachment, conversation, createEvaluator, createSpanProcessor, forceFlush, getAvailableEvaluatorSlugs, getClient, getEvaluatorSchemaInfo, getPrompt, getTraceloopTracer, initialize, isAnyAttachment, isAttachment, isAttachmentReference, isExternalAttachment, reportCustomMetric, setPricingCalculator, task, tool, traceloopInstrumentationLibraries, validateEvaluatorInput, waitForInitialization, withAgent, withAssociationProperties, withConversation, withLLMCall, withTask, withTool, withVectorDBCall, withWorkflow, workflow };
4403
5066
  //# sourceMappingURL=index.mjs.map