Semantic Conventions for Generative AI Metrics

Status: Experimental

Generative AI Client Metrics

The conventions described in this section are specific to Generative AI client applications.

Disclaimer: These are initial Generative AI client metric instruments and attributes but more may be added in the future.

The following metric instruments describe Generative AI operations. An operation may be a request to an LLM, a function call, or some other distinct action within a larger Generative AI workflow.

Individual systems may include additional system-specific attributes. It is recommended to check system-specific documentation, if available.

Metric: gen_ai.client.token.usage

This metric is recommended when an operation involves the usage of tokens and the count is readily available.

For example, if GenAI system returns usage information in the streaming response, it SHOULD be used. Or if GenAI system returns each token independently, instrumentation SHOULD count number of output tokens and record the result.

If instrumentation cannot efficiently obtain number of input and/or output tokens, it MAY allow users to enable offline token counting. Otherwise it MUST NOT report usage metric.

When systems report both used tokens and billable tokens, instrumentation MUST report billable tokens.

This metric SHOULD be specified with ExplicitBucketBoundaries of [1, 4, 16, 64, 256, 1024, 4096, 16384, 65536, 262144, 1048576, 4194304, 16777216, 67108864].

NameInstrument TypeUnit (UCUM)DescriptionStability
gen_ai.client.token.usageHistogram{token}Measures number of input and output tokens usedExperimental
AttributeTypeDescriptionExamplesRequirement LevelStability
gen_ai.operation.namestringThe name of the operation being performed. [1]chat; text_completion; embeddingsRequiredExperimental
gen_ai.systemstringThe Generative AI product as identified by the client or server instrumentation. [2]openaiRequiredExperimental
gen_ai.token.typestringThe type of token being counted.input; outputRequiredExperimental
gen_ai.request.modelstringThe name of the GenAI model a request is being made to.gpt-4Conditionally Required If available.Experimental
server.portintGenAI server port. [3]80; 8080; 443Conditionally Required If server.address is set.Stable
gen_ai.response.modelstringThe name of the model that generated the response.gpt-4-0613RecommendedExperimental
server.addressstringGenAI server address. [4]example.com; 10.1.2.80; /tmp/my.sockRecommendedStable

[1] gen_ai.operation.name: If one of the predefined values applies, but specific system uses a different name it’s RECOMMENDED to document it in the semantic conventions for specific GenAI system and use system-specific name in the instrumentation. If a different name is not documented, instrumentation libraries SHOULD use applicable predefined value.

[2] gen_ai.system: The gen_ai.system describes a family of GenAI models with specific model identified by gen_ai.request.model and gen_ai.response.model attributes.

The actual GenAI product may differ from the one identified by the client. For example, when using OpenAI client libraries to communicate with Mistral, the gen_ai.system is set to openai based on the instrumentation’s best knowledge.

For custom model, a custom friendly name SHOULD be used. If none of these options apply, the gen_ai.system SHOULD be set to _OTHER.

[3] server.port: When observed from the client side, and when communicating through an intermediary, server.port SHOULD represent the server port behind any intermediaries, for example proxies, if it’s available.

[4] server.address: When observed from the client side, and when communicating through an intermediary, server.address SHOULD represent the server address behind any intermediaries, for example proxies, if it’s available.


gen_ai.operation.name has the following list of well-known values. If one of them applies, then the respective value MUST be used; otherwise, a custom value MAY be used.

ValueDescriptionStability
chatChat completion operation such as OpenAI Chat APIExperimental
embeddingsEmbeddings operation such as OpenAI Create embeddings APIExperimental
text_completionText completions operation such as OpenAI Completions API (Legacy)Experimental

gen_ai.system has the following list of well-known values. If one of them applies, then the respective value MUST be used; otherwise, a custom value MAY be used.

ValueDescriptionStability
anthropicAnthropicExperimental
aws.bedrockAWS BedrockExperimental
az.ai.inferenceAzure AI InferenceExperimental
cohereCohereExperimental
ibm.watsonx.aiIBM Watsonx AIExperimental
openaiOpenAIExperimental
vertex_aiVertex AIExperimental

gen_ai.token.type has the following list of well-known values. If one of them applies, then the respective value MUST be used; otherwise, a custom value MAY be used.

ValueDescriptionStability
inputInput tokens (prompt, input, etc.)Experimental
outputOutput tokens (completion, response, etc.)Experimental

Metric: gen_ai.client.operation.duration

This metric is required.

This metric SHOULD be specified with ExplicitBucketBoundaries of [0.01, 0.02, 0.04, 0.08, 0.16, 0.32, 0.64, 1.28, 2.56, 5.12, 10.24, 20.48, 40.96, 81.92].

NameInstrument TypeUnit (UCUM)DescriptionStability
gen_ai.client.operation.durationHistogramsGenAI operation durationExperimental
AttributeTypeDescriptionExamplesRequirement LevelStability
gen_ai.operation.namestringThe name of the operation being performed. [1]chat; text_completion; embeddingsRequiredExperimental
gen_ai.systemstringThe Generative AI product as identified by the client or server instrumentation. [2]openaiRequiredExperimental
error.typestringDescribes a class of error the operation ended with. [3]timeout; java.net.UnknownHostException; server_certificate_invalid; 500Conditionally Required if the operation ended in an errorStable
gen_ai.request.modelstringThe name of the GenAI model a request is being made to.gpt-4Conditionally Required If available.Experimental
server.portintGenAI server port. [4]80; 8080; 443Conditionally Required If server.address is set.Stable
gen_ai.response.modelstringThe name of the model that generated the response.gpt-4-0613RecommendedExperimental
server.addressstringGenAI server address. [5]example.com; 10.1.2.80; /tmp/my.sockRecommendedStable

[1] gen_ai.operation.name: If one of the predefined values applies, but specific system uses a different name it’s RECOMMENDED to document it in the semantic conventions for specific GenAI system and use system-specific name in the instrumentation. If a different name is not documented, instrumentation libraries SHOULD use applicable predefined value.

[2] gen_ai.system: The gen_ai.system describes a family of GenAI models with specific model identified by gen_ai.request.model and gen_ai.response.model attributes.

The actual GenAI product may differ from the one identified by the client. For example, when using OpenAI client libraries to communicate with Mistral, the gen_ai.system is set to openai based on the instrumentation’s best knowledge.

For custom model, a custom friendly name SHOULD be used. If none of these options apply, the gen_ai.system SHOULD be set to _OTHER.

[3] error.type: The error.type SHOULD match the error code returned by the Generative AI provider or the client library, the canonical name of exception that occurred, or another low-cardinality error identifier. Instrumentations SHOULD document the list of errors they report.

[4] server.port: When observed from the client side, and when communicating through an intermediary, server.port SHOULD represent the server port behind any intermediaries, for example proxies, if it’s available.

[5] server.address: When observed from the client side, and when communicating through an intermediary, server.address SHOULD represent the server address behind any intermediaries, for example proxies, if it’s available.


error.type has the following list of well-known values. If one of them applies, then the respective value MUST be used; otherwise, a custom value MAY be used.

ValueDescriptionStability
_OTHERA fallback error value to be used when the instrumentation doesn’t define a custom value.Stable

gen_ai.operation.name has the following list of well-known values. If one of them applies, then the respective value MUST be used; otherwise, a custom value MAY be used.

ValueDescriptionStability
chatChat completion operation such as OpenAI Chat APIExperimental
embeddingsEmbeddings operation such as OpenAI Create embeddings APIExperimental
text_completionText completions operation such as OpenAI Completions API (Legacy)Experimental

gen_ai.system has the following list of well-known values. If one of them applies, then the respective value MUST be used; otherwise, a custom value MAY be used.

ValueDescriptionStability
anthropicAnthropicExperimental
aws.bedrockAWS BedrockExperimental
az.ai.inferenceAzure AI InferenceExperimental
cohereCohereExperimental
ibm.watsonx.aiIBM Watsonx AIExperimental
openaiOpenAIExperimental
vertex_aiVertex AIExperimental

Generative AI Model Server Metrics

The following metric instruments describe Generative AI model servers' operational metrics. It includes both functional and performance metrics.

Metric: gen_ai.server.request.duration

This metric is recommended to report the model server latency in terms of time spent per request.

This metric SHOULD be specified with ExplicitBucketBoundaries of [0.01, 0.02, 0.04, 0.08, 0.16, 0.32, 0.64, 1.28, 2.56, 5.12, 10.24, 20.48, 40.96, 81.92].

NameInstrument TypeUnit (UCUM)DescriptionStability
gen_ai.server.request.durationHistogramsGenerative AI server request duration such as time-to-last byte or last output tokenExperimental
AttributeTypeDescriptionExamplesRequirement LevelStability
gen_ai.operation.namestringThe name of the operation being performed. [1]chat; text_completion; embeddingsRequiredExperimental
gen_ai.systemstringThe Generative AI product as identified by the client or server instrumentation. [2]openaiRequiredExperimental
error.typestringDescribes a class of error the operation ended with. [3]timeout; java.net.UnknownHostException; server_certificate_invalid; 500Conditionally Required if the operation ended in an errorStable
gen_ai.request.modelstringThe name of the GenAI model a request is being made to.gpt-4Conditionally Required If available.Experimental
server.portintGenAI server port. [4]80; 8080; 443Conditionally Required If server.address is set.Stable
gen_ai.response.modelstringThe name of the model that generated the response.gpt-4-0613RecommendedExperimental
server.addressstringGenAI server address. [5]example.com; 10.1.2.80; /tmp/my.sockRecommendedStable

[1] gen_ai.operation.name: If one of the predefined values applies, but specific system uses a different name it’s RECOMMENDED to document it in the semantic conventions for specific GenAI system and use system-specific name in the instrumentation. If a different name is not documented, instrumentation libraries SHOULD use applicable predefined value.

[2] gen_ai.system: The gen_ai.system describes a family of GenAI models with specific model identified by gen_ai.request.model and gen_ai.response.model attributes.

The actual GenAI product may differ from the one identified by the client. For example, when using OpenAI client libraries to communicate with Mistral, the gen_ai.system is set to openai based on the instrumentation’s best knowledge.

For custom model, a custom friendly name SHOULD be used. If none of these options apply, the gen_ai.system SHOULD be set to _OTHER.

[3] error.type: The error.type SHOULD match the error code returned by the Generative AI service, the canonical name of exception that occurred, or another low-cardinality error identifier. Instrumentations SHOULD document the list of errors they report.

[4] server.port: When observed from the client side, and when communicating through an intermediary, server.port SHOULD represent the server port behind any intermediaries, for example proxies, if it’s available.

[5] server.address: When observed from the client side, and when communicating through an intermediary, server.address SHOULD represent the server address behind any intermediaries, for example proxies, if it’s available.


error.type has the following list of well-known values. If one of them applies, then the respective value MUST be used; otherwise, a custom value MAY be used.

ValueDescriptionStability
_OTHERA fallback error value to be used when the instrumentation doesn’t define a custom value.Stable

gen_ai.operation.name has the following list of well-known values. If one of them applies, then the respective value MUST be used; otherwise, a custom value MAY be used.

ValueDescriptionStability
chatChat completion operation such as OpenAI Chat APIExperimental
embeddingsEmbeddings operation such as OpenAI Create embeddings APIExperimental
text_completionText completions operation such as OpenAI Completions API (Legacy)Experimental

gen_ai.system has the following list of well-known values. If one of them applies, then the respective value MUST be used; otherwise, a custom value MAY be used.

ValueDescriptionStability
anthropicAnthropicExperimental
aws.bedrockAWS BedrockExperimental
az.ai.inferenceAzure AI InferenceExperimental
cohereCohereExperimental
ibm.watsonx.aiIBM Watsonx AIExperimental
openaiOpenAIExperimental
vertex_aiVertex AIExperimental

Metric: gen_ai.server.time_per_output_token

This metric is recommended to report the model server latency in terms of time per token generated after the first token for any model servers which support serving LLMs. It is measured by subtracting the time taken to generate the first output token from the request duration and dividing the rest of the duration by the number of output tokens generated after the first token. This is important in measuring the performance of the decode phase of LLM inference.

This metric SHOULD be specified with ExplicitBucketBoundaries of [0.01, 0.025, 0.05, 0.075, 0.1, 0.15, 0.2, 0.3, 0.4, 0.5, 0.75, 1.0, 2.5].

NameInstrument TypeUnit (UCUM)DescriptionStability
gen_ai.server.time_per_output_tokenHistogramsTime per output token generated after the first token for successful responsesExperimental
AttributeTypeDescriptionExamplesRequirement LevelStability
gen_ai.operation.namestringThe name of the operation being performed. [1]chat; text_completion; embeddingsRequiredExperimental
gen_ai.systemstringThe Generative AI product as identified by the client or server instrumentation. [2]openaiRequiredExperimental
gen_ai.request.modelstringThe name of the GenAI model a request is being made to.gpt-4Conditionally Required If available.Experimental
server.portintGenAI server port. [3]80; 8080; 443Conditionally Required If server.address is set.Stable
gen_ai.response.modelstringThe name of the model that generated the response.gpt-4-0613RecommendedExperimental
server.addressstringGenAI server address. [4]example.com; 10.1.2.80; /tmp/my.sockRecommendedStable

[1] gen_ai.operation.name: If one of the predefined values applies, but specific system uses a different name it’s RECOMMENDED to document it in the semantic conventions for specific GenAI system and use system-specific name in the instrumentation. If a different name is not documented, instrumentation libraries SHOULD use applicable predefined value.

[2] gen_ai.system: The gen_ai.system describes a family of GenAI models with specific model identified by gen_ai.request.model and gen_ai.response.model attributes.

The actual GenAI product may differ from the one identified by the client. For example, when using OpenAI client libraries to communicate with Mistral, the gen_ai.system is set to openai based on the instrumentation’s best knowledge.

For custom model, a custom friendly name SHOULD be used. If none of these options apply, the gen_ai.system SHOULD be set to _OTHER.

[3] server.port: When observed from the client side, and when communicating through an intermediary, server.port SHOULD represent the server port behind any intermediaries, for example proxies, if it’s available.

[4] server.address: When observed from the client side, and when communicating through an intermediary, server.address SHOULD represent the server address behind any intermediaries, for example proxies, if it’s available.


gen_ai.operation.name has the following list of well-known values. If one of them applies, then the respective value MUST be used; otherwise, a custom value MAY be used.

ValueDescriptionStability
chatChat completion operation such as OpenAI Chat APIExperimental
embeddingsEmbeddings operation such as OpenAI Create embeddings APIExperimental
text_completionText completions operation such as OpenAI Completions API (Legacy)Experimental

gen_ai.system has the following list of well-known values. If one of them applies, then the respective value MUST be used; otherwise, a custom value MAY be used.

ValueDescriptionStability
anthropicAnthropicExperimental
aws.bedrockAWS BedrockExperimental
az.ai.inferenceAzure AI InferenceExperimental
cohereCohereExperimental
ibm.watsonx.aiIBM Watsonx AIExperimental
openaiOpenAIExperimental
vertex_aiVertex AIExperimental

Metric: gen_ai.server.time_to_first_token

This metric is recommended to report the model server latency in terms of time spent to generate the first token of the response for any model servers which support serving LLMs. It helps measure the time spent in the queue and the prefill phase. It is important especially for streaming requests. It is calculated at a request level and is reported as a histogram using the buckets mentioned below.

This metric SHOULD be specified with ExplicitBucketBoundaries of [0.001, 0.005, 0.01, 0.02, 0.04, 0.06, 0.08, 0.1, 0.25, 0.5, 0.75, 1.0, 2.5, 5.0, 7.5, 10.0].

NameInstrument TypeUnit (UCUM)DescriptionStability
gen_ai.server.time_to_first_tokenHistogramsTime to generate first token for successful responsesExperimental
AttributeTypeDescriptionExamplesRequirement LevelStability
gen_ai.operation.namestringThe name of the operation being performed. [1]chat; text_completion; embeddingsRequiredExperimental
gen_ai.systemstringThe Generative AI product as identified by the client or server instrumentation. [2]openaiRequiredExperimental
gen_ai.request.modelstringThe name of the GenAI model a request is being made to.gpt-4Conditionally Required If available.Experimental
server.portintGenAI server port. [3]80; 8080; 443Conditionally Required If server.address is set.Stable
gen_ai.response.modelstringThe name of the model that generated the response.gpt-4-0613RecommendedExperimental
server.addressstringGenAI server address. [4]example.com; 10.1.2.80; /tmp/my.sockRecommendedStable

[1] gen_ai.operation.name: If one of the predefined values applies, but specific system uses a different name it’s RECOMMENDED to document it in the semantic conventions for specific GenAI system and use system-specific name in the instrumentation. If a different name is not documented, instrumentation libraries SHOULD use applicable predefined value.

[2] gen_ai.system: The gen_ai.system describes a family of GenAI models with specific model identified by gen_ai.request.model and gen_ai.response.model attributes.

The actual GenAI product may differ from the one identified by the client. For example, when using OpenAI client libraries to communicate with Mistral, the gen_ai.system is set to openai based on the instrumentation’s best knowledge.

For custom model, a custom friendly name SHOULD be used. If none of these options apply, the gen_ai.system SHOULD be set to _OTHER.

[3] server.port: When observed from the client side, and when communicating through an intermediary, server.port SHOULD represent the server port behind any intermediaries, for example proxies, if it’s available.

[4] server.address: When observed from the client side, and when communicating through an intermediary, server.address SHOULD represent the server address behind any intermediaries, for example proxies, if it’s available.


gen_ai.operation.name has the following list of well-known values. If one of them applies, then the respective value MUST be used; otherwise, a custom value MAY be used.

ValueDescriptionStability
chatChat completion operation such as OpenAI Chat APIExperimental
embeddingsEmbeddings operation such as OpenAI Create embeddings APIExperimental
text_completionText completions operation such as OpenAI Completions API (Legacy)Experimental

gen_ai.system has the following list of well-known values. If one of them applies, then the respective value MUST be used; otherwise, a custom value MAY be used.

ValueDescriptionStability
anthropicAnthropicExperimental
aws.bedrockAWS BedrockExperimental
az.ai.inferenceAzure AI InferenceExperimental
cohereCohereExperimental
ibm.watsonx.aiIBM Watsonx AIExperimental
openaiOpenAIExperimental
vertex_aiVertex AIExperimental