@@ -245,6 +245,19 @@ export class BedrockRuntimeServiceExtension implements ServiceExtension {
245245 if ( requestBody . top_p !== undefined ) {
246246 spanAttributes [ AwsSpanProcessingUtil . GEN_AI_REQUEST_TOP_P ] = requestBody . top_p ;
247247 }
248+ } else if ( modelId . includes ( 'cohere.command-r' ) ) {
249+ if ( requestBody . max_tokens !== undefined ) {
250+ spanAttributes [ AwsSpanProcessingUtil . GEN_AI_REQUEST_MAX_TOKENS ] = requestBody . max_tokens ;
251+ }
252+ if ( requestBody . temperature !== undefined ) {
253+ spanAttributes [ AwsSpanProcessingUtil . GEN_AI_REQUEST_TEMPERATURE ] = requestBody . temperature ;
254+ }
255+ if ( requestBody . p !== undefined ) {
256+ spanAttributes [ AwsSpanProcessingUtil . GEN_AI_REQUEST_TOP_P ] = requestBody . p ;
257+ }
258+ if ( requestBody . message !== undefined ) {
259+ spanAttributes [ AwsSpanProcessingUtil . GEN_AI_USAGE_INPUT_TOKENS ] = Math . ceil ( requestBody . message . length / 6 ) ;
260+ }
248261 } else if ( modelId . includes ( 'cohere.command' ) ) {
249262 if ( requestBody . max_tokens !== undefined ) {
250263 spanAttributes [ AwsSpanProcessingUtil . GEN_AI_REQUEST_MAX_TOKENS ] = requestBody . max_tokens ;
@@ -255,6 +268,9 @@ export class BedrockRuntimeServiceExtension implements ServiceExtension {
255268 if ( requestBody . p !== undefined ) {
256269 spanAttributes [ AwsSpanProcessingUtil . GEN_AI_REQUEST_TOP_P ] = requestBody . p ;
257270 }
271+ if ( requestBody . prompt !== undefined ) {
272+ spanAttributes [ AwsSpanProcessingUtil . GEN_AI_USAGE_INPUT_TOKENS ] = Math . ceil ( requestBody . prompt . length / 6 ) ;
273+ }
258274 } else if ( modelId . includes ( 'ai21.jamba' ) ) {
259275 if ( requestBody . max_tokens !== undefined ) {
260276 spanAttributes [ AwsSpanProcessingUtil . GEN_AI_REQUEST_MAX_TOKENS ] = requestBody . max_tokens ;
@@ -329,13 +345,18 @@ export class BedrockRuntimeServiceExtension implements ServiceExtension {
329345 if ( responseBody . stop_reason !== undefined ) {
330346 span . setAttribute ( AwsSpanProcessingUtil . GEN_AI_RESPONSE_FINISH_REASONS , [ responseBody . stop_reason ] ) ;
331347 }
332- } else if ( currentModelId . includes ( 'cohere.command' ) ) {
333- if ( responseBody . prompt !== undefined ) {
348+ } else if ( currentModelId . includes ( 'cohere.command-r' ) ) {
349+ console . log ( 'Response Body:' , responseBody ) ;
350+ if ( responseBody . text !== undefined ) {
334351 // NOTE: We approximate the token count since this value is not directly available in the body
335352 // According to Bedrock docs they use (total_chars / 6) to approximate token count for pricing.
336353 // https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html
337- span . setAttribute ( AwsSpanProcessingUtil . GEN_AI_USAGE_INPUT_TOKENS , Math . ceil ( responseBody . prompt . length / 6 ) ) ;
354+ span . setAttribute ( AwsSpanProcessingUtil . GEN_AI_USAGE_OUTPUT_TOKENS , Math . ceil ( responseBody . text . length / 6 ) ) ;
338355 }
356+ if ( responseBody . finish_reason !== undefined ) {
357+ span . setAttribute ( AwsSpanProcessingUtil . GEN_AI_RESPONSE_FINISH_REASONS , [ responseBody . finish_reason ] ) ;
358+ }
359+ } else if ( currentModelId . includes ( 'cohere.command' ) ) {
339360 if ( responseBody . generations ?. [ 0 ] ?. text !== undefined ) {
340361 span . setAttribute (
341362 AwsSpanProcessingUtil . GEN_AI_USAGE_OUTPUT_TOKENS ,
0 commit comments