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