From 988fa6ee1ad6d9dc8f6222a8f42327c70ee88cbe Mon Sep 17 00:00:00 2001 From: Teja Date: Sun, 1 Feb 2026 11:25:13 -0500 Subject: [PATCH 01/35] Add sync streaming support for Anthropic instrumentation - Add support for Messages.create(stream=True) with StreamWrapper - Add support for Messages.stream() with MessageStreamManagerWrapper - Add MessageWrapper for non-streaming response telemetry - Rename MessageCreateParams to MessageRequestParams - Add comprehensive tests for sync streaming functionality --- .../instrumentation/anthropic/__init__.py | 16 +- .../instrumentation/anthropic/patch.py | 77 ++++-- .../instrumentation/anthropic/utils.py | 240 ++++++++++++++++- .../test_sync_messages_create_api_error.yaml | 98 +++++++ .../test_sync_messages_create_basic.yaml | 137 ++++++++++ ...test_sync_messages_create_stop_reason.yaml | 137 ++++++++++ .../test_sync_messages_create_streaming.yaml | 136 ++++++++++ ...c_messages_create_streaming_iteration.yaml | 145 +++++++++++ ...test_sync_messages_create_token_usage.yaml | 137 ++++++++++ ..._sync_messages_create_with_all_params.yaml | 143 ++++++++++ .../test_sync_messages_stream_basic.yaml | 140 ++++++++++ ...test_sync_messages_stream_token_usage.yaml | 143 ++++++++++ ...test_sync_messages_stream_with_params.yaml | 152 +++++++++++ .../tests/test_sync_messages.py | 244 ++++++++++++++++++ 14 files changed, 1916 insertions(+), 29 deletions(-) create mode 100644 instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml create mode 100644 instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml create mode 100644 instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml create mode 100644 instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml create mode 100644 instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/__init__.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/__init__.py index bf76798462..197ad4e838 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/__init__.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/__init__.py @@ -54,7 +54,10 @@ ) from opentelemetry.instrumentation.anthropic.package import _instruments -from opentelemetry.instrumentation.anthropic.patch import messages_create +from opentelemetry.instrumentation.anthropic.patch import ( + messages_create, + messages_stream, +) from opentelemetry.instrumentation.instrumentor import BaseInstrumentor from opentelemetry.instrumentation.utils import unwrap from opentelemetry.util.genai.handler import TelemetryHandler @@ -103,6 +106,13 @@ def _instrument(self, **kwargs: Any) -> None: wrapper=messages_create(handler), ) + # Patch Messages.stream + wrap_function_wrapper( + module="anthropic.resources.messages", + name="Messages.stream", + wrapper=messages_stream(handler), + ) + def _uninstrument(self, **kwargs: Any) -> None: """Disable Anthropic instrumentation. @@ -114,3 +124,7 @@ def _uninstrument(self, **kwargs: Any) -> None: anthropic.resources.messages.Messages, # pyright: ignore[reportAttributeAccessIssue,reportUnknownMemberType,reportUnknownArgumentType] "create", ) + unwrap( + anthropic.resources.messages.Messages, # pyright: ignore[reportAttributeAccessIssue,reportUnknownMemberType,reportUnknownArgumentType] + "stream", + ) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py index 0562d638e2..52e435cdd7 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py @@ -14,35 +14,40 @@ """Patching functions for Anthropic instrumentation.""" -from typing import TYPE_CHECKING, Any, Callable +from typing import TYPE_CHECKING, Any, Callable, Union from opentelemetry.semconv._incubating.attributes import ( gen_ai_attributes as GenAIAttributes, ) from opentelemetry.util.genai.handler import TelemetryHandler -from opentelemetry.util.genai.types import LLMInvocation +from opentelemetry.util.genai.types import Error, LLMInvocation from .utils import ( + MessageStreamManagerWrapper, + MessageWrapper, + StreamWrapper, extract_params, get_llm_request_attributes, ) if TYPE_CHECKING: + from anthropic._streaming import Stream + from anthropic.lib.streaming import MessageStreamManager from anthropic.resources.messages import Messages - from anthropic.types import Message + from anthropic.types import Message, RawMessageStreamEvent def messages_create( handler: TelemetryHandler, -) -> Callable[..., "Message"]: +) -> Callable[..., Union["Message", "Stream[RawMessageStreamEvent]"]]: """Wrap the `create` method of the `Messages` class to trace it.""" def traced_method( - wrapped: Callable[..., "Message"], + wrapped: Callable[..., Union["Message", "Stream[RawMessageStreamEvent]"]], instance: "Messages", args: tuple[Any, ...], kwargs: dict[str, Any], - ) -> "Message": + ) -> Union["Message", StreamWrapper]: params = extract_params(*args, **kwargs) attributes = get_llm_request_attributes(params, instance) request_model = str( @@ -57,22 +62,60 @@ def traced_method( attributes=attributes, ) - with handler.llm(invocation) as invocation: + is_streaming = kwargs.get("stream", False) + + # Use manual lifecycle management for both streaming and non-streaming + handler.start_llm(invocation) + try: result = wrapped(*args, **kwargs) + if is_streaming: + return StreamWrapper(result, handler, invocation) + wrapper = MessageWrapper(result, handler, invocation) + return wrapper.message + except Exception as exc: + handler.fail_llm( + invocation, Error(message=str(exc), type=type(exc)) + ) + raise - if result.model: - invocation.response_model_name = result.model + return traced_method - if result.id: - invocation.response_id = result.id - if result.stop_reason: - invocation.finish_reasons = [result.stop_reason] +def messages_stream( + handler: TelemetryHandler, +) -> Callable[..., "MessageStreamManager"]: + """Wrap the `stream` method of the `Messages` class to trace it.""" - if result.usage: - invocation.input_tokens = result.usage.input_tokens - invocation.output_tokens = result.usage.output_tokens + def traced_method( + wrapped: Callable[..., "MessageStreamManager"], + instance: "Messages", + args: tuple[Any, ...], + kwargs: dict[str, Any], + ) -> MessageStreamManagerWrapper: + params = extract_params(*args, **kwargs) + attributes = get_llm_request_attributes(params, instance) + request_model = str( + attributes.get(GenAIAttributes.GEN_AI_REQUEST_MODEL) + or params.model + or "unknown" + ) + + invocation = LLMInvocation( + request_model=request_model, + provider="anthropic", + attributes=attributes, + ) - return result + # Start the span before calling the wrapped method + handler.start_llm(invocation) + try: + result = wrapped(*args, **kwargs) + # Return wrapped MessageStreamManager + return MessageStreamManagerWrapper(result, handler, invocation) + except Exception as exc: + handler.fail_llm( + invocation, Error(message=str(exc), type=type(exc)) + ) + raise return traced_method diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py index 4c2003f441..60b7a05cae 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py @@ -17,7 +17,7 @@ from __future__ import annotations from dataclasses import dataclass -from typing import TYPE_CHECKING, Any, Optional, Sequence +from typing import TYPE_CHECKING, Any, Iterator, Optional, Sequence from urllib.parse import urlparse from opentelemetry.semconv._incubating.attributes import ( @@ -26,26 +26,35 @@ from opentelemetry.semconv._incubating.attributes import ( server_attributes as ServerAttributes, ) +from opentelemetry.util.genai.handler import TelemetryHandler +from opentelemetry.util.genai.types import Error, LLMInvocation from opentelemetry.util.types import AttributeValue if TYPE_CHECKING: + from anthropic._streaming import Stream + from anthropic.lib.streaming import ( + MessageStream, + MessageStreamManager, + ) from anthropic.resources.messages import Messages + from anthropic.types import Message, RawMessageStreamEvent @dataclass -class MessageCreateParams: - """Parameters extracted from Messages.create() call.""" +class MessageRequestParams: + """Parameters extracted from Anthropic Messages API calls.""" model: str | None = None max_tokens: int | None = None temperature: float | None = None - top_p: float | None = None top_k: int | None = None + top_p: float | None = None stop_sequences: Sequence[str] | None = None # Use parameter signature from -# https://github.com/anthropics/anthropic-sdk-python/blob/9b5ab24ba17bcd5e762e5a5fd69bb3c17b100aaa/src/anthropic/resources/messages/messages.py#L92 +# https://github.com/anthropics/anthropic-sdk-python/blob/9b5ab24ba17bcd5e762e5a5fd69bb3c17b100aaa/src/anthropic/resources/messages/messages.py#L896 +# https://github.com/anthropics/anthropic-sdk-python/blob/9b5ab24ba17bcd5e762e5a5fd69bb3c17b100aaa/src/anthropic/resources/messages/messages.py#L963 # to handle named vs positional args robustly def extract_params( # pylint: disable=too-many-locals *, @@ -61,16 +70,16 @@ def extract_params( # pylint: disable=too-many-locals thinking: Any | None = None, tool_choice: Any | None = None, tools: Any | None = None, - top_p: float | None = None, top_k: int | None = None, + top_p: float | None = None, extra_headers: Any | None = None, extra_query: Any | None = None, extra_body: Any | None = None, timeout: Any | None = None, **_kwargs: Any, -) -> MessageCreateParams: - """Extract relevant parameters from Messages.create() arguments.""" - return MessageCreateParams( +) -> MessageRequestParams: + """Extract relevant parameters from Anthropic Messages API arguments.""" + return MessageRequestParams( model=model, max_tokens=max_tokens, temperature=temperature, @@ -104,9 +113,9 @@ def set_server_address_and_port( def get_llm_request_attributes( - params: MessageCreateParams, client_instance: "Messages" + params: MessageRequestParams, client_instance: "Messages" ) -> dict[str, AttributeValue]: - """Extract LLM request attributes from MessageCreateParams. + """Extract LLM request attributes from MessageRequestParams. Returns a dictionary of OpenTelemetry semantic convention attributes for LLM requests. The attributes follow the GenAI semantic conventions (gen_ai.*) and server semantic @@ -143,3 +152,212 @@ def get_llm_request_attributes( # Filter out None values return {k: v for k, v in attributes.items() if v is not None} + + +class MessageWrapper: + """Wrapper for non-streaming Message response that handles telemetry. + + This wrapper extracts telemetry data from the response and finalizes + the span immediately since the response is complete. + """ + + def __init__( + self, + message: "Message", + handler: TelemetryHandler, + invocation: LLMInvocation, + ): + self._message = message + self._extract_and_finalize(handler, invocation) + + def _extract_and_finalize( + self, handler: TelemetryHandler, invocation: LLMInvocation + ) -> None: + """Extract response data and finalize the span.""" + if self._message.model: + invocation.response_model_name = self._message.model + + if self._message.id: + invocation.response_id = self._message.id + + if self._message.stop_reason: + invocation.finish_reasons = [self._message.stop_reason] + + if self._message.usage: + invocation.input_tokens = self._message.usage.input_tokens + invocation.output_tokens = self._message.usage.output_tokens + + handler.stop_llm(invocation) + + @property + def message(self) -> "Message": + """Return the wrapped Message object.""" + return self._message + + +class StreamWrapper(Iterator["RawMessageStreamEvent"]): + """Wrapper for Anthropic Stream that handles telemetry. + + This wrapper wraps Stream[RawMessageStreamEvent] returned by + Messages.create(stream=True). It processes streaming chunks, + extracts telemetry data, and ensures the span is properly ended + when the stream is consumed. + """ + + def __init__( + self, + stream: "Stream[RawMessageStreamEvent]", + handler: TelemetryHandler, + invocation: LLMInvocation, + ): + self._stream = stream + self._handler = handler + self._invocation = invocation + self._response_id: Optional[str] = None + self._response_model: Optional[str] = None + self._stop_reason: Optional[str] = None + self._input_tokens: Optional[int] = None + self._output_tokens: Optional[int] = None + + def _process_chunk(self, chunk: "RawMessageStreamEvent") -> None: + """Extract telemetry data from a streaming chunk.""" + # Handle message_start event - contains initial message info + if chunk.type == "message_start": + message = getattr(chunk, "message", None) + if message: + if hasattr(message, "id") and message.id: + self._response_id = message.id + if hasattr(message, "model") and message.model: + self._response_model = message.model + # message_start also contains initial usage with input_tokens + if hasattr(message, "usage") and message.usage: + if hasattr(message.usage, "input_tokens"): + self._input_tokens = message.usage.input_tokens + + # Handle message_delta event - contains stop_reason and output token usage + elif chunk.type == "message_delta": + delta = getattr(chunk, "delta", None) + if delta and hasattr(delta, "stop_reason") and delta.stop_reason: + self._stop_reason = delta.stop_reason + # message_delta contains usage with output_tokens + usage = getattr(chunk, "usage", None) + if usage and hasattr(usage, "output_tokens"): + self._output_tokens = usage.output_tokens + + def _finalize_invocation(self) -> None: + """Update invocation with collected data and stop the span.""" + if self._response_model: + self._invocation.response_model_name = self._response_model + if self._response_id: + self._invocation.response_id = self._response_id + if self._stop_reason: + self._invocation.finish_reasons = [self._stop_reason] + if self._input_tokens is not None: + self._invocation.input_tokens = self._input_tokens + if self._output_tokens is not None: + self._invocation.output_tokens = self._output_tokens + + self._handler.stop_llm(self._invocation) + + def __iter__(self) -> "StreamWrapper": + return self + + def __next__(self) -> "RawMessageStreamEvent": + try: + chunk = next(self._stream) + self._process_chunk(chunk) + return chunk + except StopIteration: + self._finalize_invocation() + raise + except Exception as exc: + self._handler.fail_llm( + self._invocation, Error(message=str(exc), type=type(exc)) + ) + raise + + def __enter__(self) -> "StreamWrapper": + return self + + def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool: + self.close() + return False + + def close(self) -> None: + """Close the underlying stream and finalize telemetry.""" + if hasattr(self._stream, "close"): + self._stream.close() + self._finalize_invocation() + + +class MessageStreamManagerWrapper: + """Wrapper for MessageStreamManager that handles telemetry. + + This wrapper wraps the MessageStreamManager context manager returned by + Messages.stream(). It extracts telemetry data from the final message + when the context exits. + """ + + def __init__( + self, + stream_manager: "MessageStreamManager", + handler: TelemetryHandler, + invocation: LLMInvocation, + ): + self._stream_manager = stream_manager + self._handler = handler + self._invocation = invocation + self._message_stream: Optional["MessageStream"] = None + + def __enter__(self) -> "MessageStream": + """Enter the context and return the underlying MessageStream.""" + try: + self._message_stream = self._stream_manager.__enter__() + return self._message_stream + except Exception as exc: + # Handle errors during context entry (e.g., connection errors) + self._handler.fail_llm( + self._invocation, + Error(message=str(exc), type=type(exc)), + ) + raise + + def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool: + """Exit the context, extract telemetry, and finalize the span.""" + # Extract telemetry from the final message before exiting + if self._message_stream is not None and exc_type is None: + self._extract_telemetry_from_stream() + self._handler.stop_llm(self._invocation) + elif exc_type is not None: + # Handle error case + self._handler.fail_llm( + self._invocation, + Error(message=str(exc_val) if exc_val else str(exc_type), type=exc_type), + ) + # Always exit the underlying stream manager + return self._stream_manager.__exit__(exc_type, exc_val, exc_tb) + + def _extract_telemetry_from_stream(self) -> None: + """Extract telemetry data from the MessageStream's final message.""" + if self._message_stream is None: + return + + try: + # get_final_message() returns the accumulated Message object + final_message = self._message_stream.get_final_message() + + if final_message.model: + self._invocation.response_model_name = final_message.model + + if final_message.id: + self._invocation.response_id = final_message.id + + if final_message.stop_reason: + self._invocation.finish_reasons = [final_message.stop_reason] + + if final_message.usage: + self._invocation.input_tokens = final_message.usage.input_tokens + self._invocation.output_tokens = final_message.usage.output_tokens + except Exception: # pylint: disable=broad-exception-caught + # If we can't get the final message, we still want to end the span + pass diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml index 3940582198..d2752cba6c 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml @@ -434,4 +434,102 @@ interactions: status: code: 404 message: Not Found +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Hello" + } + ], + "model": "invalid-model-name" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '94' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "type": "error", + "error": { + "type": "not_found_error", + "message": "model: invalid-model-name" + }, + "request_id": "req_011CXhfKv2Kqp1zrqDWj6dqv" + } + headers: + CF-RAY: + - 9c72cefb9caf7c6c-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Sun, 01 Feb 2026 16:26:06 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + cf-cache-status: + - DYNAMIC + content-length: + - '133' + request-id: + - req_011CXhfKv2Kqp1zrqDWj6dqv + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '126' + x-should-retry: + - 'false' + status: + code: 404 + message: Not Found version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml index 205b1c2e49..1f39ccbfbe 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml @@ -850,4 +850,141 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '117' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01CuxDqMnML7sFP6212a2j1b", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello!" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 13, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 5, + "service_tier": "standard" + } + } + headers: + CF-RAY: + - 9c72cec25ed742e8-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Sun, 01 Feb 2026 16:25:58 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '30000' + anthropic-ratelimit-input-tokens-remaining: + - '30000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-01T16:25:58Z' + anthropic-ratelimit-output-tokens-limit: + - '8000' + anthropic-ratelimit-output-tokens-remaining: + - '8000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-01T16:25:58Z' + anthropic-ratelimit-requests-limit: + - '50' + anthropic-ratelimit-requests-remaining: + - '49' + anthropic-ratelimit-requests-reset: + - '2026-02-01T16:25:58Z' + anthropic-ratelimit-tokens-limit: + - '38000' + anthropic-ratelimit-tokens-remaining: + - '38000' + anthropic-ratelimit-tokens-reset: + - '2026-02-01T16:25:58Z' + cf-cache-status: + - DYNAMIC + content-length: + - '409' + request-id: + - req_011CXhfKErNmxjcBp7mFqHdT + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1389' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml index 17e0fb8715..9b9c8dd1aa 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml @@ -525,4 +525,141 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '102' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01WZGDeH8YFY9wyqm7sL4n1o", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hi! How are you doing today?" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 10, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 11, + "service_tier": "standard" + } + } + headers: + CF-RAY: + - 9c72cee56e637ac0-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Sun, 01 Feb 2026 16:26:04 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '30000' + anthropic-ratelimit-input-tokens-remaining: + - '30000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-01T16:26:03Z' + anthropic-ratelimit-output-tokens-limit: + - '8000' + anthropic-ratelimit-output-tokens-remaining: + - '8000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-01T16:26:04Z' + anthropic-ratelimit-requests-limit: + - '50' + anthropic-ratelimit-requests-remaining: + - '49' + anthropic-ratelimit-requests-reset: + - '2026-02-01T16:26:03Z' + anthropic-ratelimit-tokens-limit: + - '38000' + anthropic-ratelimit-tokens-remaining: + - '38000' + anthropic-ratelimit-tokens-reset: + - '2026-02-01T16:26:03Z' + cf-cache-status: + - DYNAMIC + content-length: + - '432' + request-id: + - req_011CXhfKepmyNSxwSrTaXZ4L + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1917' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml new file mode 100644 index 0000000000..f7aa869e34 --- /dev/null +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml @@ -0,0 +1,136 @@ +interactions: +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01L4V8w9WcTqy9XqeSGMvtmU","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard"}}} + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"}} + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9c72cefdb96f5e71-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Sun, 01 Feb 2026 16:26:07 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '30000' + anthropic-ratelimit-input-tokens-remaining: + - '30000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-01T16:26:06Z' + anthropic-ratelimit-output-tokens-limit: + - '8000' + anthropic-ratelimit-output-tokens-remaining: + - '8000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-01T16:26:06Z' + anthropic-ratelimit-requests-limit: + - '50' + anthropic-ratelimit-requests-remaining: + - '49' + anthropic-ratelimit-requests-reset: + - '2026-02-01T16:26:07Z' + anthropic-ratelimit-tokens-limit: + - '38000' + anthropic-ratelimit-tokens-remaining: + - '38000' + anthropic-ratelimit-tokens-reset: + - '2026-02-01T16:26:06Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXhfKwTQ5cLbB8jmLW9Td + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1221' + status: + code: 200 + message: OK +version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml new file mode 100644 index 0000000000..a9e81c05fe --- /dev/null +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml @@ -0,0 +1,145 @@ +interactions: +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '116' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_0159m5BagLKEtHHfhvuJinV7","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"!"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" How"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are you doing today?"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } + + event: message_stop + data: {"type":"message_stop"} + + headers: + CF-RAY: + - 9c72cf073e4bacc5-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Sun, 01 Feb 2026 16:26:09 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '30000' + anthropic-ratelimit-input-tokens-remaining: + - '30000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-01T16:26:08Z' + anthropic-ratelimit-output-tokens-limit: + - '8000' + anthropic-ratelimit-output-tokens-remaining: + - '8000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-01T16:26:08Z' + anthropic-ratelimit-requests-limit: + - '50' + anthropic-ratelimit-requests-remaining: + - '49' + anthropic-ratelimit-requests-reset: + - '2026-02-01T16:26:09Z' + anthropic-ratelimit-tokens-limit: + - '38000' + anthropic-ratelimit-tokens-remaining: + - '38000' + anthropic-ratelimit-tokens-reset: + - '2026-02-01T16:26:08Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXhfL3wpdUeBmx5xUp4Fg + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1202' + status: + code: 200 + message: OK +version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml index e6f90a0951..dda7184632 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml @@ -525,4 +525,141 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Count to 5." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '106' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_018pv7xuy9NfeeRkFsp9TaNB", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "1\n2\n3\n4\n5" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 12, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 13, + "service_tier": "standard" + } + } + headers: + CF-RAY: + - 9c72ced8a94daf79-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Sun, 01 Feb 2026 16:26:02 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '30000' + anthropic-ratelimit-input-tokens-remaining: + - '30000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-01T16:26:02Z' + anthropic-ratelimit-output-tokens-limit: + - '8000' + anthropic-ratelimit-output-tokens-remaining: + - '8000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-01T16:26:02Z' + anthropic-ratelimit-requests-limit: + - '50' + anthropic-ratelimit-requests-remaining: + - '49' + anthropic-ratelimit-requests-reset: + - '2026-02-01T16:26:02Z' + anthropic-ratelimit-tokens-limit: + - '38000' + anthropic-ratelimit-tokens-remaining: + - '38000' + anthropic-ratelimit-tokens-reset: + - '2026-02-01T16:26:02Z' + cf-cache-status: + - DYNAMIC + content-length: + - '417' + request-id: + - req_011CXhfKW89PXnDc5HQXH99X + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1884' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml index b63b5b56da..ae20fdc491 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml @@ -555,4 +555,147 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 50, + "messages": [ + { + "role": "user", + "content": "Say hello." + } + ], + "model": "claude-sonnet-4-20250514", + "stop_sequences": [ + "STOP" + ], + "temperature": 0.7, + "top_k": 40, + "top_p": 0.9 + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '171' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_016EWkCizXupxVXJna4vtjhm", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello! It's nice to meet you. How are you doing today?" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 10, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 18, + "service_tier": "standard" + } + } + headers: + CF-RAY: + - 9c72cecc5ef2c407-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Sun, 01 Feb 2026 16:26:00 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '30000' + anthropic-ratelimit-input-tokens-remaining: + - '30000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-01T16:25:59Z' + anthropic-ratelimit-output-tokens-limit: + - '8000' + anthropic-ratelimit-output-tokens-remaining: + - '8000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-01T16:26:00Z' + anthropic-ratelimit-requests-limit: + - '50' + anthropic-ratelimit-requests-remaining: + - '49' + anthropic-ratelimit-requests-reset: + - '2026-02-01T16:26:00Z' + anthropic-ratelimit-tokens-limit: + - '38000' + anthropic-ratelimit-tokens-remaining: + - '38000' + anthropic-ratelimit-tokens-reset: + - '2026-02-01T16:25:59Z' + cf-cache-status: + - DYNAMIC + content-length: + - '458' + request-id: + - req_011CXhfKMg9YrSDWDAnNgcwE + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1801' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml new file mode 100644 index 0000000000..803e07f182 --- /dev/null +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml @@ -0,0 +1,140 @@ +interactions: +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01UtyS6wd4yzRVPNssPV1Wgg","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5}} + + event: message_stop + data: {"type":"message_stop"} + + headers: + CF-RAY: + - 9c72cf18d90042d7-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Sun, 01 Feb 2026 16:26:11 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '30000' + anthropic-ratelimit-input-tokens-remaining: + - '30000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-01T16:26:10Z' + anthropic-ratelimit-output-tokens-limit: + - '8000' + anthropic-ratelimit-output-tokens-remaining: + - '8000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-01T16:26:10Z' + anthropic-ratelimit-requests-limit: + - '50' + anthropic-ratelimit-requests-remaining: + - '49' + anthropic-ratelimit-requests-reset: + - '2026-02-01T16:26:12Z' + anthropic-ratelimit-tokens-limit: + - '38000' + anthropic-ratelimit-tokens-remaining: + - '38000' + anthropic-ratelimit-tokens-reset: + - '2026-02-01T16:26:10Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXhfLG1cM5qTFLjqKqPof + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1157' + status: + code: 200 + message: OK +version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml new file mode 100644 index 0000000000..559a859f9f --- /dev/null +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml @@ -0,0 +1,143 @@ +interactions: +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Count to 3." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '120' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_017vXmL2yqaDeWBb7DqeSESe","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"1,"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" 2, 3."} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":12} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9c72cf2c0fd427f6-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Sun, 01 Feb 2026 16:26:15 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '30000' + anthropic-ratelimit-input-tokens-remaining: + - '30000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-01T16:26:14Z' + anthropic-ratelimit-output-tokens-limit: + - '8000' + anthropic-ratelimit-output-tokens-remaining: + - '8000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-01T16:26:14Z' + anthropic-ratelimit-requests-limit: + - '50' + anthropic-ratelimit-requests-remaining: + - '49' + anthropic-ratelimit-requests-reset: + - '2026-02-01T16:26:15Z' + anthropic-ratelimit-tokens-limit: + - '38000' + anthropic-ratelimit-tokens-remaining: + - '38000' + anthropic-ratelimit-tokens-reset: + - '2026-02-01T16:26:14Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXhfLVbfoCiVYmTTQgG8T + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1853' + status: + code: 200 + message: OK +version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml new file mode 100644 index 0000000000..50e3749d07 --- /dev/null +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml @@ -0,0 +1,152 @@ +interactions: +- request: + body: |- + { + "max_tokens": 50, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514", + "temperature": 0.7, + "top_k": 40, + "top_p": 0.9, + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '156' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_019Q4ndJ258iGw2TVyZV2CXu","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"!"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" How"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are you doing today?"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9c72cf21ff3ab9c6-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Sun, 01 Feb 2026 16:26:13 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '30000' + anthropic-ratelimit-input-tokens-remaining: + - '30000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-01T16:26:12Z' + anthropic-ratelimit-output-tokens-limit: + - '8000' + anthropic-ratelimit-output-tokens-remaining: + - '8000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-01T16:26:12Z' + anthropic-ratelimit-requests-limit: + - '50' + anthropic-ratelimit-requests-remaining: + - '49' + anthropic-ratelimit-requests-reset: + - '2026-02-01T16:26:13Z' + anthropic-ratelimit-tokens-limit: + - '38000' + anthropic-ratelimit-tokens-remaining: + - '38000' + anthropic-ratelimit-tokens-reset: + - '2026-02-01T16:26:12Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXhfLNFQGNJKZHNzk85AF + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1193' + status: + code: 200 + message: OK +version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py index f656f61eef..446290a911 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py @@ -300,3 +300,247 @@ def test_multiple_instrument_uninstrument_cycles( meter_provider=meter_provider, ) instrumentor.uninstrument() + + +@pytest.mark.vcr() +def test_sync_messages_create_streaming( # pylint: disable=too-many-locals + span_exporter, anthropic_client, instrument_no_content +): + """Test streaming message creation produces correct span.""" + model = "claude-sonnet-4-20250514" + messages = [{"role": "user", "content": "Say hello in one word."}] + + # Collect response data from stream + response_text = "" + response_id = None + response_model = None + stop_reason = None + input_tokens = None + output_tokens = None + + with anthropic_client.messages.create( + model=model, + max_tokens=100, + messages=messages, + stream=True, + ) as stream: + for chunk in stream: + # Extract data from chunks for assertion + if chunk.type == "message_start": + message = getattr(chunk, "message", None) + if message: + response_id = getattr(message, "id", None) + response_model = getattr(message, "model", None) + usage = getattr(message, "usage", None) + if usage: + input_tokens = getattr(usage, "input_tokens", None) + elif chunk.type == "content_block_delta": + delta = getattr(chunk, "delta", None) + if delta and hasattr(delta, "text"): + response_text += delta.text + elif chunk.type == "message_delta": + delta = getattr(chunk, "delta", None) + if delta: + stop_reason = getattr(delta, "stop_reason", None) + usage = getattr(chunk, "usage", None) + if usage: + output_tokens = getattr(usage, "output_tokens", None) + + spans = span_exporter.get_finished_spans() + assert len(spans) == 1 + + assert_span_attributes( + spans[0], + request_model=model, + response_id=response_id, + response_model=response_model, + input_tokens=input_tokens, + output_tokens=output_tokens, + finish_reasons=[stop_reason] if stop_reason else None, + ) + + +@pytest.mark.vcr() +def test_sync_messages_create_streaming_iteration( + span_exporter, anthropic_client, instrument_no_content +): + """Test streaming with direct iteration (without context manager).""" + model = "claude-sonnet-4-20250514" + messages = [{"role": "user", "content": "Say hi."}] + + stream = anthropic_client.messages.create( + model=model, + max_tokens=100, + messages=messages, + stream=True, + ) + + # Consume the stream by iterating + chunks = list(stream) + assert len(chunks) > 0 + + spans = span_exporter.get_finished_spans() + assert len(spans) == 1 + + span = spans[0] + assert span.attributes[GenAIAttributes.GEN_AI_REQUEST_MODEL] == model + # Verify span has response attributes from streaming + assert GenAIAttributes.GEN_AI_RESPONSE_ID in span.attributes + assert GenAIAttributes.GEN_AI_RESPONSE_MODEL in span.attributes + + +def test_sync_messages_create_streaming_connection_error( + span_exporter, instrument_no_content +): + """Test that connection errors during streaming are handled correctly.""" + model = "claude-sonnet-4-20250514" + messages = [{"role": "user", "content": "Hello"}] + + # Create client with invalid endpoint + client = Anthropic(base_url="http://localhost:9999") + + with pytest.raises(APIConnectionError): + client.messages.create( + model=model, + max_tokens=100, + messages=messages, + stream=True, + timeout=0.1, + ) + + spans = span_exporter.get_finished_spans() + assert len(spans) == 1 + + span = spans[0] + assert span.attributes[GenAIAttributes.GEN_AI_REQUEST_MODEL] == model + assert ErrorAttributes.ERROR_TYPE in span.attributes + assert "APIConnectionError" in span.attributes[ErrorAttributes.ERROR_TYPE] + + +# ============================================================================= +# Tests for Messages.stream() method +# ============================================================================= + + +@pytest.mark.vcr() +def test_sync_messages_stream_basic( + span_exporter, anthropic_client, instrument_no_content +): + """Test Messages.stream() produces correct span with context manager.""" + model = "claude-sonnet-4-20250514" + messages = [{"role": "user", "content": "Say hello in one word."}] + + with anthropic_client.messages.stream( + model=model, + max_tokens=100, + messages=messages, + ) as stream: + # Consume the stream using text_stream + response_text = "".join(stream.text_stream) + # Get the final message for assertions + final_message = stream.get_final_message() + + assert response_text # Should have some text + + spans = span_exporter.get_finished_spans() + assert len(spans) == 1 + + assert_span_attributes( + spans[0], + request_model=model, + response_id=final_message.id, + response_model=final_message.model, + input_tokens=final_message.usage.input_tokens, + output_tokens=final_message.usage.output_tokens, + finish_reasons=[final_message.stop_reason], + ) + + +@pytest.mark.vcr() +def test_sync_messages_stream_with_params( + span_exporter, anthropic_client, instrument_no_content +): + """Test Messages.stream() with additional parameters.""" + model = "claude-sonnet-4-20250514" + messages = [{"role": "user", "content": "Say hi."}] + + with anthropic_client.messages.stream( + model=model, + max_tokens=50, + messages=messages, + temperature=0.7, + top_p=0.9, + top_k=40, + ) as stream: + # Consume the stream + _ = "".join(stream.text_stream) + + spans = span_exporter.get_finished_spans() + assert len(spans) == 1 + + span = spans[0] + assert span.attributes[GenAIAttributes.GEN_AI_REQUEST_MODEL] == model + assert span.attributes[GenAIAttributes.GEN_AI_REQUEST_MAX_TOKENS] == 50 + assert span.attributes[GenAIAttributes.GEN_AI_REQUEST_TEMPERATURE] == 0.7 + assert span.attributes[GenAIAttributes.GEN_AI_REQUEST_TOP_P] == 0.9 + assert span.attributes[GenAIAttributes.GEN_AI_REQUEST_TOP_K] == 40 + + +@pytest.mark.vcr() +def test_sync_messages_stream_token_usage( + span_exporter, anthropic_client, instrument_no_content +): + """Test that Messages.stream() captures token usage correctly.""" + model = "claude-sonnet-4-20250514" + messages = [{"role": "user", "content": "Count to 3."}] + + with anthropic_client.messages.stream( + model=model, + max_tokens=100, + messages=messages, + ) as stream: + _ = "".join(stream.text_stream) + final_message = stream.get_final_message() + + spans = span_exporter.get_finished_spans() + assert len(spans) == 1 + + span = spans[0] + assert GenAIAttributes.GEN_AI_USAGE_INPUT_TOKENS in span.attributes + assert GenAIAttributes.GEN_AI_USAGE_OUTPUT_TOKENS in span.attributes + assert ( + span.attributes[GenAIAttributes.GEN_AI_USAGE_INPUT_TOKENS] + == final_message.usage.input_tokens + ) + assert ( + span.attributes[GenAIAttributes.GEN_AI_USAGE_OUTPUT_TOKENS] + == final_message.usage.output_tokens + ) + + +def test_sync_messages_stream_connection_error( + span_exporter, instrument_no_content +): + """Test that connection errors in Messages.stream() are handled correctly.""" + model = "claude-sonnet-4-20250514" + messages = [{"role": "user", "content": "Hello"}] + + # Create client with invalid endpoint + client = Anthropic(base_url="http://localhost:9999") + + with pytest.raises(APIConnectionError): + with client.messages.stream( + model=model, + max_tokens=100, + messages=messages, + timeout=0.1, + ) as stream: + # Try to consume the stream + _ = "".join(stream.text_stream) + + spans = span_exporter.get_finished_spans() + assert len(spans) == 1 + + span = spans[0] + assert span.attributes[GenAIAttributes.GEN_AI_REQUEST_MODEL] == model + assert ErrorAttributes.ERROR_TYPE in span.attributes From ea0bd9486a42196fc32f5e1675745f9975198a95 Mon Sep 17 00:00:00 2001 From: Teja Date: Sun, 1 Feb 2026 11:44:53 -0500 Subject: [PATCH 02/35] Add changelog entry for sync streaming support --- .../opentelemetry-instrumentation-anthropic/CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/CHANGELOG.md b/instrumentation-genai/opentelemetry-instrumentation-anthropic/CHANGELOG.md index ba164c0ebc..5cf210fbd1 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/CHANGELOG.md +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/CHANGELOG.md @@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Add sync streaming support for `Messages.create(stream=True)` and `Messages.stream()` + ([#4155](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4155)) + - `StreamWrapper` for handling `Messages.create(stream=True)` telemetry + - `MessageStreamManagerWrapper` for handling `Messages.stream()` telemetry + - `MessageWrapper` for non-streaming response telemetry extraction - Initial implementation of Anthropic instrumentation ([#3978](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3978)) - Implement sync `Messages.create` instrumentation with GenAI semantic convention attributes From 504d0df254bd2976d0aec043077f03d1b18c3f8e Mon Sep 17 00:00:00 2001 From: Teja Date: Sun, 1 Feb 2026 11:49:12 -0500 Subject: [PATCH 03/35] Fix type checking errors with type: ignore comments - Add type: ignore[arg-type] for Union type narrowing in messages_create - Add type: ignore[return-value] for wrapper return types - Add type: ignore[return-value] for __exit__ returning None --- .../instrumentation/anthropic/patch.py | 12 +++++++----- .../instrumentation/anthropic/utils.py | 15 +++++++++++---- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py index 52e435cdd7..e2624f2149 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py @@ -43,7 +43,9 @@ def messages_create( """Wrap the `create` method of the `Messages` class to trace it.""" def traced_method( - wrapped: Callable[..., Union["Message", "Stream[RawMessageStreamEvent]"]], + wrapped: Callable[ + ..., Union["Message", "Stream[RawMessageStreamEvent]"] + ], instance: "Messages", args: tuple[Any, ...], kwargs: dict[str, Any], @@ -69,8 +71,8 @@ def traced_method( try: result = wrapped(*args, **kwargs) if is_streaming: - return StreamWrapper(result, handler, invocation) - wrapper = MessageWrapper(result, handler, invocation) + return StreamWrapper(result, handler, invocation) # type: ignore[arg-type] + wrapper = MessageWrapper(result, handler, invocation) # type: ignore[arg-type] return wrapper.message except Exception as exc: handler.fail_llm( @@ -78,7 +80,7 @@ def traced_method( ) raise - return traced_method + return traced_method # type: ignore[return-value] def messages_stream( @@ -118,4 +120,4 @@ def traced_method( ) raise - return traced_method + return traced_method # type: ignore[return-value] diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py index 60b7a05cae..4945571b34 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py @@ -332,10 +332,13 @@ def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool: # Handle error case self._handler.fail_llm( self._invocation, - Error(message=str(exc_val) if exc_val else str(exc_type), type=exc_type), + Error( + message=str(exc_val) if exc_val else str(exc_type), + type=exc_type, + ), ) # Always exit the underlying stream manager - return self._stream_manager.__exit__(exc_type, exc_val, exc_tb) + return self._stream_manager.__exit__(exc_type, exc_val, exc_tb) # type: ignore[return-value] def _extract_telemetry_from_stream(self) -> None: """Extract telemetry data from the MessageStream's final message.""" @@ -356,8 +359,12 @@ def _extract_telemetry_from_stream(self) -> None: self._invocation.finish_reasons = [final_message.stop_reason] if final_message.usage: - self._invocation.input_tokens = final_message.usage.input_tokens - self._invocation.output_tokens = final_message.usage.output_tokens + self._invocation.input_tokens = ( + final_message.usage.input_tokens + ) + self._invocation.output_tokens = ( + final_message.usage.output_tokens + ) except Exception: # pylint: disable=broad-exception-caught # If we can't get the final message, we still want to end the span pass From 8df752a6129e0bbde15354899109e5e404859e73 Mon Sep 17 00:00:00 2001 From: Teja Date: Sun, 8 Feb 2026 21:11:15 -0500 Subject: [PATCH 04/35] Refactor Anthropic instrumentation to improve usage tracking and error handling - Introduce constants for provider name and cache token attributes. - Normalize stop reasons and aggregate cache token fields in MessageWrapper and StreamWrapper. - Enhance tests to validate input token aggregation and stop reason normalization. - Update cassettes for new request and response structures in streaming scenarios. --- .../instrumentation/anthropic/patch.py | 29 +- .../instrumentation/anthropic/utils.py | 163 +++++++++-- .../test_sync_messages_create_api_error.yaml | 192 +++++++++++++ .../test_sync_messages_create_basic.yaml | 232 ++++++++++++++++ ...test_sync_messages_create_stop_reason.yaml | 232 ++++++++++++++++ .../test_sync_messages_create_streaming.yaml | 229 ++++++++++++++++ ...c_messages_create_streaming_iteration.yaml | 241 +++++++++++++++++ ...test_sync_messages_create_token_usage.yaml | 232 ++++++++++++++++ ..._sync_messages_create_with_all_params.yaml | 244 +++++++++++++++++ .../test_sync_messages_stream_basic.yaml | 237 ++++++++++++++++ ...test_sync_messages_stream_token_usage.yaml | 237 ++++++++++++++++ ...test_sync_messages_stream_with_params.yaml | 252 ++++++++++++++++++ .../tests/test_sync_messages.py | 202 +++++++++++++- 13 files changed, 2686 insertions(+), 36 deletions(-) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py index e2624f2149..659f7f9f83 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py @@ -37,6 +37,9 @@ from anthropic.types import Message, RawMessageStreamEvent +ANTHROPIC = "anthropic" + + def messages_create( handler: TelemetryHandler, ) -> Callable[..., Union["Message", "Stream[RawMessageStreamEvent]"]]: @@ -52,15 +55,18 @@ def traced_method( ) -> Union["Message", StreamWrapper]: params = extract_params(*args, **kwargs) attributes = get_llm_request_attributes(params, instance) - request_model = str( - attributes.get(GenAIAttributes.GEN_AI_REQUEST_MODEL) - or params.model - or "unknown" + request_model_attribute = attributes.get( + GenAIAttributes.GEN_AI_REQUEST_MODEL + ) + request_model = ( + request_model_attribute + if isinstance(request_model_attribute, str) + else params.model or "" ) invocation = LLMInvocation( request_model=request_model, - provider="anthropic", + provider=ANTHROPIC, attributes=attributes, ) @@ -96,15 +102,18 @@ def traced_method( ) -> MessageStreamManagerWrapper: params = extract_params(*args, **kwargs) attributes = get_llm_request_attributes(params, instance) - request_model = str( - attributes.get(GenAIAttributes.GEN_AI_REQUEST_MODEL) - or params.model - or "unknown" + request_model_attribute = attributes.get( + GenAIAttributes.GEN_AI_REQUEST_MODEL + ) + request_model = ( + request_model_attribute + if isinstance(request_model_attribute, str) + else params.model or "" ) invocation = LLMInvocation( request_model=request_model, - provider="anthropic", + provider=ANTHROPIC, attributes=attributes, ) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py index 4945571b34..8b5bde9705 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py @@ -52,6 +52,76 @@ class MessageRequestParams: stop_sequences: Sequence[str] | None = None +_GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS = ( + "gen_ai.usage.cache_creation.input_tokens" +) +_GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS = ( + "gen_ai.usage.cache_read.input_tokens" +) + + +def _normalize_finish_reason(stop_reason: str | None) -> str | None: + """Map Anthropic stop reasons to GenAI semantic convention values.""" + if stop_reason is None: + return None + + normalized = { + "end_turn": "stop", + "stop_sequence": "stop", + "max_tokens": "length", + "tool_use": "tool_calls", + }.get(stop_reason) + return normalized or stop_reason + + +def _as_int(value: Any) -> int | None: + if isinstance(value, bool): + return None + if isinstance(value, int): + return value + return None + + +def _extract_usage_tokens( + usage: Any | None, +) -> tuple[int | None, int | None, int | None, int | None]: + """Extract Anthropic usage fields and compute semconv input tokens. + + Returns `(total_input_tokens, output_tokens, cache_creation_input_tokens, cache_read_input_tokens)`. + """ + if usage is None: + return None, None, None, None + + input_tokens = _as_int(getattr(usage, "input_tokens", None)) + cache_creation_input_tokens = _as_int( + getattr(usage, "cache_creation_input_tokens", None) + ) + cache_read_input_tokens = _as_int( + getattr(usage, "cache_read_input_tokens", None) + ) + output_tokens = _as_int(getattr(usage, "output_tokens", None)) + + if ( + input_tokens is None + and cache_creation_input_tokens is None + and cache_read_input_tokens is None + ): + total_input_tokens = None + else: + total_input_tokens = ( + (input_tokens or 0) + + (cache_creation_input_tokens or 0) + + (cache_read_input_tokens or 0) + ) + + return ( + total_input_tokens, + output_tokens, + cache_creation_input_tokens, + cache_read_input_tokens, + ) + + # Use parameter signature from # https://github.com/anthropics/anthropic-sdk-python/blob/9b5ab24ba17bcd5e762e5a5fd69bb3c17b100aaa/src/anthropic/resources/messages/messages.py#L896 # https://github.com/anthropics/anthropic-sdk-python/blob/9b5ab24ba17bcd5e762e5a5fd69bb3c17b100aaa/src/anthropic/resources/messages/messages.py#L963 @@ -180,12 +250,27 @@ def _extract_and_finalize( if self._message.id: invocation.response_id = self._message.id - if self._message.stop_reason: - invocation.finish_reasons = [self._message.stop_reason] + finish_reason = _normalize_finish_reason(self._message.stop_reason) + if finish_reason: + invocation.finish_reasons = [finish_reason] if self._message.usage: - invocation.input_tokens = self._message.usage.input_tokens - invocation.output_tokens = self._message.usage.output_tokens + ( + input_tokens, + output_tokens, + cache_creation_input_tokens, + cache_read_input_tokens, + ) = _extract_usage_tokens(self._message.usage) + invocation.input_tokens = input_tokens + invocation.output_tokens = output_tokens + if cache_creation_input_tokens is not None: + invocation.attributes[ + _GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS + ] = cache_creation_input_tokens + if cache_read_input_tokens is not None: + invocation.attributes[ + _GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS + ] = cache_read_input_tokens handler.stop_llm(invocation) @@ -218,6 +303,25 @@ def __init__( self._stop_reason: Optional[str] = None self._input_tokens: Optional[int] = None self._output_tokens: Optional[int] = None + self._cache_creation_input_tokens: Optional[int] = None + self._cache_read_input_tokens: Optional[int] = None + self._finalized = False + + def _update_usage(self, usage: Any | None) -> None: + ( + input_tokens, + output_tokens, + cache_creation_input_tokens, + cache_read_input_tokens, + ) = _extract_usage_tokens(usage) + if input_tokens is not None: + self._input_tokens = input_tokens + if output_tokens is not None: + self._output_tokens = output_tokens + if cache_creation_input_tokens is not None: + self._cache_creation_input_tokens = cache_creation_input_tokens + if cache_read_input_tokens is not None: + self._cache_read_input_tokens = cache_read_input_tokens def _process_chunk(self, chunk: "RawMessageStreamEvent") -> None: """Extract telemetry data from a streaming chunk.""" @@ -231,21 +335,22 @@ def _process_chunk(self, chunk: "RawMessageStreamEvent") -> None: self._response_model = message.model # message_start also contains initial usage with input_tokens if hasattr(message, "usage") and message.usage: - if hasattr(message.usage, "input_tokens"): - self._input_tokens = message.usage.input_tokens + self._update_usage(message.usage) # Handle message_delta event - contains stop_reason and output token usage elif chunk.type == "message_delta": delta = getattr(chunk, "delta", None) if delta and hasattr(delta, "stop_reason") and delta.stop_reason: - self._stop_reason = delta.stop_reason - # message_delta contains usage with output_tokens + self._stop_reason = _normalize_finish_reason(delta.stop_reason) + # message_delta contains usage with output_tokens (and may repeat input_tokens) usage = getattr(chunk, "usage", None) - if usage and hasattr(usage, "output_tokens"): - self._output_tokens = usage.output_tokens + self._update_usage(usage) def _finalize_invocation(self) -> None: """Update invocation with collected data and stop the span.""" + if self._finalized: + return + if self._response_model: self._invocation.response_model_name = self._response_model if self._response_id: @@ -256,8 +361,17 @@ def _finalize_invocation(self) -> None: self._invocation.input_tokens = self._input_tokens if self._output_tokens is not None: self._invocation.output_tokens = self._output_tokens + if self._cache_creation_input_tokens is not None: + self._invocation.attributes[ + _GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS + ] = self._cache_creation_input_tokens + if self._cache_read_input_tokens is not None: + self._invocation.attributes[ + _GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS + ] = self._cache_read_input_tokens self._handler.stop_llm(self._invocation) + self._finalized = True def __iter__(self) -> "StreamWrapper": return self @@ -355,16 +469,29 @@ def _extract_telemetry_from_stream(self) -> None: if final_message.id: self._invocation.response_id = final_message.id - if final_message.stop_reason: - self._invocation.finish_reasons = [final_message.stop_reason] + finish_reason = _normalize_finish_reason( + final_message.stop_reason + ) + if finish_reason: + self._invocation.finish_reasons = [finish_reason] if final_message.usage: - self._invocation.input_tokens = ( - final_message.usage.input_tokens - ) - self._invocation.output_tokens = ( - final_message.usage.output_tokens - ) + ( + input_tokens, + output_tokens, + cache_creation_input_tokens, + cache_read_input_tokens, + ) = _extract_usage_tokens(final_message.usage) + self._invocation.input_tokens = input_tokens + self._invocation.output_tokens = output_tokens + if cache_creation_input_tokens is not None: + self._invocation.attributes[ + _GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS + ] = cache_creation_input_tokens + if cache_read_input_tokens is not None: + self._invocation.attributes[ + _GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS + ] = cache_read_input_tokens except Exception: # pylint: disable=broad-exception-caught # If we can't get the final message, we still want to end the span pass diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml index d2752cba6c..a7959234bd 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml @@ -532,4 +532,196 @@ interactions: status: code: 404 message: Not Found +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Hello" + } + ], + "model": "invalid-model-name" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '94' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "type": "error", + "error": { + "type": "authentication_error", + "message": "invalid x-api-key" + }, + "request_id": "req_011CXwgSgGhfxSJTkXNcN1Zz" + } + headers: + CF-RAY: + - 9cafd28dfa24069b-EWR + Connection: + - keep-alive + Content-Length: + - '130' + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 09 Feb 2026 02:09:03 GMT + Server: + - cloudflare + X-Robots-Tag: + - none + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXwgSgGhfxSJTkXNcN1Zz + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '7' + x-should-retry: + - 'false' + status: + code: 401 + message: Unauthorized +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Hello" + } + ], + "model": "invalid-model-name" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '94' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "type": "error", + "error": { + "type": "not_found_error", + "message": "model: invalid-model-name" + }, + "request_id": "req_011CXwgYHa7w1jGDtLgoGbQB" + } + headers: + CF-RAY: + - 9cafd4697bb8429e-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 09 Feb 2026 02:10:19 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + cf-cache-status: + - DYNAMIC + content-length: + - '133' + request-id: + - req_011CXwgYHa7w1jGDtLgoGbQB + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '59' + x-should-retry: + - 'false' + status: + code: 404 + message: Not Found version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml index 1f39ccbfbe..c88a59caab 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml @@ -987,4 +987,236 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '117' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "type": "error", + "error": { + "type": "authentication_error", + "message": "invalid x-api-key" + }, + "request_id": "req_011CXwgSWJgAcLFshZ7pUbDp" + } + headers: + CF-RAY: + - 9cafd27f580a0f3b-EWR + Connection: + - keep-alive + Content-Length: + - '130' + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 09 Feb 2026 02:09:01 GMT + Server: + - cloudflare + X-Robots-Tag: + - none + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXwgSWJgAcLFshZ7pUbDp + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '8' + x-should-retry: + - 'false' + status: + code: 401 + message: Unauthorized +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '117' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_015EPMmo3gLS7YCe6TUktZb2", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello!" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 13, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 5, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cafd43a2e3c434b-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 09 Feb 2026 02:10:13 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-09T02:10:13Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-09T02:10:13Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-09T02:10:12Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-09T02:10:13Z' + cf-cache-status: + - DYNAMIC + content-length: + - '441' + request-id: + - req_011CXwgXjCCuSo8UFXeQUi1U + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1414' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml index 9b9c8dd1aa..ba428f593a 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml @@ -662,4 +662,236 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '102' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "type": "error", + "error": { + "type": "authentication_error", + "message": "invalid x-api-key" + }, + "request_id": "req_011CXwgSa1AxGMtGd5XzdLen" + } + headers: + CF-RAY: + - 9cafd284cbd141b5-EWR + Connection: + - keep-alive + Content-Length: + - '130' + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 09 Feb 2026 02:09:02 GMT + Server: + - cloudflare + X-Robots-Tag: + - none + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXwgSa1AxGMtGd5XzdLen + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '7' + x-should-retry: + - 'false' + status: + code: 401 + message: Unauthorized +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '102' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01K7sVffGTWcSPty9YFESayA", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hi! How are you doing today?" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 10, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 11, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cafd4580dc9e55d-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 09 Feb 2026 02:10:18 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-09T02:10:17Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-09T02:10:18Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-09T02:10:17Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-09T02:10:17Z' + cf-cache-status: + - DYNAMIC + content-length: + - '464' + request-id: + - req_011CXwgY5eXH1H2GjpRV41H1 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1045' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml index f7aa869e34..57f6a05423 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml @@ -133,4 +133,233 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "type": "error", + "error": { + "type": "authentication_error", + "message": "invalid x-api-key" + }, + "request_id": "req_011CXwgShB2Qa8WVkqeYfXig" + } + headers: + CF-RAY: + - 9cafd28f4a9a43cb-EWR + Connection: + - keep-alive + Content-Length: + - '130' + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 09 Feb 2026 02:09:03 GMT + Server: + - cloudflare + X-Robots-Tag: + - none + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXwgShB2Qa8WVkqeYfXig + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '8' + x-should-retry: + - 'false' + status: + code: 401 + message: Unauthorized +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01NPELKwEsJZ8JkGYmWb1dNZ","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cafd46b1f6bda48-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Mon, 09 Feb 2026 02:10:21 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-09T02:10:20Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-09T02:10:20Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-09T02:10:20Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-09T02:10:20Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXwgYJharaeaLQLFUgtAA + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1032' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml index a9e81c05fe..80fd6e3171 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml @@ -142,4 +142,245 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '116' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "type": "error", + "error": { + "type": "authentication_error", + "message": "invalid x-api-key" + }, + "request_id": "req_011CXwgSi5qjxtkPurKtrXr7" + } + headers: + CF-RAY: + - 9cafd29099c42223-EWR + Connection: + - keep-alive + Content-Length: + - '130' + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 09 Feb 2026 02:09:04 GMT + Server: + - cloudflare + X-Robots-Tag: + - none + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXwgSi5qjxtkPurKtrXr7 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '13' + x-should-retry: + - 'false' + status: + code: 401 + message: Unauthorized +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '116' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_014NZvt7j1MKDNTWFjhWasU9","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"!"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" How"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"}} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" you doing today?"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cafd475585f0cc8-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Mon, 09 Feb 2026 02:10:22 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-09T02:10:21Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-09T02:10:21Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-09T02:10:21Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-09T02:10:21Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXwgYRjkokczYVciHiVSL + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '997' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml index dda7184632..4014b60108 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml @@ -662,4 +662,236 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Count to 5." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '106' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "type": "error", + "error": { + "type": "authentication_error", + "message": "invalid x-api-key" + }, + "request_id": "req_011CXwgSYmWMTGa8zyoZHp28" + } + headers: + CF-RAY: + - 9cafd282fe6680ce-EWR + Connection: + - keep-alive + Content-Length: + - '130' + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 09 Feb 2026 02:09:01 GMT + Server: + - cloudflare + X-Robots-Tag: + - none + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXwgSYmWMTGa8zyoZHp28 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '7' + x-should-retry: + - 'false' + status: + code: 401 + message: Unauthorized +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Count to 5." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '106' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01C2Kwxu5ub3DBhyMpJ5Zkce", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "1\n2\n3\n4\n5" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 12, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 13, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cafd44f8d180c76-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 09 Feb 2026 02:10:16 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-09T02:10:16Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-09T02:10:16Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-09T02:10:15Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-09T02:10:16Z' + cf-cache-status: + - DYNAMIC + content-length: + - '449' + request-id: + - req_011CXwgXyq2Wq9g7egMSk4om + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1122' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml index ae20fdc491..8a5818e5f9 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml @@ -698,4 +698,248 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 50, + "messages": [ + { + "role": "user", + "content": "Say hello." + } + ], + "model": "claude-sonnet-4-20250514", + "stop_sequences": [ + "STOP" + ], + "temperature": 0.7, + "top_k": 40, + "top_p": 0.9 + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '171' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "type": "error", + "error": { + "type": "authentication_error", + "message": "invalid x-api-key" + }, + "request_id": "req_011CXwgSXkEnxQTGaBTxoZSF" + } + headers: + CF-RAY: + - 9cafd2817c630f9b-EWR + Connection: + - keep-alive + Content-Length: + - '130' + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 09 Feb 2026 02:09:01 GMT + Server: + - cloudflare + X-Robots-Tag: + - none + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXwgSXkEnxQTGaBTxoZSF + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '6' + x-should-retry: + - 'false' + status: + code: 401 + message: Unauthorized +- request: + body: |- + { + "max_tokens": 50, + "messages": [ + { + "role": "user", + "content": "Say hello." + } + ], + "model": "claude-sonnet-4-20250514", + "stop_sequences": [ + "STOP" + ], + "temperature": 0.7, + "top_k": 40, + "top_p": 0.9 + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '171' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_014MYP78mTSiRjcz9ac37em3", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello! It's nice to meet you. How are you doing today?" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 10, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 18, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cafd4455ab8435b-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 09 Feb 2026 02:10:15 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-09T02:10:15Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-09T02:10:15Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-09T02:10:14Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-09T02:10:15Z' + cf-cache-status: + - DYNAMIC + content-length: + - '490' + request-id: + - req_011CXwgXrqash6KC6buH67mT + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1367' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml index 803e07f182..c0a95ad54c 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml @@ -137,4 +137,241 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "type": "error", + "error": { + "type": "authentication_error", + "message": "invalid x-api-key" + }, + "request_id": "req_011CXwgSpckNmKSZ2zSSmGQe" + } + headers: + CF-RAY: + - 9cafd29a2a15edd5-EWR + Connection: + - keep-alive + Content-Length: + - '130' + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 09 Feb 2026 02:09:05 GMT + Server: + - cloudflare + X-Robots-Tag: + - none + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXwgSpckNmKSZ2zSSmGQe + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '11' + x-should-retry: + - 'false' + status: + code: 401 + message: Unauthorized +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01TYYPFFjh2MGYwMBT6dPtge","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cafd4877a208c99-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Mon, 09 Feb 2026 02:10:25 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-09T02:10:24Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-09T02:10:24Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-09T02:10:24Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-09T02:10:24Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXwgYe5evU3T1ocnZA3AN + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1116' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml index 559a859f9f..707485be56 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml @@ -140,4 +140,241 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Count to 3." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '120' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "type": "error", + "error": { + "type": "authentication_error", + "message": "invalid x-api-key" + }, + "request_id": "req_011CXwgSrZLCiephBDm8GSG4" + } + headers: + CF-RAY: + - 9cafd29cfff5610c-EWR + Connection: + - keep-alive + Content-Length: + - '130' + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 09 Feb 2026 02:09:06 GMT + Server: + - cloudflare + X-Robots-Tag: + - none + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXwgSrZLCiephBDm8GSG4 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '9' + x-should-retry: + - 'false' + status: + code: 401 + message: Unauthorized +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Count to 3." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '120' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01Di7hGD7Kjda9HtiLBmbQsG","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}}} + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"1, 2, 3."} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":12} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cafd49c781d624e-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Mon, 09 Feb 2026 02:10:28 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-09T02:10:28Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-09T02:10:28Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-09T02:10:28Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-09T02:10:28Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXwgYtTMCkfByoWq33gFZ + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '872' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml index 50e3749d07..62cb3b4c25 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml @@ -149,4 +149,256 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 50, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514", + "temperature": 0.7, + "top_k": 40, + "top_p": 0.9, + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '156' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "type": "error", + "error": { + "type": "authentication_error", + "message": "invalid x-api-key" + }, + "request_id": "req_011CXwgSqc2vZhH457PgSe2s" + } + headers: + CF-RAY: + - 9cafd29b9e514349-EWR + Connection: + - keep-alive + Content-Length: + - '130' + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 09 Feb 2026 02:09:05 GMT + Server: + - cloudflare + X-Robots-Tag: + - none + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXwgSqc2vZhH457PgSe2s + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '10' + x-should-retry: + - 'false' + status: + code: 401 + message: Unauthorized +- request: + body: |- + { + "max_tokens": 50, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514", + "temperature": 0.7, + "top_k": 40, + "top_p": 0.9, + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '156' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01JmJj8s976RDGr3bgLsG8my","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"}} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"!"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" How"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are you doing today?"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cafd490a8da9cb4-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Mon, 09 Feb 2026 02:10:27 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-09T02:10:26Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-09T02:10:26Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-09T02:10:26Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-09T02:10:26Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXwgYkRABneUfKwVLEWhv + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1272' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py index 446290a911..824d71241f 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py @@ -14,10 +14,17 @@ """Tests for sync Messages.create instrumentation.""" +from types import SimpleNamespace + import pytest from anthropic import Anthropic, APIConnectionError, NotFoundError from opentelemetry.instrumentation.anthropic import AnthropicInstrumentor +from opentelemetry.instrumentation.anthropic.utils import ( + MessageWrapper, + StreamWrapper, +) +from opentelemetry.util.genai.types import LLMInvocation from opentelemetry.semconv._incubating.attributes import ( error_attributes as ErrorAttributes, ) @@ -29,6 +36,24 @@ ) +def normalize_stop_reason(stop_reason): + """Map Anthropic stop reasons to GenAI semconv values.""" + return { + "end_turn": "stop", + "stop_sequence": "stop", + "max_tokens": "length", + "tool_use": "tool_calls", + }.get(stop_reason, stop_reason) + + +def expected_input_tokens(usage): + """Compute semconv input tokens from Anthropic usage.""" + base = getattr(usage, "input_tokens", 0) or 0 + cache_creation = getattr(usage, "cache_creation_input_tokens", 0) or 0 + cache_read = getattr(usage, "cache_read_input_tokens", 0) or 0 + return base + cache_creation + cache_read + + def assert_span_attributes( span, request_model, @@ -108,9 +133,9 @@ def test_sync_messages_create_basic( request_model=model, response_id=response.id, response_model=response.model, - input_tokens=response.usage.input_tokens, + input_tokens=expected_input_tokens(response.usage), output_tokens=response.usage.output_tokens, - finish_reasons=[response.stop_reason], + finish_reasons=[normalize_stop_reason(response.stop_reason)], ) @@ -167,7 +192,7 @@ def test_sync_messages_create_token_usage( assert GenAIAttributes.GEN_AI_USAGE_OUTPUT_TOKENS in span.attributes assert ( span.attributes[GenAIAttributes.GEN_AI_USAGE_INPUT_TOKENS] - == response.usage.input_tokens + == expected_input_tokens(response.usage) ) assert ( span.attributes[GenAIAttributes.GEN_AI_USAGE_OUTPUT_TOKENS] @@ -195,7 +220,7 @@ def test_sync_messages_create_stop_reason( span = spans[0] # Anthropic's stop_reason should be wrapped in a tuple (OTel converts lists) assert span.attributes[GenAIAttributes.GEN_AI_RESPONSE_FINISH_REASONS] == ( - response.stop_reason, + normalize_stop_reason(response.stop_reason), ) @@ -356,7 +381,9 @@ def test_sync_messages_create_streaming( # pylint: disable=too-many-locals response_model=response_model, input_tokens=input_tokens, output_tokens=output_tokens, - finish_reasons=[stop_reason] if stop_reason else None, + finish_reasons=[normalize_stop_reason(stop_reason)] + if stop_reason + else None, ) @@ -450,10 +477,169 @@ def test_sync_messages_stream_basic( request_model=model, response_id=final_message.id, response_model=final_message.model, - input_tokens=final_message.usage.input_tokens, + input_tokens=expected_input_tokens(final_message.usage), output_tokens=final_message.usage.output_tokens, - finish_reasons=[final_message.stop_reason], + finish_reasons=[normalize_stop_reason(final_message.stop_reason)], + ) + + +def test_stream_wrapper_finalize_idempotent(): + """StreamWrapper should stop telemetry exactly once.""" + + class FakeHandler: + def __init__(self): + self.stop_calls = 0 + self.fail_calls = 0 + + def stop_llm(self, invocation): + self.stop_calls += 1 + return invocation + + def fail_llm(self, invocation, error): + self.fail_calls += 1 + return invocation + + class FakeInvocation: + response_model_name = None + response_id = None + finish_reasons = None + input_tokens = None + output_tokens = None + attributes = {} + + class FakeChunk: + def __init__(self): + self.type = "message_start" + self.message = None + + class FakeStream: + def __init__(self): + self._chunks = [FakeChunk()] + self._index = 0 + + def __iter__(self): + return self + + def __next__(self): + if self._index >= len(self._chunks): + raise StopIteration + value = self._chunks[self._index] + self._index += 1 + return value + + def close(self): + return None + + handler = FakeHandler() + wrapper = StreamWrapper(FakeStream(), handler, FakeInvocation()) # type: ignore[arg-type] + + list(wrapper) + wrapper.close() + + assert handler.stop_calls == 1 + assert handler.fail_calls == 0 + + +def test_message_wrapper_aggregates_cache_tokens(): + """MessageWrapper should aggregate cache token fields into input tokens.""" + + class FakeHandler: + def stop_llm(self, invocation): + return invocation + + usage = SimpleNamespace( + input_tokens=10, + cache_creation_input_tokens=3, + cache_read_input_tokens=7, + output_tokens=5, + ) + message = SimpleNamespace( + model="claude-sonnet-4-20250514", + id="msg_123", + stop_reason="end_turn", + usage=usage, + ) + invocation = LLMInvocation( + request_model="claude-sonnet-4-20250514", + provider="anthropic", + ) + + MessageWrapper(message, FakeHandler(), invocation) # type: ignore[arg-type] + + assert invocation.input_tokens == 20 + assert invocation.output_tokens == 5 + assert invocation.finish_reasons == ["stop"] + assert ( + invocation.attributes["gen_ai.usage.cache_creation.input_tokens"] == 3 + ) + assert invocation.attributes["gen_ai.usage.cache_read.input_tokens"] == 7 + + +def test_stream_wrapper_aggregates_cache_tokens(): + """StreamWrapper should aggregate cache token fields from stream chunks.""" + + class FakeHandler: + def stop_llm(self, invocation): + return invocation + + def fail_llm(self, invocation, error): + return invocation + + message_start = SimpleNamespace( + type="message_start", + message=SimpleNamespace( + id="msg_1", + model="claude-sonnet-4-20250514", + usage=SimpleNamespace( + input_tokens=9, + cache_creation_input_tokens=1, + cache_read_input_tokens=2, + ), + ), + ) + message_delta = SimpleNamespace( + type="message_delta", + delta=SimpleNamespace(stop_reason="end_turn"), + usage=SimpleNamespace( + input_tokens=10, + cache_creation_input_tokens=3, + cache_read_input_tokens=4, + output_tokens=8, + ), + ) + + class FakeStream: + def __init__(self): + self._chunks = [message_start, message_delta] + self._index = 0 + + def __iter__(self): + return self + + def __next__(self): + if self._index >= len(self._chunks): + raise StopIteration + value = self._chunks[self._index] + self._index += 1 + return value + + def close(self): + return None + + invocation = LLMInvocation( + request_model="claude-sonnet-4-20250514", + provider="anthropic", + ) + wrapper = StreamWrapper(FakeStream(), FakeHandler(), invocation) # type: ignore[arg-type] + list(wrapper) + + assert invocation.input_tokens == 17 + assert invocation.output_tokens == 8 + assert invocation.finish_reasons == ["stop"] + assert ( + invocation.attributes["gen_ai.usage.cache_creation.input_tokens"] == 3 ) + assert invocation.attributes["gen_ai.usage.cache_read.input_tokens"] == 4 @pytest.mark.vcr() @@ -510,7 +696,7 @@ def test_sync_messages_stream_token_usage( assert GenAIAttributes.GEN_AI_USAGE_OUTPUT_TOKENS in span.attributes assert ( span.attributes[GenAIAttributes.GEN_AI_USAGE_INPUT_TOKENS] - == final_message.usage.input_tokens + == expected_input_tokens(final_message.usage) ) assert ( span.attributes[GenAIAttributes.GEN_AI_USAGE_OUTPUT_TOKENS] From 1b093774066dc0d8a4a618702348c865c5993b24 Mon Sep 17 00:00:00 2001 From: Teja Date: Sun, 8 Feb 2026 21:26:11 -0500 Subject: [PATCH 05/35] Refactor utility functions and test cases for improved readability and consistency - Simplify constant definitions and normalize function calls in utils.py. - Enhance test cases by removing unnecessary line breaks and improving formatting. - Ensure consistent usage of type hints and comments in test functions. --- .../instrumentation/anthropic/utils.py | 8 ++---- .../tests/test_sync_messages.py | 28 +++++++++---------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py index 8b5bde9705..7adfbd9a54 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py @@ -55,9 +55,7 @@ class MessageRequestParams: _GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS = ( "gen_ai.usage.cache_creation.input_tokens" ) -_GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS = ( - "gen_ai.usage.cache_read.input_tokens" -) +_GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS = "gen_ai.usage.cache_read.input_tokens" def _normalize_finish_reason(stop_reason: str | None) -> str | None: @@ -469,9 +467,7 @@ def _extract_telemetry_from_stream(self) -> None: if final_message.id: self._invocation.response_id = final_message.id - finish_reason = _normalize_finish_reason( - final_message.stop_reason - ) + finish_reason = _normalize_finish_reason(final_message.stop_reason) if finish_reason: self._invocation.finish_reasons = [finish_reason] diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py index 824d71241f..f188c4ca41 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py @@ -24,7 +24,6 @@ MessageWrapper, StreamWrapper, ) -from opentelemetry.util.genai.types import LLMInvocation from opentelemetry.semconv._incubating.attributes import ( error_attributes as ErrorAttributes, ) @@ -34,6 +33,7 @@ from opentelemetry.semconv._incubating.attributes import ( server_attributes as ServerAttributes, ) +from opentelemetry.util.genai.types import LLMInvocation def normalize_stop_reason(stop_reason): @@ -54,7 +54,7 @@ def expected_input_tokens(usage): return base + cache_creation + cache_read -def assert_span_attributes( +def assert_span_attributes( # pylint: disable=too-many-positional-arguments span, request_model, response_id=None, @@ -190,10 +190,9 @@ def test_sync_messages_create_token_usage( span = spans[0] assert GenAIAttributes.GEN_AI_USAGE_INPUT_TOKENS in span.attributes assert GenAIAttributes.GEN_AI_USAGE_OUTPUT_TOKENS in span.attributes - assert ( - span.attributes[GenAIAttributes.GEN_AI_USAGE_INPUT_TOKENS] - == expected_input_tokens(response.usage) - ) + assert span.attributes[ + GenAIAttributes.GEN_AI_USAGE_INPUT_TOKENS + ] == expected_input_tokens(response.usage) assert ( span.attributes[GenAIAttributes.GEN_AI_USAGE_OUTPUT_TOKENS] == response.usage.output_tokens @@ -527,7 +526,7 @@ def __next__(self): self._index += 1 return value - def close(self): + def close(self): # pylint: disable=no-self-use return None handler = FakeHandler() @@ -544,7 +543,7 @@ def test_message_wrapper_aggregates_cache_tokens(): """MessageWrapper should aggregate cache token fields into input tokens.""" class FakeHandler: - def stop_llm(self, invocation): + def stop_llm(self, invocation): # pylint: disable=no-self-use return invocation usage = SimpleNamespace( @@ -579,10 +578,10 @@ def test_stream_wrapper_aggregates_cache_tokens(): """StreamWrapper should aggregate cache token fields from stream chunks.""" class FakeHandler: - def stop_llm(self, invocation): + def stop_llm(self, invocation): # pylint: disable=no-self-use return invocation - def fail_llm(self, invocation, error): + def fail_llm(self, invocation, error): # pylint: disable=no-self-use return invocation message_start = SimpleNamespace( @@ -623,7 +622,7 @@ def __next__(self): self._index += 1 return value - def close(self): + def close(self): # pylint: disable=no-self-use return None invocation = LLMInvocation( @@ -694,10 +693,9 @@ def test_sync_messages_stream_token_usage( span = spans[0] assert GenAIAttributes.GEN_AI_USAGE_INPUT_TOKENS in span.attributes assert GenAIAttributes.GEN_AI_USAGE_OUTPUT_TOKENS in span.attributes - assert ( - span.attributes[GenAIAttributes.GEN_AI_USAGE_INPUT_TOKENS] - == expected_input_tokens(final_message.usage) - ) + assert span.attributes[ + GenAIAttributes.GEN_AI_USAGE_INPUT_TOKENS + ] == expected_input_tokens(final_message.usage) assert ( span.attributes[GenAIAttributes.GEN_AI_USAGE_OUTPUT_TOKENS] == final_message.usage.output_tokens From e6c83acebff54086a3f7f303800401f0d369cd7c Mon Sep 17 00:00:00 2001 From: Teja Date: Sun, 8 Feb 2026 22:04:02 -0500 Subject: [PATCH 06/35] Refactor argument handling in assert_span_attributes function - Update the pylint directive to disable too-many-arguments warning for better clarity. - Maintain consistency in function signature and improve code readability. --- .../tests/test_sync_messages.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py index f188c4ca41..38431ddee9 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py @@ -54,7 +54,7 @@ def expected_input_tokens(usage): return base + cache_creation + cache_read -def assert_span_attributes( # pylint: disable=too-many-positional-arguments +def assert_span_attributes( # pylint: disable=too-many-arguments span, request_model, response_id=None, From 1ed3c6b150a3353b42eef6068b1acffad85efe3b Mon Sep 17 00:00:00 2001 From: Teja Date: Sun, 8 Feb 2026 23:18:28 -0500 Subject: [PATCH 07/35] Enhance tests for streaming message handling in Anthropic instrumentation - Update test cases to validate streaming behavior with various parameters, including token usage and stop reasons. - Introduce new cassettes for different scenarios, ensuring comprehensive coverage of streaming interactions. - Refactor existing tests for clarity and consistency in structure and assertions. --- ...st_stream_wrapper_finalize_idempotent.yaml | 136 ++++++++++++++++ .../test_sync_messages_create_api_error.yaml | 98 +++++++++++ .../test_sync_messages_create_basic.yaml | 138 ++++++++++++++++ ...test_sync_messages_create_stop_reason.yaml | 138 ++++++++++++++++ .../test_sync_messages_create_streaming.yaml | 134 +++++++++++++++ ...c_messages_create_streaming_iteration.yaml | 143 ++++++++++++++++ ...test_sync_messages_create_token_usage.yaml | 138 ++++++++++++++++ ..._sync_messages_create_with_all_params.yaml | 144 +++++++++++++++++ .../test_sync_messages_stream_basic.yaml | 138 ++++++++++++++++ ...test_sync_messages_stream_token_usage.yaml | 141 ++++++++++++++++ ...test_sync_messages_stream_with_params.yaml | 153 ++++++++++++++++++ .../tests/test_sync_messages.py | 102 ++++++------ 12 files changed, 1552 insertions(+), 51 deletions(-) create mode 100644 instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml new file mode 100644 index 0000000000..1da06be099 --- /dev/null +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml @@ -0,0 +1,136 @@ +interactions: +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01BGX5ApzM8DLmEKxRo1YKfw","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":5,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop"} + + headers: + CF-RAY: + - 9cb07f1998c1c5e7-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Mon, 09 Feb 2026 04:06:52 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-09T04:06:51Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-09T04:06:51Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-09T04:06:51Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-09T04:06:51Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXwqReiTcD4qYBSa9FJu2 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1020' + status: + code: 200 + message: OK +version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml index a7959234bd..9843c9e71f 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml @@ -724,4 +724,102 @@ interactions: status: code: 404 message: Not Found +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Hello" + } + ], + "model": "invalid-model-name" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '94' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "type": "error", + "error": { + "type": "not_found_error", + "message": "model: invalid-model-name" + }, + "request_id": "req_011CXwqREDoqGA4tDpEHMNK6" + } + headers: + CF-RAY: + - 9cb07ef5cb058ae3-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 09 Feb 2026 04:06:45 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + cf-cache-status: + - DYNAMIC + content-length: + - '133' + request-id: + - req_011CXwqREDoqGA4tDpEHMNK6 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '67' + x-should-retry: + - 'false' + status: + code: 404 + message: Not Found version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml index c88a59caab..1bc2e7ba3f 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml @@ -1219,4 +1219,142 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '117' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01LoJKhArRbNU3Y8k1CfjFy7", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello!" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 13, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 5, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cb07ec4ddfb80d3-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 09 Feb 2026 04:06:38 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-09T04:06:38Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-09T04:06:38Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-09T04:06:37Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-09T04:06:38Z' + cf-cache-status: + - DYNAMIC + content-length: + - '441' + request-id: + - req_011CXwqQeivmMsTHWupX7Guh + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1242' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml index ba428f593a..db20fdf60d 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml @@ -894,4 +894,142 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '102' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01QBMLAiUoeut6fBz8vGFvJT", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hi! How are you doing today?" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 10, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 11, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cb07ee279e9daac-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 09 Feb 2026 04:06:43 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-09T04:06:43Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-09T04:06:43Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-09T04:06:42Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-09T04:06:43Z' + cf-cache-status: + - DYNAMIC + content-length: + - '464' + request-id: + - req_011CXwqR1156Euh9aZyJgEac + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1464' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml index 57f6a05423..0a60cb10f6 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml @@ -362,4 +362,138 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01UM7FKi4sQ9AuD6jidmAKn9","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}} + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"}} + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cb07ef75f9041d2-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Mon, 09 Feb 2026 04:06:46 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-09T04:06:45Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-09T04:06:45Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-09T04:06:45Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-09T04:06:45Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXwqRFJ44wMGtnsUvEm3R + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '911' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml index 80fd6e3171..0b03eb31cc 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml @@ -383,4 +383,147 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '116' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01JQWybySyhRsevUAmynSLpW","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"!"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" How"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are you doing today?"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cb07eff1c978153-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Mon, 09 Feb 2026 04:06:47 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-09T04:06:47Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-09T04:06:47Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-09T04:06:47Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-09T04:06:47Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXwqRLbYFZHkPv1hGbWUK + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '955' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml index 4014b60108..dbe7538e80 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml @@ -894,4 +894,142 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Count to 5." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '106' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01HX4WVufKAzBqYmzF7mk8qy", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "1, 2, 3, 4, 5" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 12, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 17, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cb07ed81d621f03-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 09 Feb 2026 04:06:42 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-09T04:06:41Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-09T04:06:41Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-09T04:06:40Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-09T04:06:41Z' + cf-cache-status: + - DYNAMIC + content-length: + - '449' + request-id: + - req_011CXwqQsvfyqSDGqpibBfuU + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1327' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml index 8a5818e5f9..d5d4010629 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml @@ -942,4 +942,148 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 50, + "messages": [ + { + "role": "user", + "content": "Say hello." + } + ], + "model": "claude-sonnet-4-20250514", + "stop_sequences": [ + "STOP" + ], + "temperature": 0.7, + "top_k": 40, + "top_p": 0.9 + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '171' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01PtP8Jkm4iforEmomiHjp6n", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello! How are you doing today?" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 10, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 11, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cb07ecebf06acc5-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 09 Feb 2026 04:06:40 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-09T04:06:40Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-09T04:06:40Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-09T04:06:39Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-09T04:06:40Z' + cf-cache-status: + - DYNAMIC + content-length: + - '467' + request-id: + - req_011CXwqQmXDBUWKj1LHbm3p5 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1210' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml index c0a95ad54c..3259810f04 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml @@ -374,4 +374,142 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_013xhnC6x7oA5LvcJRG7U42t","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cb07f10cda0255d-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Mon, 09 Feb 2026 04:06:50 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-09T04:06:49Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-09T04:06:49Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-09T04:06:49Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-09T04:06:49Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXwqRYh4Vo9JgfndnBwzL + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1113' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml index 707485be56..e72024800e 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml @@ -377,4 +377,145 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Count to 3." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '120' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01Noe1B8RqrKd5c4Bz4G1Bez","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"1,"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" 2, 3"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cb07f2f498d49aa-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Mon, 09 Feb 2026 04:06:55 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-09T04:06:54Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-09T04:06:54Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-09T04:06:54Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-09T04:06:54Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXwqRuZBdBi9usrWNeXwM + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1152' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml index 62cb3b4c25..6304a7c5b4 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml @@ -401,4 +401,157 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 50, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514", + "temperature": 0.7, + "top_k": 40, + "top_p": 0.9, + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '156' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01Xn5esvQrnMFQiahr6QsZdK","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"!"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" How"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" you doing today?"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cb07f21c8d243dc-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Mon, 09 Feb 2026 04:06:54 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-09T04:06:52Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-09T04:06:52Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-09T04:06:52Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-09T04:06:52Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXwqRkkrNN5FqY3bv5qNt + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1530' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py index 38431ddee9..708c4485e6 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py @@ -482,61 +482,61 @@ def test_sync_messages_stream_basic( ) -def test_stream_wrapper_finalize_idempotent(): - """StreamWrapper should stop telemetry exactly once.""" - - class FakeHandler: - def __init__(self): - self.stop_calls = 0 - self.fail_calls = 0 - - def stop_llm(self, invocation): - self.stop_calls += 1 - return invocation - - def fail_llm(self, invocation, error): - self.fail_calls += 1 - return invocation - - class FakeInvocation: - response_model_name = None - response_id = None - finish_reasons = None - input_tokens = None - output_tokens = None - attributes = {} - - class FakeChunk: - def __init__(self): - self.type = "message_start" - self.message = None - - class FakeStream: - def __init__(self): - self._chunks = [FakeChunk()] - self._index = 0 - - def __iter__(self): - return self - - def __next__(self): - if self._index >= len(self._chunks): - raise StopIteration - value = self._chunks[self._index] - self._index += 1 - return value +@pytest.mark.vcr() +def test_stream_wrapper_finalize_idempotent( + span_exporter, anthropic_client, instrument_no_content +): + """Fully consumed stream plus explicit close should still yield one span.""" + model = "claude-sonnet-4-20250514" + messages = [{"role": "user", "content": "Say hello in one word."}] - def close(self): # pylint: disable=no-self-use - return None + stream = anthropic_client.messages.create( + model=model, + max_tokens=100, + messages=messages, + stream=True, + ) - handler = FakeHandler() - wrapper = StreamWrapper(FakeStream(), handler, FakeInvocation()) # type: ignore[arg-type] + response_id = None + response_model = None + stop_reason = None + input_tokens = None + output_tokens = None - list(wrapper) - wrapper.close() + # Consume the stream fully, then call close() to verify idempotent finalization. + for chunk in stream: + if chunk.type == "message_start": + message = getattr(chunk, "message", None) + if message: + response_id = getattr(message, "id", None) + response_model = getattr(message, "model", None) + usage = getattr(message, "usage", None) + if usage: + input_tokens = expected_input_tokens(usage) + elif chunk.type == "message_delta": + delta = getattr(chunk, "delta", None) + if delta: + stop_reason = getattr(delta, "stop_reason", None) + usage = getattr(chunk, "usage", None) + if usage: + output_tokens = getattr(usage, "output_tokens", None) + input_tokens = expected_input_tokens(usage) + + stream.close() - assert handler.stop_calls == 1 - assert handler.fail_calls == 0 + spans = span_exporter.get_finished_spans() + assert len(spans) == 1 + assert_span_attributes( + spans[0], + request_model=model, + response_id=response_id, + response_model=response_model, + input_tokens=input_tokens, + output_tokens=output_tokens, + finish_reasons=[normalize_stop_reason(stop_reason)] + if stop_reason + else None, + ) def test_message_wrapper_aggregates_cache_tokens(): From 2851e4a8abeb237e8c6abbabb6450d34de69c66a Mon Sep 17 00:00:00 2001 From: Teja Date: Sun, 8 Feb 2026 23:25:09 -0500 Subject: [PATCH 08/35] Update test_sync_messages.py to disable pylint warning for too-many-locals in test_stream_wrapper_finalize_idempotent function --- .../tests/test_sync_messages.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py index 708c4485e6..3358483615 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py @@ -484,7 +484,7 @@ def test_sync_messages_stream_basic( @pytest.mark.vcr() def test_stream_wrapper_finalize_idempotent( - span_exporter, anthropic_client, instrument_no_content + span_exporter, anthropic_client, instrument_no_content # pylint: disable=too-many-locals ): """Fully consumed stream plus explicit close should still yield one span.""" model = "claude-sonnet-4-20250514" From 38d442923edd9949e16dc4b07f0424ad4683a226 Mon Sep 17 00:00:00 2001 From: Teja Date: Tue, 10 Feb 2026 06:43:28 -0500 Subject: [PATCH 09/35] Enhance StreamWrapper and MessageStreamManagerWrapper for idempotent finalization - Refactor finalization logic in StreamWrapper and MessageStreamManagerWrapper to ensure idempotent behavior during context exit. - Introduce new methods for successful and error finalization, improving clarity and reducing code duplication. - Add tests to validate double exit idempotency in streaming scenarios, ensuring only one span is emitted. - Update cassettes to reflect new request and response structures for streaming interactions. --- .../instrumentation/anthropic/utils.py | 36 +++-- ...st_stream_wrapper_finalize_idempotent.yaml | 134 ++++++++++++++++ .../test_sync_messages_create_api_error.yaml | 98 ++++++++++++ .../test_sync_messages_create_basic.yaml | 138 ++++++++++++++++ ...test_sync_messages_create_stop_reason.yaml | 138 ++++++++++++++++ .../test_sync_messages_create_streaming.yaml | 134 ++++++++++++++++ ...c_messages_create_streaming_iteration.yaml | 143 +++++++++++++++++ ...test_sync_messages_create_token_usage.yaml | 138 ++++++++++++++++ ..._sync_messages_create_with_all_params.yaml | 144 +++++++++++++++++ .../test_sync_messages_stream_basic.yaml | 138 ++++++++++++++++ ...essages_stream_double_exit_idempotent.yaml | 140 ++++++++++++++++ ...test_sync_messages_stream_token_usage.yaml | 141 ++++++++++++++++ ...test_sync_messages_stream_with_params.yaml | 150 ++++++++++++++++++ .../tests/test_sync_messages.py | 23 +++ 14 files changed, 1682 insertions(+), 13 deletions(-) create mode 100644 instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_double_exit_idempotent.yaml diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py index 7adfbd9a54..49cd03be4c 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py @@ -348,6 +348,7 @@ def _finalize_invocation(self) -> None: """Update invocation with collected data and stop the span.""" if self._finalized: return + self._finalized = True if self._response_model: self._invocation.response_model_name = self._response_model @@ -369,7 +370,6 @@ def _finalize_invocation(self) -> None: ] = self._cache_read_input_tokens self._handler.stop_llm(self._invocation) - self._finalized = True def __iter__(self) -> "StreamWrapper": return self @@ -420,6 +420,25 @@ def __init__( self._handler = handler self._invocation = invocation self._message_stream: Optional["MessageStream"] = None + self._finalized = False + + def _finalize_success(self) -> None: + if self._finalized: + return + self._finalized = True + self._handler.stop_llm(self._invocation) + + def _finalize_error(self, exc_type: Any, exc_val: Any) -> None: + if self._finalized: + return + self._finalized = True + self._handler.fail_llm( + self._invocation, + Error( + message=str(exc_val) if exc_val else str(exc_type), + type=exc_type, + ), + ) def __enter__(self) -> "MessageStream": """Enter the context and return the underlying MessageStream.""" @@ -428,10 +447,7 @@ def __enter__(self) -> "MessageStream": return self._message_stream except Exception as exc: # Handle errors during context entry (e.g., connection errors) - self._handler.fail_llm( - self._invocation, - Error(message=str(exc), type=type(exc)), - ) + self._finalize_error(type(exc), exc) raise def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool: @@ -439,16 +455,10 @@ def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool: # Extract telemetry from the final message before exiting if self._message_stream is not None and exc_type is None: self._extract_telemetry_from_stream() - self._handler.stop_llm(self._invocation) + self._finalize_success() elif exc_type is not None: # Handle error case - self._handler.fail_llm( - self._invocation, - Error( - message=str(exc_val) if exc_val else str(exc_type), - type=exc_type, - ), - ) + self._finalize_error(exc_type, exc_val) # Always exit the underlying stream manager return self._stream_manager.__exit__(exc_type, exc_val, exc_tb) # type: ignore[return-value] diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml index 1da06be099..e8fe735c47 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml @@ -133,4 +133,138 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01L2adFyfDDLTDx7dTiMxebU","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cb88a23d8f1f78d-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Tue, 10 Feb 2026 03:32:30 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-10T03:32:29Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-10T03:32:29Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-10T03:32:29Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-10T03:32:29Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXygcb5wc3EEzoQ7LZTuz + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1268' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml index 9843c9e71f..a9c4c98c5b 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml @@ -822,4 +822,102 @@ interactions: status: code: 404 message: Not Found +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Hello" + } + ], + "model": "invalid-model-name" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '94' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "type": "error", + "error": { + "type": "not_found_error", + "message": "model: invalid-model-name" + }, + "request_id": "req_011CXygc6hPiqrWctdPWryki" + } + headers: + CF-RAY: + - 9cb889fa58d33d3e-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Tue, 10 Feb 2026 03:32:22 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + cf-cache-status: + - DYNAMIC + content-length: + - '133' + request-id: + - req_011CXygc6hPiqrWctdPWryki + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '76' + x-should-retry: + - 'false' + status: + code: 404 + message: Not Found version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml index 1bc2e7ba3f..3eb64c25e4 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml @@ -1357,4 +1357,142 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '117' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01K78vKWGf2VjiHfBeMUqzLd", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello!" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 13, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 5, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cb889c988ef41af-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Tue, 10 Feb 2026 03:32:16 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-10T03:32:15Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-10T03:32:16Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-10T03:32:15Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-10T03:32:15Z' + cf-cache-status: + - DYNAMIC + content-length: + - '441' + request-id: + - req_011CXygbXLC4RW3sUycx3X7f + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1103' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml index db20fdf60d..515ecb8d79 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml @@ -1032,4 +1032,142 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '102' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01Sq9dhxjKKX1FCrg1eDTDui", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hi! How are you doing today?" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 10, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 11, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cb889e62e1e2f65-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Tue, 10 Feb 2026 03:32:21 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-10T03:32:20Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-10T03:32:21Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-10T03:32:19Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-10T03:32:20Z' + cf-cache-status: + - DYNAMIC + content-length: + - '464' + request-id: + - req_011CXygbrtvjUXsii1Y146gj + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1635' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml index 0a60cb10f6..868565b3cc 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml @@ -496,4 +496,138 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_012oHhogVPBokZdYPVAew9X9","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cb889fc19275642-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Tue, 10 Feb 2026 03:32:24 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-10T03:32:23Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-10T03:32:23Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-10T03:32:23Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-10T03:32:23Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXygc7sLZXhoTvZSQiyNf + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1093' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml index 0b03eb31cc..611c3f24ca 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml @@ -526,4 +526,147 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '116' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01ApLwwRkGe67Yjnarmgk4eu","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}} + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"! How"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" you doing today?"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cb88a04da4cf78d-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Tue, 10 Feb 2026 03:32:25 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-10T03:32:24Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-10T03:32:24Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-10T03:32:24Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-10T03:32:24Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXygcDsk8uukt8VNQHvUK + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '906' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml index dbe7538e80..240f756e9f 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml @@ -1032,4 +1032,142 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Count to 5." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '106' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01871ZBq5Y4CXmNXvUZJZSjB", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "1, 2, 3, 4, 5" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 12, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 17, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cb889dad8d81c6f-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Tue, 10 Feb 2026 03:32:19 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-10T03:32:18Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-10T03:32:19Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-10T03:32:17Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-10T03:32:18Z' + cf-cache-status: + - DYNAMIC + content-length: + - '449' + request-id: + - req_011CXygbj9MRg9YVhm8owbVG + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1471' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml index d5d4010629..03229a8dff 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml @@ -1086,4 +1086,148 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 50, + "messages": [ + { + "role": "user", + "content": "Say hello." + } + ], + "model": "claude-sonnet-4-20250514", + "stop_sequences": [ + "STOP" + ], + "temperature": 0.7, + "top_k": 40, + "top_p": 0.9 + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '171' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_015zydpZjnzzXbjbmDYcPJzE", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello! It's nice to meet you. How are you doing today?" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 10, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 18, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cb889d23c1942fb-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Tue, 10 Feb 2026 03:32:17 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-10T03:32:17Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-10T03:32:17Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-10T03:32:16Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-10T03:32:17Z' + cf-cache-status: + - DYNAMIC + content-length: + - '490' + request-id: + - req_011CXygbdHshaW4LSfGHCw5L + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1102' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml index 3259810f04..fa0c618882 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml @@ -512,4 +512,142 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01FSTci7pL3KTtDnAaqxTK7Z","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cb88a165a2fef9f-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Tue, 10 Feb 2026 03:32:29 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-10T03:32:27Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-10T03:32:27Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-10T03:32:27Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-10T03:32:27Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXygcRs4PZeVP1JqvbGoZ + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1885' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_double_exit_idempotent.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_double_exit_idempotent.yaml new file mode 100644 index 0000000000..029d4c9ba4 --- /dev/null +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_double_exit_idempotent.yaml @@ -0,0 +1,140 @@ +interactions: +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hi in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '128' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01TrsQqacXpj6Ud9M6oVYKft","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}} + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0} + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop"} + + headers: + CF-RAY: + - 9cb88a402f32c64a-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Tue, 10 Feb 2026 03:32:35 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-10T03:32:34Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-10T03:32:34Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-10T03:32:34Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-10T03:32:34Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXygcvS2mxUsiKQWWnxaA + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1117' + status: + code: 200 + message: OK +version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml index e72024800e..33c11e637e 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml @@ -518,4 +518,145 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Count to 3." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '120' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_0175FsXWrcYiyPjWyX99tgfc","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"1"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"\n2\n3"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":9} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cb88a367be343c3-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Tue, 10 Feb 2026 03:32:33 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-10T03:32:32Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-10T03:32:32Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-10T03:32:32Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-10T03:32:32Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXygcpFhtQd8RjVgXcnVB + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1099' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml index 6304a7c5b4..cf490e76b7 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml @@ -554,4 +554,154 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 50, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514", + "temperature": 0.7, + "top_k": 40, + "top_p": 0.9, + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '156' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01WjabTqNX9CP6M4pYmaoaNg","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"! How"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" you doing today?"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } + + event: message_stop + data: {"type":"message_stop"} + + headers: + CF-RAY: + - 9cb88a2eeb244b05-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Tue, 10 Feb 2026 03:32:31 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-10T03:32:31Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-10T03:32:31Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-10T03:32:31Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-10T03:32:31Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXygcidsTv149v7gXLDdt + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '746' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py index 3358483615..9e809f6ad6 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py @@ -702,6 +702,29 @@ def test_sync_messages_stream_token_usage( ) +@pytest.mark.vcr() +def test_sync_messages_stream_double_exit_idempotent( + span_exporter, anthropic_client, instrument_no_content +): + """Calling __exit__ twice should still emit only one span.""" + model = "claude-sonnet-4-20250514" + messages = [{"role": "user", "content": "Say hi in one word."}] + + manager = anthropic_client.messages.stream( + model=model, + max_tokens=100, + messages=messages, + ) + stream = manager.__enter__() + _ = "".join(stream.text_stream) + manager.__exit__(None, None, None) + manager.__exit__(None, None, None) + + spans = span_exporter.get_finished_spans() + assert len(spans) == 1 + assert spans[0].attributes[GenAIAttributes.GEN_AI_REQUEST_MODEL] == model + + def test_sync_messages_stream_connection_error( span_exporter, instrument_no_content ): From 0f481c15ae10761c033c35db0b8f268c0bfeab5e Mon Sep 17 00:00:00 2001 From: Teja Date: Wed, 11 Feb 2026 12:13:22 -0500 Subject: [PATCH 10/35] Enhance Anthropic instrumentation to support content capture - Added logger_provider to TelemetryHandler for improved logging capabilities. - Implemented content capture logic in messages_create and messages_stream functions, allowing for the extraction of input messages and system instructions. - Introduced utility functions for content conversion and message handling in utils.py. - Updated tests to validate content capture functionality for both synchronous and streaming message creation. - Added new cassettes to reflect the changes in request and response structures for content capture scenarios. --- .../instrumentation/anthropic/__init__.py | 3 +- .../instrumentation/anthropic/patch.py | 21 +- .../instrumentation/anthropic/utils.py | 285 ++- ...st_stream_wrapper_finalize_idempotent.yaml | 402 ++++ .../test_sync_messages_create_api_error.yaml | 294 +++ .../test_sync_messages_create_basic.yaml | 414 ++++ ...sync_messages_create_captures_content.yaml | 1912 +++++++++++++++++ ...ages_create_captures_thinking_content.yaml | 250 +++ ...ages_create_captures_tool_use_content.yaml | 328 +++ ...test_sync_messages_create_stop_reason.yaml | 414 ++++ .../test_sync_messages_create_streaming.yaml | 402 ++++ ...ges_create_streaming_captures_content.yaml | 1035 +++++++++ ...c_messages_create_streaming_iteration.yaml | 423 ++++ ...test_sync_messages_create_token_usage.yaml | 414 ++++ ..._sync_messages_create_with_all_params.yaml | 432 ++++ .../test_sync_messages_stream_basic.yaml | 414 ++++ ...sync_messages_stream_captures_content.yaml | 1067 +++++++++ ...essages_stream_double_exit_idempotent.yaml | 423 ++++ ...test_sync_messages_stream_token_usage.yaml | 420 ++++ ...test_sync_messages_stream_with_params.yaml | 456 ++++ .../tests/conftest.py | 18 +- .../tests/test_sync_messages.py | 188 +- 22 files changed, 9992 insertions(+), 23 deletions(-) create mode 100644 instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml create mode 100644 instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml create mode 100644 instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml create mode 100644 instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml create mode 100644 instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_captures_content.yaml diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/__init__.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/__init__.py index 197ad4e838..cac7db6d14 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/__init__.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/__init__.py @@ -92,11 +92,12 @@ def _instrument(self, **kwargs: Any) -> None: # Get providers from kwargs tracer_provider = kwargs.get("tracer_provider") meter_provider = kwargs.get("meter_provider") + logger_provider = kwargs.get("logger_provider") - # TODO: Add logger_provider to TelemetryHandler to capture content events. handler = TelemetryHandler( tracer_provider=tracer_provider, meter_provider=meter_provider, + logger_provider=logger_provider, ) # Patch Messages.create diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py index 659f7f9f83..c69c8681eb 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py @@ -27,7 +27,10 @@ MessageWrapper, StreamWrapper, extract_params, + get_input_messages, get_llm_request_attributes, + get_system_instruction, + should_capture_content, ) if TYPE_CHECKING: @@ -64,9 +67,16 @@ def traced_method( else params.model or "" ) + capture_content = should_capture_content() invocation = LLMInvocation( request_model=request_model, provider=ANTHROPIC, + input_messages=get_input_messages(params.messages) + if capture_content + else [], + system_instruction=get_system_instruction(params.system) + if capture_content + else [], attributes=attributes, ) @@ -78,7 +88,9 @@ def traced_method( result = wrapped(*args, **kwargs) if is_streaming: return StreamWrapper(result, handler, invocation) # type: ignore[arg-type] - wrapper = MessageWrapper(result, handler, invocation) # type: ignore[arg-type] + wrapper = MessageWrapper(result) # type: ignore[arg-type] + wrapper.extract_into(invocation) + handler.stop_llm(invocation) return wrapper.message except Exception as exc: handler.fail_llm( @@ -111,9 +123,16 @@ def traced_method( else params.model or "" ) + capture_content = should_capture_content() invocation = LLMInvocation( request_model=request_model, provider=ANTHROPIC, + input_messages=get_input_messages(params.messages) + if capture_content + else [], + system_instruction=get_system_instruction(params.system) + if capture_content + else [], attributes=attributes, ) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py index 49cd03be4c..7453bc5e83 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py @@ -16,6 +16,9 @@ from __future__ import annotations +import base64 +import json +import logging from dataclasses import dataclass from typing import TYPE_CHECKING, Any, Iterator, Optional, Sequence from urllib.parse import urlparse @@ -27,7 +30,24 @@ server_attributes as ServerAttributes, ) from opentelemetry.util.genai.handler import TelemetryHandler -from opentelemetry.util.genai.types import Error, LLMInvocation +from opentelemetry.util.genai.types import ( + Blob, + Error, + InputMessage, + LLMInvocation, + MessagePart, + OutputMessage, + Reasoning, + Text, + ToolCall, + ToolCallResponse, +) +from opentelemetry.util.genai.utils import ( + ContentCapturingMode, + get_content_capturing_mode, + is_experimental_mode, + should_emit_event, +) from opentelemetry.util.types import AttributeValue if TYPE_CHECKING: @@ -39,6 +59,8 @@ from anthropic.resources.messages import Messages from anthropic.types import Message, RawMessageStreamEvent +_logger = logging.getLogger(__name__) + @dataclass class MessageRequestParams: @@ -50,6 +72,8 @@ class MessageRequestParams: top_k: int | None = None top_p: float | None = None stop_sequences: Sequence[str] | None = None + messages: Any | None = None + system: Any | None = None _GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS = ( @@ -120,6 +144,206 @@ def _extract_usage_tokens( ) +def should_capture_content() -> bool: + """Return True when content conversion should be performed.""" + if not is_experimental_mode(): + return False + mode = get_content_capturing_mode() + if mode == ContentCapturingMode.NO_CONTENT: + return False + if mode == ContentCapturingMode.EVENT_ONLY and not should_emit_event(): + return False + return True + + +def _get_field(obj: Any, name: str, default: Any = None) -> Any: + if isinstance(obj, dict): + return obj.get(name, default) + return getattr(obj, name, default) + + +def _as_str(value: Any) -> str | None: + if value is None: + return None + if isinstance(value, str): + return value + return str(value) + + +def _to_dict_if_possible(value: Any) -> Any: + if isinstance(value, dict): + return value + if hasattr(value, "to_dict"): + to_dict = getattr(value, "to_dict") + if callable(to_dict): + try: + return to_dict() + except Exception: # pylint: disable=broad-exception-caught + return value + if hasattr(value, "__dict__"): + return dict(value.__dict__) + return value + + +def _decode_base64(data: str | None) -> bytes | None: + if not data: + return None + try: + return base64.b64decode(data) + except Exception: # pylint: disable=broad-exception-caught + return None + + +def _convert_content_block_to_part(content_block: Any) -> MessagePart | None: + block_type = _as_str(_get_field(content_block, "type")) + if block_type is None: + return None + + if block_type == "text": + text = _as_str(_get_field(content_block, "text")) + return Text(content=text or "") + + if block_type == "tool_use": + return ToolCall( + arguments=_to_dict_if_possible(_get_field(content_block, "input")), + name=_as_str(_get_field(content_block, "name")) or "", + id=_as_str(_get_field(content_block, "id")), + ) + + if block_type == "tool_result": + return ToolCallResponse( + response=_to_dict_if_possible(_get_field(content_block, "content")), + id=_as_str(_get_field(content_block, "tool_use_id")), + ) + + if block_type in ("thinking", "redacted_thinking"): + content = _as_str(_get_field(content_block, "thinking")) + if content is None: + content = _as_str(_get_field(content_block, "data")) + return Reasoning(content=content or "") + + if block_type in ("image", "audio", "video", "document", "file"): + source = _get_field(content_block, "source") + mime_type = _as_str(_get_field(source, "media_type")) + raw_data = _as_str(_get_field(source, "data")) + data = _decode_base64(raw_data) + if data is None: + return None + modality = _as_str(_get_field(content_block, "type")) or "file" + return Blob(mime_type=mime_type, modality=modality, content=data) + + return _to_dict_if_possible(content_block) + + +def _convert_content_to_parts(content: Any) -> list[MessagePart]: + if content is None: + return [] + if isinstance(content, str): + return [Text(content=content)] + if isinstance(content, list): + parts: list[MessagePart] = [] + for item in content: + part = _convert_content_block_to_part(item) + if part is not None: + parts.append(part) + return parts + part = _convert_content_block_to_part(content) + return [part] if part is not None else [] + + +def get_input_messages(messages: Any) -> list[InputMessage]: + if not isinstance(messages, list): + return [] + + result: list[InputMessage] = [] + for message in messages: + role = _as_str(_get_field(message, "role")) or "user" + parts = _convert_content_to_parts(_get_field(message, "content")) + result.append(InputMessage(role=role, parts=parts)) + return result + + +def get_system_instruction(system: Any) -> list[MessagePart]: + return _convert_content_to_parts(system) + + +def get_output_messages_from_message(message: Any) -> list[OutputMessage]: + if message is None: + return [] + + parts = _convert_content_to_parts(_get_field(message, "content")) + finish_reason = _normalize_finish_reason(_get_field(message, "stop_reason")) + return [ + OutputMessage( + role=_as_str(_get_field(message, "role")) or "assistant", + parts=parts, + finish_reason=finish_reason or "", + ) + ] + + +def _create_stream_block_state(content_block: Any) -> dict[str, Any]: + block_type = _as_str(_get_field(content_block, "type")) or "text" + state: dict[str, Any] = {"type": block_type} + if block_type == "text": + state["text"] = _as_str(_get_field(content_block, "text")) or "" + elif block_type == "tool_use": + state["id"] = _as_str(_get_field(content_block, "id")) + state["name"] = _as_str(_get_field(content_block, "name")) or "" + input_value = _get_field(content_block, "input") + state["input"] = _to_dict_if_possible(input_value) + state["input_json"] = "" + elif block_type in ("thinking", "redacted_thinking"): + state["thinking"] = _as_str(_get_field(content_block, "thinking")) or "" + return state + + +def _update_stream_block_state(state: dict[str, Any], delta: Any) -> None: + delta_type = _as_str(_get_field(delta, "type")) + if delta_type == "text_delta": + state["type"] = "text" + state["text"] = ( + f"{state.get('text', '')}" + f"{_as_str(_get_field(delta, 'text')) or ''}" + ) + return + if delta_type == "input_json_delta": + state["type"] = "tool_use" + state["input_json"] = ( + f"{state.get('input_json', '')}" + f"{_as_str(_get_field(delta, 'partial_json')) or ''}" + ) + return + if delta_type == "thinking_delta": + state["type"] = "thinking" + state["thinking"] = ( + f"{state.get('thinking', '')}" + f"{_as_str(_get_field(delta, 'thinking')) or ''}" + ) + + +def _stream_block_state_to_part(state: dict[str, Any]) -> MessagePart | None: + block_type = _as_str(state.get("type")) + if block_type == "text": + return Text(content=_as_str(state.get("text")) or "") + if block_type == "tool_use": + arguments: Any = state.get("input") + partial_json = _as_str(state.get("input_json")) + if partial_json: + try: + arguments = json.loads(partial_json) + except ValueError: + arguments = partial_json + return ToolCall( + arguments=arguments, + name=_as_str(state.get("name")) or "", + id=_as_str(state.get("id")), + ) + if block_type in ("thinking", "redacted_thinking"): + return Reasoning(content=_as_str(state.get("thinking")) or "") + return None + + # Use parameter signature from # https://github.com/anthropics/anthropic-sdk-python/blob/9b5ab24ba17bcd5e762e5a5fd69bb3c17b100aaa/src/anthropic/resources/messages/messages.py#L896 # https://github.com/anthropics/anthropic-sdk-python/blob/9b5ab24ba17bcd5e762e5a5fd69bb3c17b100aaa/src/anthropic/resources/messages/messages.py#L963 @@ -154,6 +378,8 @@ def extract_params( # pylint: disable=too-many-locals top_p=top_p, top_k=top_k, stop_sequences=stop_sequences, + messages=messages, + system=system, ) @@ -229,19 +455,11 @@ class MessageWrapper: the span immediately since the response is complete. """ - def __init__( - self, - message: "Message", - handler: TelemetryHandler, - invocation: LLMInvocation, - ): + def __init__(self, message: "Message"): self._message = message - self._extract_and_finalize(handler, invocation) - def _extract_and_finalize( - self, handler: TelemetryHandler, invocation: LLMInvocation - ) -> None: - """Extract response data and finalize the span.""" + def extract_into(self, invocation: LLMInvocation) -> None: + """Extract response data into the invocation.""" if self._message.model: invocation.response_model_name = self._message.model @@ -270,7 +488,10 @@ def _extract_and_finalize( _GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS ] = cache_read_input_tokens - handler.stop_llm(invocation) + if should_capture_content(): + invocation.output_messages = get_output_messages_from_message( + self._message + ) @property def message(self) -> "Message": @@ -303,6 +524,8 @@ def __init__( self._output_tokens: Optional[int] = None self._cache_creation_input_tokens: Optional[int] = None self._cache_read_input_tokens: Optional[int] = None + self._capture_content = should_capture_content() + self._content_blocks: dict[int, dict[str, Any]] = {} self._finalized = False def _update_usage(self, usage: Any | None) -> None: @@ -343,6 +566,19 @@ def _process_chunk(self, chunk: "RawMessageStreamEvent") -> None: # message_delta contains usage with output_tokens (and may repeat input_tokens) usage = getattr(chunk, "usage", None) self._update_usage(usage) + elif self._capture_content and chunk.type == "content_block_start": + index = _get_field(chunk, "index") + content_block = _get_field(chunk, "content_block") + if isinstance(index, int): + self._content_blocks[index] = _create_stream_block_state( + content_block + ) + elif self._capture_content and chunk.type == "content_block_delta": + index = _get_field(chunk, "index") + delta = _get_field(chunk, "delta") + if isinstance(index, int) and delta is not None: + block = self._content_blocks.setdefault(index, {}) + _update_stream_block_state(block, delta) def _finalize_invocation(self) -> None: """Update invocation with collected data and stop the span.""" @@ -369,6 +605,20 @@ def _finalize_invocation(self) -> None: _GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS ] = self._cache_read_input_tokens + if self._capture_content and self._content_blocks: + parts = [] + for index in sorted(self._content_blocks): + part = _stream_block_state_to_part(self._content_blocks[index]) + if part is not None: + parts.append(part) + self._invocation.output_messages = [ + OutputMessage( + role="assistant", + parts=parts, + finish_reason=self._stop_reason or "", + ) + ] + self._handler.stop_llm(self._invocation) def __iter__(self) -> "StreamWrapper": @@ -498,6 +748,13 @@ def _extract_telemetry_from_stream(self) -> None: self._invocation.attributes[ _GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS ] = cache_read_input_tokens + if should_capture_content(): + self._invocation.output_messages = ( + get_output_messages_from_message(final_message) + ) except Exception: # pylint: disable=broad-exception-caught # If we can't get the final message, we still want to end the span - pass + _logger.warning( + "Failed to extract telemetry from Anthropic MessageStream final message.", + exc_info=True, + ) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml index e8fe735c47..be79ed38ed 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml @@ -267,4 +267,406 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_019X4aWwBgmn42vLbcKV1qQh","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cbfd2c778c2269c-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Wed, 11 Feb 2026 00:45:26 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T00:45:25Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T00:45:25Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T00:45:25Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T00:45:25Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY1MgZhWFdBJcfgxAcyWK + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1180' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01JNAaVLt4SnAKmdQyPanbek","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cc0d11f0b2997d5-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Wed, 11 Feb 2026 03:39:03 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T03:39:02Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T03:39:02Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T03:39:03Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T03:39:02Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY1avWRiNqSZhMGCEtyuE + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '996' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01Wer2xYPqQ9zRHAieCRCtkn","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}} + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cc0d5d56e2c1705-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Wed, 11 Feb 2026 03:42:16 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T03:42:15Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T03:42:15Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T03:42:16Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T03:42:15Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY1bAjhpBL3zGuBYmG9c4 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1047' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml index a9c4c98c5b..29e83d54d2 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml @@ -920,4 +920,298 @@ interactions: status: code: 404 message: Not Found +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Hello" + } + ], + "model": "invalid-model-name" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '94' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "type": "error", + "error": { + "type": "not_found_error", + "message": "model: invalid-model-name" + }, + "request_id": "req_011CY1MfySypEhzBWMDLVBss" + } + headers: + CF-RAY: + - 9cbfd2956f048c2d-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Wed, 11 Feb 2026 00:45:17 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + cf-cache-status: + - DYNAMIC + content-length: + - '133' + request-id: + - req_011CY1MfySypEhzBWMDLVBss + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '81' + x-should-retry: + - 'false' + status: + code: 404 + message: Not Found +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Hello" + } + ], + "model": "invalid-model-name" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '94' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "type": "error", + "error": { + "type": "not_found_error", + "message": "model: invalid-model-name" + }, + "request_id": "req_011CY1auecJy4eAmB9yJCs65" + } + headers: + CF-RAY: + - 9cc0d0d61bc780d9-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Wed, 11 Feb 2026 03:38:51 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + cf-cache-status: + - DYNAMIC + content-length: + - '133' + request-id: + - req_011CY1auecJy4eAmB9yJCs65 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '165' + x-should-retry: + - 'false' + status: + code: 404 + message: Not Found +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Hello" + } + ], + "model": "invalid-model-name" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '94' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "type": "error", + "error": { + "type": "not_found_error", + "message": "model: invalid-model-name" + }, + "request_id": "req_011CY1b9bzwEJaSGKv2SnKNe" + } + headers: + CF-RAY: + - 9cc0d57569c8acc5-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Wed, 11 Feb 2026 03:42:00 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + cf-cache-status: + - DYNAMIC + content-length: + - '133' + request-id: + - req_011CY1b9bzwEJaSGKv2SnKNe + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '49' + x-should-retry: + - 'false' + status: + code: 404 + message: Not Found version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml index 3eb64c25e4..97d13f0966 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml @@ -1495,4 +1495,418 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '117' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_015udupaxNYisb19LJvnZxJc", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello!" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 13, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 5, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cbfd259be8d7ac0-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Wed, 11 Feb 2026 00:45:08 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T00:45:08Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T00:45:08Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T00:45:07Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T00:45:08Z' + cf-cache-status: + - DYNAMIC + content-length: + - '441' + request-id: + - req_011CY1MfGaLewP6aLtFmrcRT + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1051' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '117' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01YVqgfLP7JT2f6Hd8R6ZfjV", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello!" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 13, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 5, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cc0d0985cd01c6b-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Wed, 11 Feb 2026 03:38:42 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T03:38:42Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T03:38:42Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T03:38:41Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T03:38:42Z' + cf-cache-status: + - DYNAMIC + content-length: + - '441' + request-id: + - req_011CY1atvJ6mBthoAaepY2DL + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1143' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '117' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_015aToGJFxMx7DiBQ9FjP2zM", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello." + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 13, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 5, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cc0d53b79f7da80-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Wed, 11 Feb 2026 03:41:52 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T03:41:52Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T03:41:52Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T03:41:51Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T03:41:52Z' + cf-cache-status: + - DYNAMIC + content-length: + - '441' + request-id: + - req_011CY1b8vPCXdC5TtHiX5tbV + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1044' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml new file mode 100644 index 0000000000..a42a6cceed --- /dev/null +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml @@ -0,0 +1,1912 @@ +interactions: +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-3-5-sonnet-20241022" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '128' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python + x-api-key: + - test_anthropic_api_key + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "id": "msg_01XFDUDYJgAACzvnptvVoYEL", + "type": "message", + "role": "assistant", + "model": "claude-3-5-sonnet-20241022", + "content": [ + { + "type": "text", + "text": "Hello!" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 14, + "output_tokens": 4 + } + } + headers: + Connection: + - keep-alive + Content-Type: + - application/json + Date: + - Mon, 15 Dec 2024 10:00:00 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + content-length: + - '350' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-3-5-sonnet-20241022" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '119' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "type": "error", + "error": { + "type": "authentication_error", + "message": "invalid x-api-key" + }, + "request_id": "req_011CX88X7DM3SrsuuERgZeYJ" + } + headers: + CF-RAY: + - 9be0e0315fa2a02c-EWR + Connection: + - keep-alive + Content-Length: + - '130' + Content-Type: + - application/json + Date: + - Wed, 14 Jan 2026 23:22:30 GMT + Server: + - cloudflare + X-Robots-Tag: + - none + cf-cache-status: + - DYNAMIC + request-id: + - req_011CX88X7DM3SrsuuERgZeYJ + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '13' + x-should-retry: + - 'false' + status: + code: 401 + message: Unauthorized +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-3-5-sonnet-20241022" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '119' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "type": "error", + "error": { + "type": "invalid_request_error", + "message": "Your credit balance is too low to access the Anthropic API. Please go to Plans & Billing to upgrade or purchase credits." + }, + "request_id": "req_011CX88Zakc7NS5rDAkMMK45" + } + headers: + CF-RAY: + - 9be0e1032e73ace5-EWR + Connection: + - keep-alive + Content-Length: + - '234' + Content-Type: + - application/json + Date: + - Wed, 14 Jan 2026 23:23:03 GMT + Server: + - cloudflare + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + cf-cache-status: + - DYNAMIC + request-id: + - req_011CX88Zakc7NS5rDAkMMK45 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '30' + x-should-retry: + - 'false' + status: + code: 400 + message: Bad Request +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-3-5-sonnet-20241022" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '119' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "type": "error", + "error": { + "type": "invalid_request_error", + "message": "Your credit balance is too low to access the Anthropic API. Please go to Plans & Billing to upgrade or purchase credits." + }, + "request_id": "req_011CX88qYh2YvHnk7Hp8vCR7" + } + headers: + CF-RAY: + - 9be0e64cc92eb4c6-EWR + Connection: + - keep-alive + Content-Length: + - '234' + Content-Type: + - application/json + Date: + - Wed, 14 Jan 2026 23:26:40 GMT + Server: + - cloudflare + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + cf-cache-status: + - DYNAMIC + request-id: + - req_011CX88qYh2YvHnk7Hp8vCR7 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '20' + x-should-retry: + - 'false' + status: + code: 400 + message: Bad Request +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-3-5-sonnet-20241022" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '119' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "type": "error", + "error": { + "type": "not_found_error", + "message": "model: claude-3-5-sonnet-20241022" + }, + "request_id": "req_011CX89Wba1H8DoNZMAq5M9M" + } + headers: + CF-RAY: + - 9be0f33baa01cdf0-EWR + Connection: + - keep-alive + Content-Type: + - application/json + Date: + - Wed, 14 Jan 2026 23:35:29 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + cf-cache-status: + - DYNAMIC + content-length: + - '141' + request-id: + - req_011CX89Wba1H8DoNZMAq5M9M + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '28' + x-should-retry: + - 'false' + status: + code: 404 + message: Not Found +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '117' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01ChhLEFb4TSQWHpQzFqEQsj", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello!" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 13, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 5, + "service_tier": "standard" + } + } + headers: + CF-RAY: + - 9be0f55b2b560866-EWR + Connection: + - keep-alive + Content-Type: + - application/json + Date: + - Wed, 14 Jan 2026 23:36:58 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '30000' + anthropic-ratelimit-input-tokens-remaining: + - '30000' + anthropic-ratelimit-input-tokens-reset: + - '2026-01-14T23:36:58Z' + anthropic-ratelimit-output-tokens-limit: + - '8000' + anthropic-ratelimit-output-tokens-remaining: + - '8000' + anthropic-ratelimit-output-tokens-reset: + - '2026-01-14T23:36:58Z' + anthropic-ratelimit-requests-limit: + - '50' + anthropic-ratelimit-requests-remaining: + - '49' + anthropic-ratelimit-requests-reset: + - '2026-01-14T23:36:58Z' + anthropic-ratelimit-tokens-limit: + - '38000' + anthropic-ratelimit-tokens-remaining: + - '38000' + anthropic-ratelimit-tokens-reset: + - '2026-01-14T23:36:58Z' + cf-cache-status: + - DYNAMIC + content-length: + - '409' + request-id: + - req_011CX89d1Mu8qapBc5y9KdXf + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1596' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '117' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01W7B22k9o9QrCqiEWmU1v9G", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello!" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 13, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 5, + "service_tier": "standard" + } + } + headers: + CF-RAY: + - 9be0f5d0cffcdcde-EWR + Connection: + - keep-alive + Content-Type: + - application/json + Date: + - Wed, 14 Jan 2026 23:37:17 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '30000' + anthropic-ratelimit-input-tokens-remaining: + - '30000' + anthropic-ratelimit-input-tokens-reset: + - '2026-01-14T23:37:16Z' + anthropic-ratelimit-output-tokens-limit: + - '8000' + anthropic-ratelimit-output-tokens-remaining: + - '8000' + anthropic-ratelimit-output-tokens-reset: + - '2026-01-14T23:37:17Z' + anthropic-ratelimit-requests-limit: + - '50' + anthropic-ratelimit-requests-remaining: + - '49' + anthropic-ratelimit-requests-reset: + - '2026-01-14T23:37:16Z' + anthropic-ratelimit-tokens-limit: + - '38000' + anthropic-ratelimit-tokens-remaining: + - '38000' + anthropic-ratelimit-tokens-reset: + - '2026-01-14T23:37:16Z' + cf-cache-status: + - DYNAMIC + content-length: + - '409' + request-id: + - req_011CX89ePqXjam4ByzovDWC6 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1516' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '117' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01MpMMdwiz43MhCffJBjWRZP", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello!" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 13, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 5, + "service_tier": "standard" + } + } + headers: + CF-RAY: + - 9be0f7a98b01b734-EWR + Connection: + - keep-alive + Content-Type: + - application/json + Date: + - Wed, 14 Jan 2026 23:38:33 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '30000' + anthropic-ratelimit-input-tokens-remaining: + - '30000' + anthropic-ratelimit-input-tokens-reset: + - '2026-01-14T23:38:33Z' + anthropic-ratelimit-output-tokens-limit: + - '8000' + anthropic-ratelimit-output-tokens-remaining: + - '8000' + anthropic-ratelimit-output-tokens-reset: + - '2026-01-14T23:38:33Z' + anthropic-ratelimit-requests-limit: + - '50' + anthropic-ratelimit-requests-remaining: + - '49' + anthropic-ratelimit-requests-reset: + - '2026-01-14T23:38:32Z' + anthropic-ratelimit-tokens-limit: + - '38000' + anthropic-ratelimit-tokens-remaining: + - '38000' + anthropic-ratelimit-tokens-reset: + - '2026-01-14T23:38:33Z' + cf-cache-status: + - DYNAMIC + content-length: + - '409' + request-id: + - req_011CX89jyLYwphKuArFEcRij + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1970' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '117' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01CuxDqMnML7sFP6212a2j1b", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello!" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 13, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 5, + "service_tier": "standard" + } + } + headers: + CF-RAY: + - 9c72cec25ed742e8-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Sun, 01 Feb 2026 16:25:58 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '30000' + anthropic-ratelimit-input-tokens-remaining: + - '30000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-01T16:25:58Z' + anthropic-ratelimit-output-tokens-limit: + - '8000' + anthropic-ratelimit-output-tokens-remaining: + - '8000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-01T16:25:58Z' + anthropic-ratelimit-requests-limit: + - '50' + anthropic-ratelimit-requests-remaining: + - '49' + anthropic-ratelimit-requests-reset: + - '2026-02-01T16:25:58Z' + anthropic-ratelimit-tokens-limit: + - '38000' + anthropic-ratelimit-tokens-remaining: + - '38000' + anthropic-ratelimit-tokens-reset: + - '2026-02-01T16:25:58Z' + cf-cache-status: + - DYNAMIC + content-length: + - '409' + request-id: + - req_011CXhfKErNmxjcBp7mFqHdT + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1389' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '117' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "type": "error", + "error": { + "type": "authentication_error", + "message": "invalid x-api-key" + }, + "request_id": "req_011CXwgSWJgAcLFshZ7pUbDp" + } + headers: + CF-RAY: + - 9cafd27f580a0f3b-EWR + Connection: + - keep-alive + Content-Length: + - '130' + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 09 Feb 2026 02:09:01 GMT + Server: + - cloudflare + X-Robots-Tag: + - none + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXwgSWJgAcLFshZ7pUbDp + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '8' + x-should-retry: + - 'false' + status: + code: 401 + message: Unauthorized +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '117' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_015EPMmo3gLS7YCe6TUktZb2", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello!" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 13, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 5, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cafd43a2e3c434b-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 09 Feb 2026 02:10:13 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-09T02:10:13Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-09T02:10:13Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-09T02:10:12Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-09T02:10:13Z' + cf-cache-status: + - DYNAMIC + content-length: + - '441' + request-id: + - req_011CXwgXjCCuSo8UFXeQUi1U + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1414' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '117' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01LoJKhArRbNU3Y8k1CfjFy7", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello!" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 13, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 5, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cb07ec4ddfb80d3-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 09 Feb 2026 04:06:38 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-09T04:06:38Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-09T04:06:38Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-09T04:06:37Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-09T04:06:38Z' + cf-cache-status: + - DYNAMIC + content-length: + - '441' + request-id: + - req_011CXwqQeivmMsTHWupX7Guh + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1242' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '117' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01K78vKWGf2VjiHfBeMUqzLd", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello!" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 13, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 5, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cb889c988ef41af-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Tue, 10 Feb 2026 03:32:16 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-10T03:32:15Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-10T03:32:16Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-10T03:32:15Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-10T03:32:15Z' + cf-cache-status: + - DYNAMIC + content-length: + - '441' + request-id: + - req_011CXygbXLC4RW3sUycx3X7f + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1103' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '117' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01S7Kzp6RYADbosUzujiwSvK", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello!" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 13, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 5, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cbfd2622e1942df-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Wed, 11 Feb 2026 00:45:09 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T00:45:09Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T00:45:09Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T00:45:08Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T00:45:09Z' + cf-cache-status: + - DYNAMIC + content-length: + - '441' + request-id: + - req_011CY1MfNP672aPFNTMycTox + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '977' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '117' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01RDp61PCLrmSt6BgktY8ssL", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello!" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 13, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 5, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cc0d0a1da6b0ab9-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Wed, 11 Feb 2026 03:38:44 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T03:38:43Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T03:38:43Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T03:38:42Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T03:38:43Z' + cf-cache-status: + - DYNAMIC + content-length: + - '441' + request-id: + - req_011CY1au2q1TkDQD8f3szYsW + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1126' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '117' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01EDcFRbbaDj8g97D8EbVrju", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello!" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 13, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 5, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cc0d543eff2db49-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Wed, 11 Feb 2026 03:41:53 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T03:41:53Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T03:41:53Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T03:41:52Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T03:41:53Z' + cf-cache-status: + - DYNAMIC + content-length: + - '441' + request-id: + - req_011CY1b92ADR8pULetRW4uPf + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1079' + status: + code: 200 + message: OK +version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml new file mode 100644 index 0000000000..def115bd64 --- /dev/null +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml @@ -0,0 +1,250 @@ +interactions: +- request: + body: |- + { + "max_tokens": 16000, + "messages": [ + { + "role": "user", + "content": "What is 17*19? Think first." + } + ], + "model": "claude-sonnet-4-20250514", + "thinking": { + "type": "enabled", + "budget_tokens": 10000 + } + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '195' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01ThinkingTest123", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "thinking", + "thinking": "Let me calculate 17 times 19. I can break this down: 17 * 19 = 17 * 20 - 17 = 340 - 17 = 323." + }, + { + "type": "text", + "text": "17 \u00d7 19 = **323**" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 18, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "output_tokens": 42, + "service_tier": "standard" + } + } + headers: + Connection: + - keep-alive + Content-Type: + - application/json + Date: + - Wed, 11 Feb 2026 04:00:00 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + content-length: + - '580' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 16000, + "messages": [ + { + "role": "user", + "content": "What is 17*19? Think first." + } + ], + "model": "claude-sonnet-4-20250514", + "thinking": { + "type": "enabled", + "budget_tokens": 10000 + } + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '176' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01R2Wyw6D8vK1yD6jBK1g9C7", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "thinking", + "thinking": "I need to calculate 17 * 19.\n\nLet me think about this step by step.\n\nOne way is to use the standard multiplication:\n17 * 19\n\nI can break this down:\n17 * 19 = 17 * (20 - 1) = 17 * 20 - 17 * 1 = 340 - 17 = 323\n\nLet me double-check this another way:\n19 * 17 = 19 * (10 + 7) = 19 * 10 + 19 * 7 = 190 + 133\n\nNow I need to calculate 19 * 7:\n19 * 7 = (20 - 1) * 7 = 20 * 7 - 1 * 7 = 140 - 7 = 133\n\nSo 19 * 17 = 190 + 133 = 323\n\nBoth methods give me 323, so that should be correct.", + "signature": "EoIFCkYICxgCKkAzrBHkSvp2t+O6FeldCSOZG6sRsBctId9L5ZKp7KPHthia6QKTS11mYuN5Uyb2Yx4WV7FIHtbUSbkEqbPqnjRGEgxzQGA5fiVU00cGq0UaDLQ1BTDI8043Aw1W1CIwgE/ounmA8v9rxn+Pnyf0hdd0FvMOC57oedMKS8aAm8uf3hlbqAnYkvwf4SxHIbDXKukD/m9nFQLSY0yZBzfIoI8w9OMD3SldlcEo3HofmOq2huaOMBY6YZXY5MDulFXMJiGHS267Le+NVB0OmS5r3dih0dIuUXnpgP9DXH8YuP4QSVwFnmDtfWMQWGx8FzpaH2Miq/JWp1wN2Ulu7vFxGnnt9uOORCj0LXII9QAXBmNVEFGY8eZTO9OjvZY6AGswnlOWrlQZKzIkt9wVpCprcOcFarIhxnQhNIR115PG+iH4OhedCuXzKVaD/MyEV2k5CIdpHZFLWz2y2xyUQV5XZv3m0nXB4u+GlRbHMTLcl5Do5LbhcKiU30PLxdwsawGN2LKJY+n2fjrQjX7xcmEQvStOOTlNzCrAd63H8sa+GzVpFGd3wnG3RK5bOxMI2GuNXKI1XOHGd1ODqQcjm67nB1vmUkR8BVbm94k5u4hspYCiRePqGtfkIFyMa4W93YfFKszviMlOBHSGbEulQZhIoQ0e5+y7ftF5VtSJijGH93K5I4WrVI+/pHh5j5RsjUX7wIU+Zq3brBttE+mHZnGnSiB73m8qk0H/woW/9Ck83leRw2Zuy44U4Wto9gQaNaWRjq0AsUxhx9s6MqpOoNrDDjIKFpZHScMMU6AL9rKPinWwA581af5tCMXXQCg58+OUCyxKPBBYIXfqAswFGAE=" + }, + { + "type": "text", + "text": "I need to calculate 17 \u00d7 19.\n\nLet me use the distributive property to make this easier:\n17 \u00d7 19 = 17 \u00d7 (20 - 1) = 17 \u00d7 20 - 17 \u00d7 1 = 340 - 17 = 323\n\nLet me verify with another approach:\n19 \u00d7 17 = 19 \u00d7 (10 + 7) = 190 + (19 \u00d7 7) = 190 + 133 = 323\n\nTherefore, 17 \u00d7 19 = 323." + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 46, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 380, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cc0d5b61a4c643e-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Wed, 11 Feb 2026 03:42:15 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T03:42:11Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T03:42:15Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T03:42:11Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T03:42:11Z' + cf-cache-status: + - DYNAMIC + content-length: + - '2129' + request-id: + - req_011CY1bANHDGDVtTXtSLNAXN + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '4812' + status: + code: 200 + message: OK +version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml new file mode 100644 index 0000000000..bec58c7521 --- /dev/null +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml @@ -0,0 +1,328 @@ +interactions: +- request: + body: |- + { + "max_tokens": 256, + "messages": [ + { + "role": "user", + "content": "What is the weather in SF?" + } + ], + "model": "claude-sonnet-4-20250514", + "tool_choice": { + "type": "tool", + "name": "get_weather" + }, + "tools": [ + { + "name": "get_weather", + "description": "Get weather by city", + "input_schema": { + "type": "object", + "properties": { + "city": { + "type": "string" + } + }, + "required": [ + "city" + ] + } + } + ] + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '334' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_013sXaTjCSez5pHDYPvRromP", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "tool_use", + "id": "toolu_01DKptrcYW8pczGw82pgshof", + "name": "get_weather", + "input": { + "city": "San Francisco" + } + } + ], + "stop_reason": "tool_use", + "stop_sequence": null, + "usage": { + "input_tokens": 386, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 34, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cc0d10dda96cb2e-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Wed, 11 Feb 2026 03:39:02 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T03:39:02Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T03:39:02Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T03:39:00Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T03:39:02Z' + cf-cache-status: + - DYNAMIC + content-length: + - '523' + request-id: + - req_011CY1avJnEG3TGWYKaBxHSZ + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '2216' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 256, + "messages": [ + { + "role": "user", + "content": "What is the weather in SF?" + } + ], + "model": "claude-sonnet-4-20250514", + "tool_choice": { + "type": "tool", + "name": "get_weather" + }, + "tools": [ + { + "name": "get_weather", + "description": "Get weather by city", + "input_schema": { + "type": "object", + "properties": { + "city": { + "type": "string" + } + }, + "required": [ + "city" + ] + } + } + ] + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '334' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01WD8aRCAvkA54hdDwKKn9HH", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "tool_use", + "id": "toolu_01RdT9XeaCzrDHtCMgjWntbB", + "name": "get_weather", + "input": { + "city": "San Francisco" + } + } + ], + "stop_reason": "tool_use", + "stop_sequence": null, + "usage": { + "input_tokens": 386, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 34, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cc0d5ad481f3788-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Wed, 11 Feb 2026 03:42:10 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T03:42:10Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T03:42:10Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T03:42:09Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T03:42:10Z' + cf-cache-status: + - DYNAMIC + content-length: + - '523' + request-id: + - req_011CY1bAGDahii5NHGYK85GR + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1203' + status: + code: 200 + message: OK +version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml index 515ecb8d79..3e9d575e51 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml @@ -1170,4 +1170,418 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '102' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01QkMfxdENJsSAdg89asyjPS", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hi! How are you doing today?" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 10, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 11, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cbfd28298bc8465-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Wed, 11 Feb 2026 00:45:15 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T00:45:15Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T00:45:15Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T00:45:14Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T00:45:15Z' + cf-cache-status: + - DYNAMIC + content-length: + - '464' + request-id: + - req_011CY1MfkZLeSpsrk6Wnhb42 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1311' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '102' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01KpPuYdUUBsFSMC4YFAhejS", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hi! How are you doing today?" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 10, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 11, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cc0d0c49ffad826-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Wed, 11 Feb 2026 03:38:49 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T03:38:49Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T03:38:49Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T03:38:48Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T03:38:49Z' + cf-cache-status: + - DYNAMIC + content-length: + - '464' + request-id: + - req_011CY1auSb1ACRDz6yT5P3Du + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1212' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '102' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01W5pBhYzMpo9pNVuKeQjc9E", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hi! How are you doing today?" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 10, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 11, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cc0d562eb7eb4c6-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Wed, 11 Feb 2026 03:41:58 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T03:41:58Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T03:41:58Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T03:41:57Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T03:41:58Z' + cf-cache-status: + - DYNAMIC + content-length: + - '464' + request-id: + - req_011CY1b9PNRF9QtcWWkZgDbM + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1338' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml index 868565b3cc..af9c51def7 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml @@ -630,4 +630,406 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01DEXdKjQxYs1URcxvKjQEwq","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cbfd2977ad0a10a-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Wed, 11 Feb 2026 00:45:18 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T00:45:17Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T00:45:17Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T00:45:17Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T00:45:17Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY1Mfzr54eUeix1eS7ZhW + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '780' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01HGay48sqJhc56SNCJjCoiz","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cc0d0d8983c1016-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Wed, 11 Feb 2026 03:38:52 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T03:38:51Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T03:38:51Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T03:38:51Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T03:38:51Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY1augFnKZsDhThMeaNLy + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1156' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_011weMCgsfAXGexR1Gq7hgjC","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cc0d5772b0ad123-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Wed, 11 Feb 2026 03:42:01 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T03:42:00Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T03:42:00Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T03:42:00Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T03:42:00Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY1b9dEMJJx7nop7Qrz56 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1006' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml new file mode 100644 index 0000000000..a2af7d8333 --- /dev/null +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml @@ -0,0 +1,1035 @@ +interactions: +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01L4V8w9WcTqy9XqeSGMvtmU","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard"}}} + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"}} + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9c72cefdb96f5e71-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Sun, 01 Feb 2026 16:26:07 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '30000' + anthropic-ratelimit-input-tokens-remaining: + - '30000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-01T16:26:06Z' + anthropic-ratelimit-output-tokens-limit: + - '8000' + anthropic-ratelimit-output-tokens-remaining: + - '8000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-01T16:26:06Z' + anthropic-ratelimit-requests-limit: + - '50' + anthropic-ratelimit-requests-remaining: + - '49' + anthropic-ratelimit-requests-reset: + - '2026-02-01T16:26:07Z' + anthropic-ratelimit-tokens-limit: + - '38000' + anthropic-ratelimit-tokens-remaining: + - '38000' + anthropic-ratelimit-tokens-reset: + - '2026-02-01T16:26:06Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXhfKwTQ5cLbB8jmLW9Td + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1221' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "type": "error", + "error": { + "type": "authentication_error", + "message": "invalid x-api-key" + }, + "request_id": "req_011CXwgShB2Qa8WVkqeYfXig" + } + headers: + CF-RAY: + - 9cafd28f4a9a43cb-EWR + Connection: + - keep-alive + Content-Length: + - '130' + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 09 Feb 2026 02:09:03 GMT + Server: + - cloudflare + X-Robots-Tag: + - none + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXwgShB2Qa8WVkqeYfXig + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '8' + x-should-retry: + - 'false' + status: + code: 401 + message: Unauthorized +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01NPELKwEsJZ8JkGYmWb1dNZ","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cafd46b1f6bda48-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Mon, 09 Feb 2026 02:10:21 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-09T02:10:20Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-09T02:10:20Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-09T02:10:20Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-09T02:10:20Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXwgYJharaeaLQLFUgtAA + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1032' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01UM7FKi4sQ9AuD6jidmAKn9","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}} + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"}} + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cb07ef75f9041d2-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Mon, 09 Feb 2026 04:06:46 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-09T04:06:45Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-09T04:06:45Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-09T04:06:45Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-09T04:06:45Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXwqRFJ44wMGtnsUvEm3R + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '911' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_012oHhogVPBokZdYPVAew9X9","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cb889fc19275642-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Tue, 10 Feb 2026 03:32:24 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-10T03:32:23Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-10T03:32:23Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-10T03:32:23Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-10T03:32:23Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXygc7sLZXhoTvZSQiyNf + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1093' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01UzxnH6yLX2hYsuaswms5M5","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cbfd29eec70659d-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Wed, 11 Feb 2026 00:45:19 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T00:45:18Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T00:45:18Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T00:45:18Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T00:45:18Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY1Mg5vfKFrFYmCmCEgn1 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '815' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01JhhD5JShFDfmFGe5wKmgCg","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cc0d0e1e97edb40-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Wed, 11 Feb 2026 03:38:54 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T03:38:53Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T03:38:53Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T03:38:53Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T03:38:53Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY1aundm4FDfWaP7mx3Z3 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1156' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_0188ofvsbrF4hnB1ctEazjQn","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"}} + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cc0d57fb8d40f93-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Wed, 11 Feb 2026 03:42:02 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T03:42:02Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T03:42:02Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T03:42:02Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T03:42:02Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY1b9j46Pwx2pYJKJ9MjW + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '785' + status: + code: 200 + message: OK +version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml index 611c3f24ca..eeea24aa9f 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml @@ -669,4 +669,427 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '116' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01NZGnKhEzSZicN3pG2orWNg","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"! How"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are you doing today?"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cbfd2a5ff6b3ee0-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Wed, 11 Feb 2026 00:45:20 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T00:45:19Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T00:45:19Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T00:45:19Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T00:45:19Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY1MgAmsDhdF2P7xHz91Y + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1248' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '116' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01EUUGDrivPbs3wQZuCWKegE","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" there! How"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" you doing today?"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0} + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":12} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cc0d0eb99224276-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Wed, 11 Feb 2026 03:38:55 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T03:38:54Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T03:38:54Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T03:38:54Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T03:38:54Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY1auuH7E9b5k7Kmucga8 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '927' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '116' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01Ddsijy47vScG6hRZMFrzTD","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"! How"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are you doing today?"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cc0d5872f8058c1-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Wed, 11 Feb 2026 03:42:04 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T03:42:03Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T03:42:03Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T03:42:03Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T03:42:03Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY1b9pAvKt35Cpcy14vgn + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1220' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml index 240f756e9f..9a4252f562 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml @@ -1170,4 +1170,418 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Count to 5." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '106' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_013MNsLPFCh6U1ktNYd1w1Kt", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "1, 2, 3, 4, 5" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 12, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 17, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cbfd2729fbfc3ab-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Wed, 11 Feb 2026 00:45:13 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T00:45:13Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T00:45:13Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T00:45:11Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T00:45:13Z' + cf-cache-status: + - DYNAMIC + content-length: + - '449' + request-id: + - req_011CY1MfZbXeLTM8bkcxvgvd + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '2317' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Count to 5." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '106' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01TZ2mzRLhFAZFMNDHjjgm3X", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "1\n2\n3\n4\n5" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 12, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 13, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cc0d0ba3fead826-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Wed, 11 Feb 2026 03:38:48 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T03:38:47Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T03:38:48Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T03:38:46Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T03:38:47Z' + cf-cache-status: + - DYNAMIC + content-length: + - '449' + request-id: + - req_011CY1auKVNGfuc2JAZMRHYC + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1399' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Count to 5." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '106' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01KtEQPkubeVibsiUEWJGuQb", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "1, 2, 3, 4, 5" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 12, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 17, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cc0d5594b29438c-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Wed, 11 Feb 2026 03:41:57 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T03:41:57Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T03:41:57Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T03:41:56Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T03:41:57Z' + cf-cache-status: + - DYNAMIC + content-length: + - '449' + request-id: + - req_011CY1b9GoXNd1TjZRyYLyFT + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1224' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml index 03229a8dff..2766c0a8ac 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml @@ -1230,4 +1230,436 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 50, + "messages": [ + { + "role": "user", + "content": "Say hello." + } + ], + "model": "claude-sonnet-4-20250514", + "stop_sequences": [ + "STOP" + ], + "temperature": 0.7, + "top_k": 40, + "top_p": 0.9 + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '171' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01BzCQ8orpyan7Ystv5CgnyT", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello! It's nice to meet you. How are you doing today?" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 10, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 18, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cbfd269cf457cb1-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Wed, 11 Feb 2026 00:45:11 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T00:45:10Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T00:45:11Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T00:45:10Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T00:45:10Z' + cf-cache-status: + - DYNAMIC + content-length: + - '490' + request-id: + - req_011CY1MfTb88KBgprh7xpf5B + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1103' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 50, + "messages": [ + { + "role": "user", + "content": "Say hello." + } + ], + "model": "claude-sonnet-4-20250514", + "stop_sequences": [ + "STOP" + ], + "temperature": 0.7, + "top_k": 40, + "top_p": 0.9 + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '171' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_012DY733SL6BQu73vs85NbyT", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello! How are you doing today?" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 10, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 11, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cc0d0ab09cbf569-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Wed, 11 Feb 2026 03:38:46 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T03:38:46Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T03:38:46Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T03:38:44Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T03:38:46Z' + cf-cache-status: + - DYNAMIC + content-length: + - '467' + request-id: + - req_011CY1au95YQ9YSXvsuERw3a + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '2153' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 50, + "messages": [ + { + "role": "user", + "content": "Say hello." + } + ], + "model": "claude-sonnet-4-20250514", + "stop_sequences": [ + "STOP" + ], + "temperature": 0.7, + "top_k": 40, + "top_p": 0.9 + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '171' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01G1eYYnJGCf4h51N85Rm5Nh", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello! It's nice to meet you. How are you doing today?" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 10, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 18, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cc0d54c89c65017-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Wed, 11 Feb 2026 03:41:55 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T03:41:55Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T03:41:55Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T03:41:54Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T03:41:55Z' + cf-cache-status: + - DYNAMIC + content-length: + - '490' + request-id: + - req_011CY1b982gjPt4PyVaFsmtT + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1689' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml index fa0c618882..42cc1dc0e2 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml @@ -650,4 +650,418 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_014Rrw3BTA8R9AkwdwJ5rL7s","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cbfd2b7ddeaacc5-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Wed, 11 Feb 2026 00:45:23 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T00:45:22Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T00:45:22Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T00:45:22Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T00:45:22Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY1MgP15E4awNFDucwMoM + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '924' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01N6FeF1X4TkKZwjRVjXi9t6","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cc0d0fc5d98c338-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Wed, 11 Feb 2026 03:38:58 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T03:38:57Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T03:38:57Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T03:38:57Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T03:38:57Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY1av6kBJesRpLh98yFpz + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1012' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01RHawB9h7Wc5byj1Lnw87nh","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cc0d59a3b27f534-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Wed, 11 Feb 2026 03:42:07 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T03:42:06Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T03:42:06Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T03:42:06Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T03:42:06Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY1bA3Djmo1h7ryn18d1H + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '921' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_captures_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_captures_content.yaml new file mode 100644 index 0000000000..d7dc48ea75 --- /dev/null +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_captures_content.yaml @@ -0,0 +1,1067 @@ +interactions: +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01UtyS6wd4yzRVPNssPV1Wgg","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5}} + + event: message_stop + data: {"type":"message_stop"} + + headers: + CF-RAY: + - 9c72cf18d90042d7-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Sun, 01 Feb 2026 16:26:11 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '30000' + anthropic-ratelimit-input-tokens-remaining: + - '30000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-01T16:26:10Z' + anthropic-ratelimit-output-tokens-limit: + - '8000' + anthropic-ratelimit-output-tokens-remaining: + - '8000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-01T16:26:10Z' + anthropic-ratelimit-requests-limit: + - '50' + anthropic-ratelimit-requests-remaining: + - '49' + anthropic-ratelimit-requests-reset: + - '2026-02-01T16:26:12Z' + anthropic-ratelimit-tokens-limit: + - '38000' + anthropic-ratelimit-tokens-remaining: + - '38000' + anthropic-ratelimit-tokens-reset: + - '2026-02-01T16:26:10Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXhfLG1cM5qTFLjqKqPof + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1157' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "type": "error", + "error": { + "type": "authentication_error", + "message": "invalid x-api-key" + }, + "request_id": "req_011CXwgSpckNmKSZ2zSSmGQe" + } + headers: + CF-RAY: + - 9cafd29a2a15edd5-EWR + Connection: + - keep-alive + Content-Length: + - '130' + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Mon, 09 Feb 2026 02:09:05 GMT + Server: + - cloudflare + X-Robots-Tag: + - none + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXwgSpckNmKSZ2zSSmGQe + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '11' + x-should-retry: + - 'false' + status: + code: 401 + message: Unauthorized +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01TYYPFFjh2MGYwMBT6dPtge","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cafd4877a208c99-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Mon, 09 Feb 2026 02:10:25 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-09T02:10:24Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-09T02:10:24Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-09T02:10:24Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-09T02:10:24Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXwgYe5evU3T1ocnZA3AN + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1116' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_013xhnC6x7oA5LvcJRG7U42t","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cb07f10cda0255d-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Mon, 09 Feb 2026 04:06:50 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-09T04:06:49Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-09T04:06:49Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-09T04:06:49Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-09T04:06:49Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXwqRYh4Vo9JgfndnBwzL + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1113' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01FSTci7pL3KTtDnAaqxTK7Z","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cb88a165a2fef9f-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Tue, 10 Feb 2026 03:32:29 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-10T03:32:27Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-10T03:32:27Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-10T03:32:27Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-10T03:32:27Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CXygcRs4PZeVP1JqvbGoZ + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1885' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01QHyqdCPMhKT8JybA83DdQn","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cbfd2bfacc59d36-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Wed, 11 Feb 2026 00:45:24 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T00:45:23Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T00:45:23Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T00:45:23Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T00:45:23Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY1MgUK4WEui52vVFk6jZ + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '899' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01Uu7K7FHX4eEwuhJ9CG7dWj","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"}} + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cc0d10508ea75b1-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Wed, 11 Feb 2026 03:38:59 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T03:38:58Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T03:38:58Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T03:38:58Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T03:38:58Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY1avCfNt24up33JfsVJk + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1035' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01GB8hHk17Jy8cwQrWdzTt7s","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5}} + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cc0d5a258613448-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Wed, 11 Feb 2026 03:42:09 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T03:42:08Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T03:42:08Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T03:42:08Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T03:42:08Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY1bA8qaVQbmaXKUc4KQX + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1373' + status: + code: 200 + message: OK +version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_double_exit_idempotent.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_double_exit_idempotent.yaml index 029d4c9ba4..2aa049385d 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_double_exit_idempotent.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_double_exit_idempotent.yaml @@ -137,4 +137,427 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hi in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '128' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01St2f8sJGdRzHasYXE727z9","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cbfd2e3ad93b17b-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Wed, 11 Feb 2026 00:45:30 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T00:45:29Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T00:45:29Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T00:45:29Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T00:45:29Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY1MgtxPEexPaMCpXEpxe + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '908' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hi in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '128' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01XvFruh8TJ8ArXQ3SDSXNFv","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}} + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cc0d1391f6d9b29-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Wed, 11 Feb 2026 03:39:08 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T03:39:07Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T03:39:07Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T03:39:07Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T03:39:07Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY1avpHkeBCQGAPkf7Hza + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1066' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hi in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '128' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01BoKfvVZrunqFtSBj4S7YkK","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"!"}} + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cc0d5f45d2f7c9f-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Wed, 11 Feb 2026 03:42:21 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T03:42:20Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T03:42:20Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T03:42:20Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T03:42:20Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY1bB6qoYvgAiop4p1XWm + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '859' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml index 33c11e637e..27709106ee 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml @@ -659,4 +659,424 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Count to 3." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '120' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_019HzaVnWRVFS8veS41f4TSp","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"1,"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" 2, 3."} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":12} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cbfd2db2f8eacc5-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Wed, 11 Feb 2026 00:45:29 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T00:45:28Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T00:45:28Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T00:45:28Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T00:45:28Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY1Mgo7u39EipqBZrvYQh + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '976' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Count to 3." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '120' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01To6kPeqvjM1M1mbJmc32nB","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"1,"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" 2, 3."} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":12} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cc0d1310d1e0cc0-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Wed, 11 Feb 2026 03:39:06 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T03:39:05Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T03:39:05Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T03:39:05Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T03:39:05Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY1avincJvVrcduD2TMkx + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '845' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Count to 3." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '120' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01X1qhGSJt1fAfBSigbNhMUq","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"1, 2, 3"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cc0d5eb5d181705-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Wed, 11 Feb 2026 03:42:20 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T03:42:19Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T03:42:19Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T03:42:19Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T03:42:19Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY1bAzgxzQ8YMScVDCeS1 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1024' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml index cf490e76b7..5b2fe688c7 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml @@ -704,4 +704,460 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 50, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514", + "temperature": 0.7, + "top_k": 40, + "top_p": 0.9, + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '156' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01DqGRL1X5HHQHC7bECxd7uF","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"!"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" How"}} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" you doing today?"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cbfd2d17c884289-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Wed, 11 Feb 2026 00:45:27 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T00:45:26Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T00:45:26Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T00:45:26Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T00:45:26Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY1MggXGvfEPvtvh1y9Rg + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1040' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 50, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514", + "temperature": 0.7, + "top_k": 40, + "top_p": 0.9, + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '156' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01HrgfLzAtLcSTFiSQE7RB4n","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"!"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" How"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are you doing today?"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cc0d1276eba6a52-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Wed, 11 Feb 2026 03:39:05 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T03:39:04Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T03:39:04Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T03:39:04Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T03:39:04Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY1avcAjvdWiJtaVA79ei + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1070' + status: + code: 200 + message: OK +- request: + body: |- + { + "max_tokens": 50, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514", + "temperature": 0.7, + "top_k": 40, + "top_p": 0.9, + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '156' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01DYfSiMg927w9EkviLFmji5","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}}} + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"!"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" How"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" you doing today?"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cc0d5de692cc327-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Wed, 11 Feb 2026 03:42:18 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-organization-id: + - 455ea6be-bd92-4199-83ec-0c6b39c5c169 + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-11T03:42:17Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-11T03:42:17Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-11T03:42:17Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-11T03:42:17Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY1bAqr9ecmPKhkrzFegW + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1084' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/conftest.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/conftest.py index 9f660d1fd4..0d4aa012b7 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/conftest.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/conftest.py @@ -22,6 +22,10 @@ import yaml from anthropic import Anthropic +from opentelemetry.instrumentation._semconv import ( + OTEL_SEMCONV_STABILITY_OPT_IN, + _OpenTelemetrySemanticConventionStability, +) from opentelemetry.instrumentation.anthropic import AnthropicInstrumentor from opentelemetry.sdk._logs import LoggerProvider from opentelemetry.sdk._logs.export import ( @@ -115,8 +119,12 @@ def vcr_config(): @pytest.fixture(scope="function") def instrument_no_content(tracer_provider, logger_provider, meter_provider): """Instrument Anthropic without content capture.""" + _OpenTelemetrySemanticConventionStability._initialized = False os.environ.update( - {OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT: "False"} + { + OTEL_SEMCONV_STABILITY_OPT_IN: "stable", + OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT: "NO_CONTENT", + } ) instrumentor = AnthropicInstrumentor() @@ -128,14 +136,19 @@ def instrument_no_content(tracer_provider, logger_provider, meter_provider): yield instrumentor os.environ.pop(OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT, None) + os.environ.pop(OTEL_SEMCONV_STABILITY_OPT_IN, None) instrumentor.uninstrument() @pytest.fixture(scope="function") def instrument_with_content(tracer_provider, logger_provider, meter_provider): """Instrument Anthropic with content capture enabled.""" + _OpenTelemetrySemanticConventionStability._initialized = False os.environ.update( - {OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT: "True"} + { + OTEL_SEMCONV_STABILITY_OPT_IN: "gen_ai_latest_experimental", + OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT: "SPAN_ONLY", + } ) instrumentor = AnthropicInstrumentor() instrumentor.instrument( @@ -146,6 +159,7 @@ def instrument_with_content(tracer_provider, logger_provider, meter_provider): yield instrumentor os.environ.pop(OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT, None) + os.environ.pop(OTEL_SEMCONV_STABILITY_OPT_IN, None) instrumentor.uninstrument() diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py index 9e809f6ad6..fe0781847d 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py @@ -14,6 +14,9 @@ """Tests for sync Messages.create instrumentation.""" +import json +import os +from pathlib import Path from types import SimpleNamespace import pytest @@ -111,6 +114,27 @@ def assert_span_attributes( # pylint: disable=too-many-arguments ) +def _load_span_messages(span, attribute): + value = span.attributes.get(attribute) + assert value is not None + assert isinstance(value, str) + parsed = json.loads(value) + assert isinstance(parsed, list) + return parsed + + +def _skip_if_cassette_missing_and_no_real_key(request): + cassette_path = ( + Path(__file__).parent / "cassettes" / f"{request.node.name}.yaml" + ) + api_key = os.getenv("ANTHROPIC_API_KEY") + if not cassette_path.exists() and api_key == "test_anthropic_api_key": + pytest.skip( + f"Cassette {cassette_path.name} is missing. " + "Set a real ANTHROPIC_API_KEY to record it." + ) + + @pytest.mark.vcr() def test_sync_messages_create_basic( span_exporter, anthropic_client, instrument_no_content @@ -139,6 +163,35 @@ def test_sync_messages_create_basic( ) +@pytest.mark.vcr() +def test_sync_messages_create_captures_content( + span_exporter, anthropic_client, instrument_with_content +): + """Test content capture on non-streaming create.""" + model = "claude-sonnet-4-20250514" + messages = [{"role": "user", "content": "Say hello in one word."}] + + anthropic_client.messages.create( + model=model, + max_tokens=100, + messages=messages, + ) + + spans = span_exporter.get_finished_spans() + assert len(spans) == 1 + span = spans[0] + + input_messages = _load_span_messages(span, GenAIAttributes.GEN_AI_INPUT_MESSAGES) + output_messages = _load_span_messages( + span, GenAIAttributes.GEN_AI_OUTPUT_MESSAGES + ) + + assert input_messages[0]["role"] == "user" + assert input_messages[0]["parts"][0]["type"] == "text" + assert output_messages[0]["role"] == "assistant" + assert output_messages[0]["parts"][0]["type"] == "text" + + @pytest.mark.vcr() def test_sync_messages_create_with_all_params( span_exporter, anthropic_client, instrument_no_content @@ -386,6 +439,36 @@ def test_sync_messages_create_streaming( # pylint: disable=too-many-locals ) +@pytest.mark.vcr() +def test_sync_messages_create_streaming_captures_content( + span_exporter, anthropic_client, instrument_with_content +): + """Test content capture on create(stream=True).""" + model = "claude-sonnet-4-20250514" + messages = [{"role": "user", "content": "Say hello in one word."}] + + with anthropic_client.messages.create( + model=model, + max_tokens=100, + messages=messages, + stream=True, + ) as stream: + for _ in stream: + pass + + spans = span_exporter.get_finished_spans() + assert len(spans) == 1 + span = spans[0] + + input_messages = _load_span_messages(span, GenAIAttributes.GEN_AI_INPUT_MESSAGES) + output_messages = _load_span_messages( + span, GenAIAttributes.GEN_AI_OUTPUT_MESSAGES + ) + assert input_messages[0]["role"] == "user" + assert output_messages[0]["role"] == "assistant" + assert output_messages[0]["parts"] + + @pytest.mark.vcr() def test_sync_messages_create_streaming_iteration( span_exporter, anthropic_client, instrument_no_content @@ -482,6 +565,105 @@ def test_sync_messages_stream_basic( ) +@pytest.mark.vcr() +def test_sync_messages_stream_captures_content( + span_exporter, anthropic_client, instrument_with_content +): + """Test content capture on Messages.stream().""" + model = "claude-sonnet-4-20250514" + messages = [{"role": "user", "content": "Say hello in one word."}] + + with anthropic_client.messages.stream( + model=model, + max_tokens=100, + messages=messages, + ) as stream: + _ = "".join(stream.text_stream) + + spans = span_exporter.get_finished_spans() + assert len(spans) == 1 + span = spans[0] + + input_messages = _load_span_messages(span, GenAIAttributes.GEN_AI_INPUT_MESSAGES) + output_messages = _load_span_messages( + span, GenAIAttributes.GEN_AI_OUTPUT_MESSAGES + ) + assert input_messages[0]["role"] == "user" + assert output_messages[0]["role"] == "assistant" + assert output_messages[0]["parts"] + + +@pytest.mark.vcr() +def test_sync_messages_create_captures_tool_use_content( + request, span_exporter, anthropic_client, instrument_with_content +): + """Test that tool_use blocks are captured as tool_call parts.""" + _skip_if_cassette_missing_and_no_real_key(request) + model = "claude-sonnet-4-20250514" + messages = [{"role": "user", "content": "What is the weather in SF?"}] + + anthropic_client.messages.create( + model=model, + max_tokens=256, + messages=messages, + tools=[ + { + "name": "get_weather", + "description": "Get weather by city", + "input_schema": { + "type": "object", + "properties": {"city": {"type": "string"}}, + "required": ["city"], + }, + } + ], + tool_choice={"type": "tool", "name": "get_weather"}, + ) + + spans = span_exporter.get_finished_spans() + assert len(spans) == 1 + span = spans[0] + output_messages = _load_span_messages( + span, GenAIAttributes.GEN_AI_OUTPUT_MESSAGES + ) + + assert any( + part.get("type") == "tool_call" + for message in output_messages + for part in message.get("parts", []) + ) + + +@pytest.mark.vcr() +def test_sync_messages_create_captures_thinking_content( + request, span_exporter, anthropic_client, instrument_with_content +): + """Test that thinking blocks are captured as reasoning parts.""" + _skip_if_cassette_missing_and_no_real_key(request) + model = "claude-sonnet-4-20250514" + messages = [{"role": "user", "content": "What is 17*19? Think first."}] + + anthropic_client.messages.create( + model=model, + max_tokens=16000, + messages=messages, + thinking={"type": "enabled", "budget_tokens": 10000}, + ) + + spans = span_exporter.get_finished_spans() + assert len(spans) == 1 + span = spans[0] + output_messages = _load_span_messages( + span, GenAIAttributes.GEN_AI_OUTPUT_MESSAGES + ) + + assert any( + part.get("type") == "reasoning" + for message in output_messages + for part in message.get("parts", []) + ) + + @pytest.mark.vcr() def test_stream_wrapper_finalize_idempotent( span_exporter, anthropic_client, instrument_no_content # pylint: disable=too-many-locals @@ -542,10 +724,6 @@ def test_stream_wrapper_finalize_idempotent( def test_message_wrapper_aggregates_cache_tokens(): """MessageWrapper should aggregate cache token fields into input tokens.""" - class FakeHandler: - def stop_llm(self, invocation): # pylint: disable=no-self-use - return invocation - usage = SimpleNamespace( input_tokens=10, cache_creation_input_tokens=3, @@ -563,7 +741,7 @@ def stop_llm(self, invocation): # pylint: disable=no-self-use provider="anthropic", ) - MessageWrapper(message, FakeHandler(), invocation) # type: ignore[arg-type] + MessageWrapper(message).extract_into(invocation) # type: ignore[arg-type] assert invocation.input_tokens == 20 assert invocation.output_tokens == 5 From 75fcb3b22d94f7685291207d522963fbe794c7fc Mon Sep 17 00:00:00 2001 From: Teja Date: Wed, 11 Feb 2026 13:44:55 -0500 Subject: [PATCH 11/35] Enhance tests for sync message creation in Anthropic instrumentation - Added checks for the presence of 'tools' and 'thinking' parameters in the installed anthropic SDK. - Updated test cases to skip if the SDK version does not support these parameters, ensuring compatibility with older versions. - Improved test robustness by dynamically determining parameter support. --- .../tests/test_sync_messages.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py index fe0781847d..b763b404e1 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py @@ -14,6 +14,7 @@ """Tests for sync Messages.create instrumentation.""" +import inspect import json import os from pathlib import Path @@ -23,6 +24,18 @@ from anthropic import Anthropic, APIConnectionError, NotFoundError from opentelemetry.instrumentation.anthropic import AnthropicInstrumentor + +# Detect whether the installed anthropic SDK supports tools / thinking params. +# Older SDK versions (e.g. 0.16.0) do not accept these keyword arguments. +try: + from anthropic.resources.messages import Messages as _Messages + + _create_params = set(inspect.signature(_Messages.create).parameters) +except Exception: # pylint: disable=broad-except + _create_params = set() + +_has_tools_param = "tools" in _create_params +_has_thinking_param = "thinking" in _create_params from opentelemetry.instrumentation.anthropic.utils import ( MessageWrapper, StreamWrapper, @@ -594,6 +607,10 @@ def test_sync_messages_stream_captures_content( @pytest.mark.vcr() +@pytest.mark.skipif( + not _has_tools_param, + reason="anthropic SDK too old to support 'tools' parameter", +) def test_sync_messages_create_captures_tool_use_content( request, span_exporter, anthropic_client, instrument_with_content ): @@ -635,6 +652,10 @@ def test_sync_messages_create_captures_tool_use_content( @pytest.mark.vcr() +@pytest.mark.skipif( + not _has_thinking_param, + reason="anthropic SDK too old to support 'thinking' parameter", +) def test_sync_messages_create_captures_thinking_content( request, span_exporter, anthropic_client, instrument_with_content ): From 8b5b20fef4a461f12e85ca8ccaf671e4db270988 Mon Sep 17 00:00:00 2001 From: Teja Date: Wed, 11 Feb 2026 15:07:37 -0500 Subject: [PATCH 12/35] Remove sensitive 'anthropic-organization-id' headers from test cassettes and update header scrubbing logic in tests. This enhances security by ensuring sensitive information is not recorded in test artifacts. --- ...st_stream_wrapper_finalize_idempotent.yaml | 10 ------- .../test_sync_messages_create_api_error.yaml | 20 -------------- .../test_sync_messages_create_basic.yaml | 26 ------------------- ...sync_messages_create_captures_content.yaml | 26 ------------------- ...ages_create_captures_thinking_content.yaml | 2 -- ...ages_create_captures_tool_use_content.yaml | 4 --- ...test_sync_messages_create_stop_reason.yaml | 20 -------------- .../test_sync_messages_create_streaming.yaml | 14 ---------- ...ges_create_streaming_captures_content.yaml | 14 ---------- ...c_messages_create_streaming_iteration.yaml | 14 ---------- ...test_sync_messages_create_token_usage.yaml | 20 -------------- ..._sync_messages_create_with_all_params.yaml | 20 -------------- .../test_sync_messages_stream_basic.yaml | 14 ---------- ...sync_messages_stream_captures_content.yaml | 14 ---------- ...essages_stream_double_exit_idempotent.yaml | 8 ------ ...test_sync_messages_stream_token_usage.yaml | 14 ---------- ...test_sync_messages_stream_with_params.yaml | 14 ---------- .../tests/conftest.py | 12 ++++++++- 18 files changed, 11 insertions(+), 255 deletions(-) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml index be79ed38ed..6d20d522b7 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml @@ -96,8 +96,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -230,8 +228,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -364,8 +360,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -498,8 +492,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -632,8 +624,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml index 29e83d54d2..6b29965730 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml @@ -227,8 +227,6 @@ interactions: - cloudflare X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 cf-cache-status: - DYNAMIC request-id: @@ -321,8 +319,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 cf-cache-status: - DYNAMIC content-length: @@ -417,8 +413,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 cf-cache-status: - DYNAMIC content-length: @@ -515,8 +509,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 cf-cache-status: - DYNAMIC content-length: @@ -707,8 +699,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 cf-cache-status: - DYNAMIC content-length: @@ -805,8 +795,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 cf-cache-status: - DYNAMIC content-length: @@ -903,8 +891,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 cf-cache-status: - DYNAMIC content-length: @@ -1001,8 +987,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 cf-cache-status: - DYNAMIC content-length: @@ -1099,8 +1083,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 cf-cache-status: - DYNAMIC content-length: @@ -1197,8 +1179,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 cf-cache-status: - DYNAMIC content-length: diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml index 97d13f0966..5dffc654c8 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml @@ -240,8 +240,6 @@ interactions: - cloudflare X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 cf-cache-status: - DYNAMIC request-id: @@ -334,8 +332,6 @@ interactions: - cloudflare X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 cf-cache-status: - DYNAMIC request-id: @@ -428,8 +424,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 cf-cache-status: - DYNAMIC content-length: @@ -541,8 +535,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '30000' anthropic-ratelimit-input-tokens-remaining: @@ -676,8 +668,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '30000' anthropic-ratelimit-input-tokens-remaining: @@ -811,8 +801,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '30000' anthropic-ratelimit-input-tokens-remaining: @@ -948,8 +936,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '30000' anthropic-ratelimit-input-tokens-remaining: @@ -1180,8 +1166,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -1318,8 +1302,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -1456,8 +1438,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -1594,8 +1574,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -1732,8 +1710,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -1870,8 +1846,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml index a42a6cceed..85977c61a9 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml @@ -240,8 +240,6 @@ interactions: - cloudflare X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 cf-cache-status: - DYNAMIC request-id: @@ -334,8 +332,6 @@ interactions: - cloudflare X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 cf-cache-status: - DYNAMIC request-id: @@ -428,8 +424,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 cf-cache-status: - DYNAMIC content-length: @@ -541,8 +535,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '30000' anthropic-ratelimit-input-tokens-remaining: @@ -676,8 +668,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '30000' anthropic-ratelimit-input-tokens-remaining: @@ -811,8 +801,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '30000' anthropic-ratelimit-input-tokens-remaining: @@ -948,8 +936,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '30000' anthropic-ratelimit-input-tokens-remaining: @@ -1180,8 +1166,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -1318,8 +1302,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -1456,8 +1438,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -1594,8 +1574,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -1732,8 +1710,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -1870,8 +1846,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml index def115bd64..0aa259fc65 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml @@ -208,8 +208,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml index bec58c7521..9971289676 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml @@ -123,8 +123,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -286,8 +284,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml index 3e9d575e51..4164222843 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml @@ -240,8 +240,6 @@ interactions: - cloudflare X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 cf-cache-status: - DYNAMIC request-id: @@ -351,8 +349,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '30000' anthropic-ratelimit-input-tokens-remaining: @@ -486,8 +482,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '30000' anthropic-ratelimit-input-tokens-remaining: @@ -623,8 +617,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '30000' anthropic-ratelimit-input-tokens-remaining: @@ -855,8 +847,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -993,8 +983,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -1131,8 +1119,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -1269,8 +1255,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -1407,8 +1391,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -1545,8 +1527,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml index af9c51def7..6358370afb 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml @@ -96,8 +96,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '30000' anthropic-ratelimit-input-tokens-remaining: @@ -325,8 +323,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -459,8 +455,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -593,8 +587,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -727,8 +719,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -861,8 +851,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -995,8 +983,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml index a2af7d8333..32027ab543 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml @@ -96,8 +96,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '30000' anthropic-ratelimit-input-tokens-remaining: @@ -325,8 +323,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -459,8 +455,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -593,8 +587,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -727,8 +719,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -861,8 +851,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -995,8 +983,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml index eeea24aa9f..bb7f3943b3 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml @@ -105,8 +105,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '30000' anthropic-ratelimit-input-tokens-remaining: @@ -346,8 +344,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -489,8 +485,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -632,8 +626,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -772,8 +764,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -915,8 +905,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -1055,8 +1043,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml index 9a4252f562..c52a46f16b 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml @@ -240,8 +240,6 @@ interactions: - cloudflare X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 cf-cache-status: - DYNAMIC request-id: @@ -351,8 +349,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '30000' anthropic-ratelimit-input-tokens-remaining: @@ -486,8 +482,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '30000' anthropic-ratelimit-input-tokens-remaining: @@ -623,8 +617,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '30000' anthropic-ratelimit-input-tokens-remaining: @@ -855,8 +847,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -993,8 +983,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -1131,8 +1119,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -1269,8 +1255,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -1407,8 +1391,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -1545,8 +1527,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml index 2766c0a8ac..fc2c5372a9 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml @@ -258,8 +258,6 @@ interactions: - cloudflare X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 cf-cache-status: - DYNAMIC request-id: @@ -375,8 +373,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '30000' anthropic-ratelimit-input-tokens-remaining: @@ -516,8 +512,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '30000' anthropic-ratelimit-input-tokens-remaining: @@ -659,8 +653,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '30000' anthropic-ratelimit-input-tokens-remaining: @@ -903,8 +895,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -1047,8 +1037,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -1191,8 +1179,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -1335,8 +1321,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -1479,8 +1463,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -1623,8 +1605,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml index 42cc1dc0e2..38562c0b1f 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml @@ -100,8 +100,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '30000' anthropic-ratelimit-input-tokens-remaining: @@ -337,8 +335,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -475,8 +471,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -613,8 +607,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -751,8 +743,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -889,8 +879,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -1027,8 +1015,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_captures_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_captures_content.yaml index d7dc48ea75..cd2b74e168 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_captures_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_captures_content.yaml @@ -100,8 +100,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '30000' anthropic-ratelimit-input-tokens-remaining: @@ -337,8 +335,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -475,8 +471,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -613,8 +607,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -751,8 +743,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -889,8 +879,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -1027,8 +1015,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_double_exit_idempotent.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_double_exit_idempotent.yaml index 2aa049385d..a6a18ad0db 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_double_exit_idempotent.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_double_exit_idempotent.yaml @@ -100,8 +100,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -241,8 +239,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -382,8 +378,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -523,8 +517,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml index 27709106ee..3383829def 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml @@ -103,8 +103,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '30000' anthropic-ratelimit-input-tokens-remaining: @@ -340,8 +338,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -481,8 +477,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -622,8 +616,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -763,8 +755,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -904,8 +894,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -1042,8 +1030,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml index 5b2fe688c7..f8ceb77e5a 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml @@ -112,8 +112,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '30000' anthropic-ratelimit-input-tokens-remaining: @@ -364,8 +362,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -517,8 +513,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -667,8 +661,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -820,8 +812,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -970,8 +960,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: @@ -1123,8 +1111,6 @@ interactions: - chunked X-Robots-Tag: - none - anthropic-organization-id: - - 455ea6be-bd92-4199-83ec-0c6b39c5c169 anthropic-ratelimit-input-tokens-limit: - '450000' anthropic-ratelimit-input-tokens-remaining: diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/conftest.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/conftest.py index 0d4aa012b7..18f5d8835e 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/conftest.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/conftest.py @@ -244,6 +244,16 @@ def fixture_vcr(vcr): return vcr +_SCRUBBED_RESPONSE_HEADERS = frozenset( + { + "anthropic-organization-id", + } +) + + def scrub_response_headers(response): - """Scrub sensitive response headers.""" + """Scrub sensitive headers from recorded responses.""" + headers = response.get("headers", {}) + for header in _SCRUBBED_RESPONSE_HEADERS: + headers.pop(header, None) return response From d48c7e3bfef6f59a6029678a855455a02aff97c9 Mon Sep 17 00:00:00 2001 From: Teja Date: Wed, 11 Feb 2026 15:22:08 -0500 Subject: [PATCH 13/35] Refactor tests for sync message handling in Anthropic instrumentation - Simplified detection of 'tools' and 'thinking' parameters by directly accessing the _Messages class. - Improved readability of test cases by formatting input message loading. - Enhanced test function signatures for better clarity and maintainability. --- .../tests/test_sync_messages.py | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py index b763b404e1..7f353abaf4 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py @@ -22,20 +22,9 @@ import pytest from anthropic import Anthropic, APIConnectionError, NotFoundError +from anthropic.resources.messages import Messages as _Messages from opentelemetry.instrumentation.anthropic import AnthropicInstrumentor - -# Detect whether the installed anthropic SDK supports tools / thinking params. -# Older SDK versions (e.g. 0.16.0) do not accept these keyword arguments. -try: - from anthropic.resources.messages import Messages as _Messages - - _create_params = set(inspect.signature(_Messages.create).parameters) -except Exception: # pylint: disable=broad-except - _create_params = set() - -_has_tools_param = "tools" in _create_params -_has_thinking_param = "thinking" in _create_params from opentelemetry.instrumentation.anthropic.utils import ( MessageWrapper, StreamWrapper, @@ -51,6 +40,12 @@ ) from opentelemetry.util.genai.types import LLMInvocation +# Detect whether the installed anthropic SDK supports tools / thinking params. +# Older SDK versions (e.g. 0.16.0) do not accept these keyword arguments. +_create_params = set(inspect.signature(_Messages.create).parameters) +_has_tools_param = "tools" in _create_params +_has_thinking_param = "thinking" in _create_params + def normalize_stop_reason(stop_reason): """Map Anthropic stop reasons to GenAI semconv values.""" @@ -194,7 +189,9 @@ def test_sync_messages_create_captures_content( assert len(spans) == 1 span = spans[0] - input_messages = _load_span_messages(span, GenAIAttributes.GEN_AI_INPUT_MESSAGES) + input_messages = _load_span_messages( + span, GenAIAttributes.GEN_AI_INPUT_MESSAGES + ) output_messages = _load_span_messages( span, GenAIAttributes.GEN_AI_OUTPUT_MESSAGES ) @@ -473,7 +470,9 @@ def test_sync_messages_create_streaming_captures_content( assert len(spans) == 1 span = spans[0] - input_messages = _load_span_messages(span, GenAIAttributes.GEN_AI_INPUT_MESSAGES) + input_messages = _load_span_messages( + span, GenAIAttributes.GEN_AI_INPUT_MESSAGES + ) output_messages = _load_span_messages( span, GenAIAttributes.GEN_AI_OUTPUT_MESSAGES ) @@ -597,7 +596,9 @@ def test_sync_messages_stream_captures_content( assert len(spans) == 1 span = spans[0] - input_messages = _load_span_messages(span, GenAIAttributes.GEN_AI_INPUT_MESSAGES) + input_messages = _load_span_messages( + span, GenAIAttributes.GEN_AI_INPUT_MESSAGES + ) output_messages = _load_span_messages( span, GenAIAttributes.GEN_AI_OUTPUT_MESSAGES ) @@ -687,7 +688,9 @@ def test_sync_messages_create_captures_thinking_content( @pytest.mark.vcr() def test_stream_wrapper_finalize_idempotent( - span_exporter, anthropic_client, instrument_no_content # pylint: disable=too-many-locals + span_exporter, + anthropic_client, + instrument_no_content, # pylint: disable=too-many-locals ): """Fully consumed stream plus explicit close should still yield one span.""" model = "claude-sonnet-4-20250514" From ee173da03e2974f7f886d0e21aa0e1039082dcd9 Mon Sep 17 00:00:00 2001 From: Teja Date: Wed, 11 Feb 2026 19:11:26 -0500 Subject: [PATCH 14/35] Refactor utils.py for improved type safety and clarity - Added type casting for dictionary access to enhance type safety. - Simplified content block conversion logic to improve readability and maintainability. - Updated test cases to ensure consistent handling of content types and structures. --- .../instrumentation/anthropic/utils.py | 58 ++++++++++--------- .../tests/test_sync_messages.py | 10 ++-- 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py index 7453bc5e83..4c870cf441 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py @@ -20,7 +20,7 @@ import json import logging from dataclasses import dataclass -from typing import TYPE_CHECKING, Any, Iterator, Optional, Sequence +from typing import TYPE_CHECKING, Any, Iterator, Optional, Sequence, cast from urllib.parse import urlparse from opentelemetry.semconv._incubating.attributes import ( @@ -158,7 +158,7 @@ def should_capture_content() -> bool: def _get_field(obj: Any, name: str, default: Any = None) -> Any: if isinstance(obj, dict): - return obj.get(name, default) + return cast(dict[str, Any], obj).get(name, default) return getattr(obj, name, default) @@ -172,7 +172,7 @@ def _as_str(value: Any) -> str | None: def _to_dict_if_possible(value: Any) -> Any: if isinstance(value, dict): - return value + return cast(dict[str, Any], value) if hasattr(value, "to_dict"): to_dict = getattr(value, "to_dict") if callable(to_dict): @@ -181,7 +181,7 @@ def _to_dict_if_possible(value: Any) -> Any: except Exception: # pylint: disable=broad-exception-caught return value if hasattr(value, "__dict__"): - return dict(value.__dict__) + return cast(dict[str, Any], dict(value.__dict__)) return value @@ -199,40 +199,40 @@ def _convert_content_block_to_part(content_block: Any) -> MessagePart | None: if block_type is None: return None + result: MessagePart | None = None if block_type == "text": text = _as_str(_get_field(content_block, "text")) - return Text(content=text or "") - - if block_type == "tool_use": - return ToolCall( + result = Text(content=text or "") + elif block_type == "tool_use": + result = ToolCall( arguments=_to_dict_if_possible(_get_field(content_block, "input")), name=_as_str(_get_field(content_block, "name")) or "", id=_as_str(_get_field(content_block, "id")), ) - - if block_type == "tool_result": - return ToolCallResponse( - response=_to_dict_if_possible(_get_field(content_block, "content")), + elif block_type == "tool_result": + result = ToolCallResponse( + response=_to_dict_if_possible( + _get_field(content_block, "content") + ), id=_as_str(_get_field(content_block, "tool_use_id")), ) - - if block_type in ("thinking", "redacted_thinking"): + elif block_type in ("thinking", "redacted_thinking"): content = _as_str(_get_field(content_block, "thinking")) if content is None: content = _as_str(_get_field(content_block, "data")) - return Reasoning(content=content or "") - - if block_type in ("image", "audio", "video", "document", "file"): + result = Reasoning(content=content or "") + elif block_type in ("image", "audio", "video", "document", "file"): source = _get_field(content_block, "source") mime_type = _as_str(_get_field(source, "media_type")) raw_data = _as_str(_get_field(source, "data")) data = _decode_base64(raw_data) - if data is None: - return None - modality = _as_str(_get_field(content_block, "type")) or "file" - return Blob(mime_type=mime_type, modality=modality, content=data) + if data is not None: + modality = _as_str(_get_field(content_block, "type")) or "file" + result = Blob(mime_type=mime_type, modality=modality, content=data) + else: + result = _to_dict_if_possible(content_block) - return _to_dict_if_possible(content_block) + return result def _convert_content_to_parts(content: Any) -> list[MessagePart]: @@ -242,7 +242,7 @@ def _convert_content_to_parts(content: Any) -> list[MessagePart]: return [Text(content=content)] if isinstance(content, list): parts: list[MessagePart] = [] - for item in content: + for item in cast(list[Any], content): part = _convert_content_block_to_part(item) if part is not None: parts.append(part) @@ -256,7 +256,7 @@ def get_input_messages(messages: Any) -> list[InputMessage]: return [] result: list[InputMessage] = [] - for message in messages: + for message in cast(list[Any], messages): role = _as_str(_get_field(message, "role")) or "user" parts = _convert_content_to_parts(_get_field(message, "content")) result.append(InputMessage(role=role, parts=parts)) @@ -272,7 +272,9 @@ def get_output_messages_from_message(message: Any) -> list[OutputMessage]: return [] parts = _convert_content_to_parts(_get_field(message, "content")) - finish_reason = _normalize_finish_reason(_get_field(message, "stop_reason")) + finish_reason = _normalize_finish_reason( + _get_field(message, "stop_reason") + ) return [ OutputMessage( role=_as_str(_get_field(message, "role")) or "assistant", @@ -294,7 +296,9 @@ def _create_stream_block_state(content_block: Any) -> dict[str, Any]: state["input"] = _to_dict_if_possible(input_value) state["input_json"] = "" elif block_type in ("thinking", "redacted_thinking"): - state["thinking"] = _as_str(_get_field(content_block, "thinking")) or "" + state["thinking"] = ( + _as_str(_get_field(content_block, "thinking")) or "" + ) return state @@ -606,7 +610,7 @@ def _finalize_invocation(self) -> None: ] = self._cache_read_input_tokens if self._capture_content and self._content_blocks: - parts = [] + parts: list[MessagePart] = [] for index in sorted(self._content_blocks): part = _stream_block_state_to_part(self._content_blocks[index]) if part is not None: diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py index 7f353abaf4..5d04746583 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py @@ -687,10 +687,10 @@ def test_sync_messages_create_captures_thinking_content( @pytest.mark.vcr() -def test_stream_wrapper_finalize_idempotent( +def test_stream_wrapper_finalize_idempotent( # pylint: disable=too-many-locals span_exporter, anthropic_client, - instrument_no_content, # pylint: disable=too-many-locals + instrument_no_content, ): """Fully consumed stream plus explicit close should still yield one span.""" model = "claude-sonnet-4-20250514" @@ -917,10 +917,10 @@ def test_sync_messages_stream_double_exit_idempotent( max_tokens=100, messages=messages, ) - stream = manager.__enter__() + stream = manager.__enter__() # pylint: disable=unnecessary-dunder-call _ = "".join(stream.text_stream) - manager.__exit__(None, None, None) - manager.__exit__(None, None, None) + manager.__exit__(None, None, None) # pylint: disable=unnecessary-dunder-call + manager.__exit__(None, None, None) # pylint: disable=unnecessary-dunder-call spans = span_exporter.get_finished_spans() assert len(spans) == 1 From ed46be89ba6d7e00122625a879350703c4d6a471 Mon Sep 17 00:00:00 2001 From: Teja Date: Wed, 11 Feb 2026 21:49:52 -0500 Subject: [PATCH 15/35] Enhance Anthropic instrumentation tests for EVENT_ONLY content capture - Introduced a new fixture to instrument Anthropic with EVENT_ONLY content capture mode. - Added tests to verify that content is not captured in span attributes while ensuring log events are emitted correctly. - Updated cassettes to reflect new request and response structures for EVENT_ONLY scenarios. - Enhanced existing tests to cover various content capture scenarios, including streaming and tool usage. --- ...st_stream_wrapper_finalize_idempotent.yaml | 132 ++++++++++++++ .../test_sync_messages_create_api_error.yaml | 96 +++++++++++ .../test_sync_messages_create_basic.yaml | 136 +++++++++++++++ ...sync_messages_create_captures_content.yaml | 136 +++++++++++++++ ...ages_create_captures_thinking_content.yaml | 145 ++++++++++++++++ ...ages_create_captures_tool_use_content.yaml | 161 ++++++++++++++++++ ..._create_event_only_no_content_in_span.yaml | 138 +++++++++++++++ ...test_sync_messages_create_stop_reason.yaml | 136 +++++++++++++++ .../test_sync_messages_create_streaming.yaml | 132 ++++++++++++++ ...ges_create_streaming_captures_content.yaml | 132 ++++++++++++++ ...c_messages_create_streaming_iteration.yaml | 141 +++++++++++++++ ...test_sync_messages_create_token_usage.yaml | 136 +++++++++++++++ ..._sync_messages_create_with_all_params.yaml | 142 +++++++++++++++ .../test_sync_messages_stream_basic.yaml | 136 +++++++++++++++ ...sync_messages_stream_captures_content.yaml | 136 +++++++++++++++ ...essages_stream_double_exit_idempotent.yaml | 139 +++++++++++++++ ...test_sync_messages_stream_token_usage.yaml | 139 +++++++++++++++ ...test_sync_messages_stream_with_params.yaml | 145 ++++++++++++++++ .../tests/conftest.py | 26 +++ .../tests/test_sync_messages.py | 44 +++++ 20 files changed, 2528 insertions(+) create mode 100644 instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml index 6d20d522b7..cc7cc069b4 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml @@ -659,4 +659,136 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01VT1R2Lzjsn7AMCTQNjnsqP","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5}} + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cc8c3b38889ac6e-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Thu, 12 Feb 2026 02:48:00 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-12T02:47:59Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-12T02:47:59Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-12T02:47:59Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-12T02:47:59Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY3QqbKbhrR9YVDAF6en4 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1022' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml index 6b29965730..9949e6c479 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml @@ -1194,4 +1194,100 @@ interactions: status: code: 404 message: Not Found +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Hello" + } + ], + "model": "invalid-model-name" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '94' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "type": "error", + "error": { + "type": "not_found_error", + "message": "model: invalid-model-name" + }, + "request_id": "req_011CY3QpP6cMeGR736sN44u9" + } + headers: + CF-RAY: + - 9cc8c34cca225e7e-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Thu, 12 Feb 2026 02:47:42 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + cf-cache-status: + - DYNAMIC + content-length: + - '133' + request-id: + - req_011CY3QpP6cMeGR736sN44u9 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '47' + x-should-retry: + - 'false' + status: + code: 404 + message: Not Found version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml index 5dffc654c8..4f4835c756 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml @@ -1883,4 +1883,140 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '117' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01WwXmU84NdpiiUXuz2Qda3E", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello!" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 13, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 5, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cc8c315ab2d9187-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Thu, 12 Feb 2026 02:47:34 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-12T02:47:34Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-12T02:47:34Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-12T02:47:34Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-12T02:47:34Z' + cf-cache-status: + - DYNAMIC + content-length: + - '441' + request-id: + - req_011CY3QojMjQ3bQGJeiU1Lur + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '939' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml index 85977c61a9..f441184e5e 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml @@ -1883,4 +1883,140 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '117' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01GfhPDczEhZYwihvH74pt3E", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello!" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 13, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 5, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cc8c31d982a8d3f-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Thu, 12 Feb 2026 02:47:36 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-12T02:47:36Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-12T02:47:36Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-12T02:47:35Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-12T02:47:36Z' + cf-cache-status: + - DYNAMIC + content-length: + - '441' + request-id: + - req_011CY3QopoQXN5AS8qDP8eCJ + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1268' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml index 0aa259fc65..e4f03a8ded 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml @@ -245,4 +245,149 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 16000, + "messages": [ + { + "role": "user", + "content": "What is 17*19? Think first." + } + ], + "model": "claude-sonnet-4-20250514", + "thinking": { + "type": "enabled", + "budget_tokens": 10000 + } + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '176' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01QZXwbxRaiRGHtU7xxooHTc", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "thinking", + "thinking": "I need to calculate 17 \u00d7 19.\n\nLet me think about this step by step. I can use the standard multiplication method or look for patterns.\n\nOne approach is to use the fact that both numbers are close to 20:\n17 \u00d7 19 = (20 - 3) \u00d7 (20 - 1)\n= 20\u00b2 - 20\u00d71 - 20\u00d73 + 3\u00d71\n= 400 - 20 - 60 + 3\n= 400 - 80 + 3\n= 320 + 3\n= 323\n\nLet me double-check this with standard multiplication:\n 17\n \u00d7 19\n ----\n 153 (17 \u00d7 9)\n 170 (17 \u00d7 10, shifted one place)\n ----\n 323\n\nLet me verify the first line: 17 \u00d7 9\n17 \u00d7 9 = 17 \u00d7 (10 - 1) = 170 - 17 = 153 \u2713\n\nAnd 17 \u00d7 10 = 170 \u2713\n\nSo 153 + 170 = 323 \u2713\n\nBoth methods give me 323.", + "signature": "EpgGCkYICxgCKkC23dGy4G89aOB/G0AEgl/YoxyYjLLQNjXsCMrWZqc/ZMQq9gAOMRpteSezIYWTc07F31ORVASHDaLNe2Ty0sGkEgwQprMbHAucH973U0waDBkRzLZZgddLcuk5QCIwuuII2T6wylsLsD4fRwA3CHaSCZrO4LJiK874yGjSa2acy10XGjwXXS3tVOQbxwETKv8EBeIp6G7y5QRorylUQVwMQxo6ZUpk6KQObHK8nJRqltBxsrYkvCpCI/102k+2Liq/5cZEXWHt0rbozb4J3qfn0YsMprV2WoiO5D0bllZBt9DzoVnxarTWv1thNbrwoUMcPgb50uNarNGC4S/hKSWrgv/uA0HaGFHnXHLTTIpCLvjLIaVNHeYG9NRFJcbYf1Y5CwP6V1JlKIuFO7y+9dkAQySneuyg1UkhxJptEs498MN62OQVul7MffRdmOiqkqxArtNIz9eLQDAx0O15E/5MY1YR3q/vtv2swtVWBvL4D+DaDKvIjiA81aLzVaUP9EHPe5Jy/aHzKxLodgl0+lAH3t9MNoapk40UQALM85hU+rkSFbWUWXG0ViTLAhZIC4LtZZpbXw5GucGgHqkwy7xVUI46ebuePM1ejTgLIkJOqEAvHsR+7W2s4gy1eehC4bA3dU/9V9fEVuEm8V4NjnRWEVvj3fL5Qio1lO9yXzNlkRx2CNP8BOsk3qYPZDa+1fxUNI9mFtMs9vsPUdoSQ1VGc+RPp6QSUaBIa2p5dmdaaWLBU9IVmh7Dke5I7digHFj2Y9JfP/4cL/p71xDp5ylj+GjTzejPRsyvhewiLMcTseV9+zFXeAK6LnvON63MxBAp2YbEoKKTpVo/wcff5Syg6QKLunKZo15wl8OKcYMxdfmpNqvDz3XNcDOvvanuC7gID2jWJut4gnQjVp0kjUGTZCEnum8Or17xTI6mirb+WGF+Bt1Zng/4JqBR60iN9y2m+n2LI3/ofDe5xcxfa7ZuYvRqrPcVBX+/wfQQfM+gyYsB9vCw365/A2GwYEzohwSY9oMxlScJTBr9CAzNJT9NGAE=" + }, + { + "type": "text", + "text": "Let me work through 17 \u00d7 19 step by step.\n\nI can use the standard multiplication method:\n```\n 17\n \u00d7 19\n ----\n 153 (17 \u00d7 9)\n 170 (17 \u00d7 10)\n ----\n 323\n```\n\nOr I can use the fact that both numbers are close to 20:\n17 \u00d7 19 = (20 - 3) \u00d7 (20 - 1) = 400 - 20 - 60 + 3 = 323\n\nTherefore, 17 \u00d7 19 = 323." + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 46, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 431, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cc8c38c49eb5017-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Thu, 12 Feb 2026 02:47:59 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-12T02:47:53Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-12T02:47:59Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-12T02:47:53Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-12T02:47:53Z' + cf-cache-status: + - DYNAMIC + content-length: + - '2530' + request-id: + - req_011CY3Qq8Uoq7QhpK5b2KnAy + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '6043' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml index 9971289676..a2d4b350c0 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml @@ -321,4 +321,165 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 256, + "messages": [ + { + "role": "user", + "content": "What is the weather in SF?" + } + ], + "model": "claude-sonnet-4-20250514", + "tool_choice": { + "type": "tool", + "name": "get_weather" + }, + "tools": [ + { + "name": "get_weather", + "description": "Get weather by city", + "input_schema": { + "type": "object", + "properties": { + "city": { + "type": "string" + } + }, + "required": [ + "city" + ] + } + } + ] + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '334' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_011JS9iWt1o4R56eqeZFnHtY", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "tool_use", + "id": "toolu_01W6DT6AwaJh7JkcXYdEiTbh", + "name": "get_weather", + "input": { + "city": "San Francisco" + } + } + ], + "stop_reason": "tool_use", + "stop_sequence": null, + "usage": { + "input_tokens": 386, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 34, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cc8c3843c76efa9-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Thu, 12 Feb 2026 02:47:52 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-12T02:47:52Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-12T02:47:52Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-12T02:47:51Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-12T02:47:52Z' + cf-cache-status: + - DYNAMIC + content-length: + - '523' + request-id: + - req_011CY3Qq2yfbk2hzays52LaG + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1098' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml new file mode 100644 index 0000000000..d958a76609 --- /dev/null +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml @@ -0,0 +1,138 @@ +interactions: +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '117' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01QiwQEGrr3tagonEdoVhPre", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello!" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 13, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 5, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cc8c3df0c0da5f1-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Thu, 12 Feb 2026 02:48:07 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-12T02:48:07Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-12T02:48:07Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-12T02:48:06Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-12T02:48:07Z' + cf-cache-status: + - DYNAMIC + content-length: + - '441' + request-id: + - req_011CY3Qr76FPTFGyXuAkm1oT + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1067' + status: + code: 200 + message: OK +version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml index 4164222843..2a82e7fe46 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml @@ -1564,4 +1564,140 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '102' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_015bDxsCC482eLwW9VQmPvMY", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hi! How are you doing today?" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 10, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 11, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cc8c33b4e95de9c-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Thu, 12 Feb 2026 02:47:41 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-12T02:47:40Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-12T02:47:41Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-12T02:47:40Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-12T02:47:40Z' + cf-cache-status: + - DYNAMIC + content-length: + - '464' + request-id: + - req_011CY3QpB5Z2mPessQ4wQfC9 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1135' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml index 6358370afb..3d25891c09 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml @@ -1018,4 +1018,136 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01AKmfTCRXXJUUpkT6xknT7E","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello."} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cc8c34ebbbec439-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Thu, 12 Feb 2026 02:47:44 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-12T02:47:43Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-12T02:47:43Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-12T02:47:43Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-12T02:47:43Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY3QpQP1CyWbnSVQFwuUD + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '963' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml index 32027ab543..ff91ba37d3 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml @@ -1018,4 +1018,136 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01DB4wa2XbVxgZXXW7UAGGCb","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cc8c357ffc043aa-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Thu, 12 Feb 2026 02:47:45 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-12T02:47:44Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-12T02:47:44Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-12T02:47:44Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-12T02:47:44Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY3QpWhWTag5PSoX3S4ws + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '932' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml index bb7f3943b3..56d736635a 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml @@ -1078,4 +1078,145 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '116' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01LYmwC7VS3vLuFPDVTi8Wvm","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"! How"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" you doing today?"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cc8c3606fe8e8c4-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Thu, 12 Feb 2026 02:47:46 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-12T02:47:46Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-12T02:47:46Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-12T02:47:46Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-12T02:47:46Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY3QpcUms4usvBtgfQVxQ + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '971' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml index c52a46f16b..99c812ac23 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml @@ -1564,4 +1564,140 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Count to 5." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '106' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01L6VCoGpqErD9JSmy5p64Pp", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "1\n2\n3\n4\n5" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 12, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 13, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cc8c330aac12067-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Thu, 12 Feb 2026 02:47:39 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-12T02:47:39Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-12T02:47:39Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-12T02:47:38Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-12T02:47:39Z' + cf-cache-status: + - DYNAMIC + content-length: + - '449' + request-id: + - req_011CY3Qp3qjSQQbCT4NAu6JL + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1403' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml index fc2c5372a9..e0c1492b71 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml @@ -1642,4 +1642,146 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 50, + "messages": [ + { + "role": "user", + "content": "Say hello." + } + ], + "model": "claude-sonnet-4-20250514", + "stop_sequences": [ + "STOP" + ], + "temperature": 0.7, + "top_k": 40, + "top_p": 0.9 + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '171' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01XjNmHT85KYJCsZxYQ2vshk", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello! How are you doing today?" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 10, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 11, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cc8c327d948381d-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Thu, 12 Feb 2026 02:47:38 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-12T02:47:37Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-12T02:47:38Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-12T02:47:37Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-12T02:47:37Z' + cf-cache-status: + - DYNAMIC + content-length: + - '467' + request-id: + - req_011CY3Qown73cxcgWpMdjvwD + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1111' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml index 38562c0b1f..360923e784 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml @@ -1050,4 +1050,140 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01RsJuC6Y9KAXnjygdT2SMUF","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cc8c3737bbac54d-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Thu, 12 Feb 2026 02:47:49 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-12T02:47:49Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-12T02:47:49Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-12T02:47:49Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-12T02:47:49Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY3QpqWbUfUqudtPaQNEd + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '809' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_captures_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_captures_content.yaml index cd2b74e168..203b1e6e3d 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_captures_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_captures_content.yaml @@ -1050,4 +1050,140 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01GnHSTMpypTVe48XcA8Lr6j","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cc8c37aabd8862e-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Thu, 12 Feb 2026 02:47:51 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-12T02:47:50Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-12T02:47:50Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-12T02:47:50Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-12T02:47:50Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY3QpvRmmawqP6RzUgk9w + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1114' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_double_exit_idempotent.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_double_exit_idempotent.yaml index a6a18ad0db..fc14c0b6e3 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_double_exit_idempotent.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_double_exit_idempotent.yaml @@ -552,4 +552,143 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hi in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '128' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_015Bir6aMGpKqmjBGTYzz33d","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"}} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cc8c3cccf9d33d5-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Thu, 12 Feb 2026 02:48:04 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-12T02:48:03Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-12T02:48:03Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-12T02:48:03Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-12T02:48:03Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY3QqtetfD18dHQSNmqrm + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1161' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml index 3383829def..97cc87b381 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml @@ -1065,4 +1065,143 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Count to 3." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '120' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01BnnAcU5gZLrsARmcACoPQj","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"1,"}} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" 2, 3"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cc8c3c4a96b438b-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Thu, 12 Feb 2026 02:48:02 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-12T02:48:02Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-12T02:48:02Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-12T02:48:02Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-12T02:48:02Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY3Qqo6mcmVdxkDiXWn69 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '858' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml index f8ceb77e5a..a98166af39 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml @@ -1146,4 +1146,149 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 50, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514", + "temperature": 0.7, + "top_k": 40, + "top_p": 0.9, + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '156' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01QD2kpos8jPR1zTUSnYscYE","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"! How"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are you doing today?"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cc8c3bc5ac7eef5-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Thu, 12 Feb 2026 02:48:01 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-12T02:48:00Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-12T02:48:00Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-12T02:48:00Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-12T02:48:00Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY3QqhPihXbU8w8ovz969 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '877' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/conftest.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/conftest.py index 18f5d8835e..3e7a087d0b 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/conftest.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/conftest.py @@ -41,6 +41,7 @@ ) from opentelemetry.util.genai.environment_variables import ( OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT, + OTEL_INSTRUMENTATION_GENAI_EMIT_EVENT, ) @@ -163,6 +164,31 @@ def instrument_with_content(tracer_provider, logger_provider, meter_provider): instrumentor.uninstrument() +@pytest.fixture(scope="function") +def instrument_event_only(tracer_provider, logger_provider, meter_provider): + """Instrument Anthropic with EVENT_ONLY content capture.""" + _OpenTelemetrySemanticConventionStability._initialized = False + os.environ.update( + { + OTEL_SEMCONV_STABILITY_OPT_IN: "gen_ai_latest_experimental", + OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT: "EVENT_ONLY", + OTEL_INSTRUMENTATION_GENAI_EMIT_EVENT: "true", + } + ) + instrumentor = AnthropicInstrumentor() + instrumentor.instrument( + tracer_provider=tracer_provider, + logger_provider=logger_provider, + meter_provider=meter_provider, + ) + + yield instrumentor + os.environ.pop(OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT, None) + os.environ.pop(OTEL_SEMCONV_STABILITY_OPT_IN, None) + os.environ.pop(OTEL_INSTRUMENTATION_GENAI_EMIT_EVENT, None) + instrumentor.uninstrument() + + @pytest.fixture def instrument_anthropic(tracer_provider, logger_provider, meter_provider): """Fixture to instrument Anthropic with test providers.""" diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py index 5d04746583..1d889b90b6 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py @@ -953,3 +953,47 @@ def test_sync_messages_stream_connection_error( span = spans[0] assert span.attributes[GenAIAttributes.GEN_AI_REQUEST_MODEL] == model assert ErrorAttributes.ERROR_TYPE in span.attributes + + +# ============================================================================= +# Tests for EVENT_ONLY content capture mode +# ============================================================================= + + +@pytest.mark.vcr() +def test_sync_messages_create_event_only_no_content_in_span( + span_exporter, log_exporter, anthropic_client, instrument_event_only +): + """Test that EVENT_ONLY mode does not capture content in span attributes + but does emit a log event with the content.""" + model = "claude-sonnet-4-20250514" + messages = [{"role": "user", "content": "Say hello in one word."}] + + anthropic_client.messages.create( + model=model, + max_tokens=100, + messages=messages, + ) + + spans = span_exporter.get_finished_spans() + assert len(spans) == 1 + span = spans[0] + + # Content should NOT be in span attributes under EVENT_ONLY + assert GenAIAttributes.GEN_AI_INPUT_MESSAGES not in span.attributes + assert GenAIAttributes.GEN_AI_OUTPUT_MESSAGES not in span.attributes + + # Basic span attributes should still be present + assert span.attributes[GenAIAttributes.GEN_AI_REQUEST_MODEL] == model + assert GenAIAttributes.GEN_AI_RESPONSE_MODEL in span.attributes + assert GenAIAttributes.GEN_AI_USAGE_INPUT_TOKENS in span.attributes + assert GenAIAttributes.GEN_AI_USAGE_OUTPUT_TOKENS in span.attributes + + # A log event should have been emitted with the content + logs = log_exporter.get_finished_logs() + assert len(logs) == 1 + log_record = logs[0].log_record + assert ( + log_record.event_name + == "gen_ai.client.inference.operation.details" + ) From d1af77822c0a237f8deaefac232d55dc12fa4faf Mon Sep 17 00:00:00 2001 From: Teja Date: Wed, 11 Feb 2026 21:53:03 -0500 Subject: [PATCH 16/35] Refactor assertion in sync messages test for clarity - Simplified the assertion statement in the test_sync_messages_create_event_only_no_content_in_span function to improve readability. --- .../tests/test_sync_messages.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py index 1d889b90b6..122283c50b 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py @@ -993,7 +993,4 @@ def test_sync_messages_create_event_only_no_content_in_span( logs = log_exporter.get_finished_logs() assert len(logs) == 1 log_record = logs[0].log_record - assert ( - log_record.event_name - == "gen_ai.client.inference.operation.details" - ) + assert log_record.event_name == "gen_ai.client.inference.operation.details" From 401e1b1175879391006d1a95499c0c6dd76773bb Mon Sep 17 00:00:00 2001 From: Teja Date: Fri, 13 Feb 2026 18:52:09 -0500 Subject: [PATCH 17/35] Refactor content capture logic and enhance streaming tests for Anthropic instrumentation. --- .../instrumentation/anthropic/utils.py | 17 +- ...st_stream_wrapper_finalize_idempotent.yaml | 132 ++++++++++++++ .../test_sync_messages_create_api_error.yaml | 96 ++++++++++ .../test_sync_messages_create_basic.yaml | 136 +++++++++++++++ ...sync_messages_create_captures_content.yaml | 136 +++++++++++++++ ...ages_create_captures_thinking_content.yaml | 145 ++++++++++++++++ ...ages_create_captures_tool_use_content.yaml | 164 ++++++++++++++++++ ..._create_event_only_no_content_in_span.yaml | 136 +++++++++++++++ ...test_sync_messages_create_stop_reason.yaml | 136 +++++++++++++++ .../test_sync_messages_create_streaming.yaml | 132 ++++++++++++++ ...ges_create_streaming_captures_content.yaml | 132 ++++++++++++++ ...c_messages_create_streaming_iteration.yaml | 138 +++++++++++++++ ...test_sync_messages_create_token_usage.yaml | 136 +++++++++++++++ ..._sync_messages_create_with_all_params.yaml | 142 +++++++++++++++ .../test_sync_messages_stream_basic.yaml | 136 +++++++++++++++ ...sync_messages_stream_captures_content.yaml | 136 +++++++++++++++ ...essages_stream_double_exit_idempotent.yaml | 139 +++++++++++++++ ...test_sync_messages_stream_token_usage.yaml | 136 +++++++++++++++ ...test_sync_messages_stream_with_params.yaml | 148 ++++++++++++++++ .../src/opentelemetry/util/genai/utils.py | 12 ++ 20 files changed, 2469 insertions(+), 16 deletions(-) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py index 4c870cf441..67e6a691e1 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py @@ -43,10 +43,7 @@ ToolCallResponse, ) from opentelemetry.util.genai.utils import ( - ContentCapturingMode, - get_content_capturing_mode, - is_experimental_mode, - should_emit_event, + should_capture_content, ) from opentelemetry.util.types import AttributeValue @@ -144,18 +141,6 @@ def _extract_usage_tokens( ) -def should_capture_content() -> bool: - """Return True when content conversion should be performed.""" - if not is_experimental_mode(): - return False - mode = get_content_capturing_mode() - if mode == ContentCapturingMode.NO_CONTENT: - return False - if mode == ContentCapturingMode.EVENT_ONLY and not should_emit_event(): - return False - return True - - def _get_field(obj: Any, name: str, default: Any = None) -> Any: if isinstance(obj, dict): return cast(dict[str, Any], obj).get(name, default) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml index cc7cc069b4..453b1b74a3 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml @@ -791,4 +791,136 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_017HqurdrPRjjcJk9VmHy3BN","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}}} + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cd82ebecf4b6180-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Fri, 13 Feb 2026 23:42:31 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-13T23:42:30Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-13T23:42:30Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-13T23:42:30Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-13T23:42:30Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY6xK3zLotRudMjixxsHz + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1042' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml index 9949e6c479..19b2eb1355 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml @@ -1290,4 +1290,100 @@ interactions: status: code: 404 message: Not Found +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Hello" + } + ], + "model": "invalid-model-name" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '94' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "type": "error", + "error": { + "type": "not_found_error", + "message": "model: invalid-model-name" + }, + "request_id": "req_011CY6xHZmvghhuS5mgC2ByE" + } + headers: + CF-RAY: + - 9cd82e409e0d8c27-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Fri, 13 Feb 2026 23:42:10 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + cf-cache-status: + - DYNAMIC + content-length: + - '133' + request-id: + - req_011CY6xHZmvghhuS5mgC2ByE + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '194' + x-should-retry: + - 'false' + status: + code: 404 + message: Not Found version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml index 4f4835c756..f4366c102a 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml @@ -2019,4 +2019,140 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '117' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01HpCE3eMAt15ZVvxtYwAdVv", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello!" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 13, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 5, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cd82dd6fb394fb3-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Fri, 13 Feb 2026 23:41:54 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-13T23:41:54Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-13T23:41:54Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-13T23:41:53Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-13T23:41:54Z' + cf-cache-status: + - DYNAMIC + content-length: + - '441' + request-id: + - req_011CY6xGKPxjLJpdDmNXrKfY + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1182' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml index f441184e5e..519badff61 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml @@ -2019,4 +2019,140 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '117' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01ASX8rG4atqMREVf7tYuJFG", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello!" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 13, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 5, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cd82de07fb54544-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Fri, 13 Feb 2026 23:41:55 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-13T23:41:55Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-13T23:41:55Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-13T23:41:54Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-13T23:41:55Z' + cf-cache-status: + - DYNAMIC + content-length: + - '441' + request-id: + - req_011CY6xGRstfeY6iyeKp3W2T + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1234' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml index e4f03a8ded..51ca4cce14 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml @@ -390,4 +390,149 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 16000, + "messages": [ + { + "role": "user", + "content": "What is 17*19? Think first." + } + ], + "model": "claude-sonnet-4-20250514", + "thinking": { + "type": "enabled", + "budget_tokens": 10000 + } + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '176' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01DcB32cwfGMHtiDGUBij77d", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "thinking", + "thinking": "I need to calculate 17 * 19.\n\nLet me think about this step by step.\n\nI can use the standard multiplication method:\n17 * 19\n\nOne way is to break this down:\n17 * 19 = 17 * (20 - 1) = 17 * 20 - 17 * 1 = 340 - 17 = 323\n\nLet me double-check this another way:\n19 * 17 = 19 * (10 + 7) = 19 * 10 + 19 * 7 = 190 + 133\n\nNow I need to calculate 19 * 7:\n19 * 7 = (20 - 1) * 7 = 20 * 7 - 1 * 7 = 140 - 7 = 133\n\nSo: 190 + 133 = 323\n\nBoth methods give me 323, so that should be correct.", + "signature": "EoAFCkYICxgCKkBXcBjcMdTOeEo8YcimnUeQ6/5AWg0k7fc7hWm28+twAOyMSpID9V8deQAcscFb03tg/oJhlDlowC+4qpccFMDiEgzV/xet2tQ877zlQlgaDGk+lfb8EHdSSw/vHCIw4Jj5mnz2Sp9j/+r9FPnPCqq6DJyAGYLA3kIq8KUbi0/BcTWpaAuFXOk9MBARTnfXKucD1Cw8HNx+RbgKx7ab7T2eb5m6ZBE4oL4D++UBS4bky7dUEEWux+CYZVnnn8w+DBQS/hAwXJritlIF8W0/E3VVdmFnsHfzKNNIxiHbyqIh+jJfRqF9tmYTDro/07Xgn1O9NqOreF8t4uq6SVicy7gUUJcliFC3tJUoHG29HAS3SdCtjiZTpj9YDWj2ZbyLehsKyY4/F4xRur/fe+oyrX1/BHwC4Q16UE95MRtIpqc4X/xbw5NFI1nGPBeP1EVISiqAr+E6OGteJMhbBUX54Zv4B9WduabUidsR4WB5A512Dfz7ozgRMOlZwbYGtHULxK0plAHQqSAmwsVkNBrWXwYscUUCPIHCd+pKy5rRqgV6HnpTBy/S3sziy30PapARjdaJjh0L1wwusjh8G2zretOsxHerWajsJoNJNu32E6kPkeItg5XxK9sx2E9iEdqCq6bAp2Wb67HLdVynO1A/45toa5ayM6vYOWtG/Ko/7M4PDJKDTSOl7TqXpZMvJVsCne3Jr7ia5McdSeYtTdqsgp4HlBWKuQ1Up+hpb46w2xcvzIeQzKfbLH+PLps4INaiRljqv/PYvTNiH4cxfqX+9th/Xz9EcLzRIrU7WvyxFT4TSAmOUVBxh+SkScn/tfVp8ShyCBzUixbVdRgB" + }, + { + "type": "text", + "text": "Let me work through this multiplication step by step.\n\n17 \u00d7 19\n\nI can break this down using the distributive property:\n17 \u00d7 19 = 17 \u00d7 (20 - 1)\n= 17 \u00d7 20 - 17 \u00d7 1\n= 340 - 17\n= 323\n\nLet me verify with another approach:\n17 \u00d7 19 = (10 + 7) \u00d7 19\n= 10 \u00d7 19 + 7 \u00d7 19\n= 190 + 133\n= 323\n\nTherefore, 17 \u00d7 19 = 323." + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 46, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 383, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cd82e9ddc1419c7-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Fri, 13 Feb 2026 23:42:30 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-13T23:42:25Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-13T23:42:30Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-13T23:42:25Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-13T23:42:25Z' + cf-cache-status: + - DYNAMIC + content-length: + - '2165' + request-id: + - req_011CY6xJfRXgTVmeCFV7sX15 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '5055' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml index a2d4b350c0..69e9943bd1 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml @@ -482,4 +482,168 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 256, + "messages": [ + { + "role": "user", + "content": "What is the weather in SF?" + } + ], + "model": "claude-sonnet-4-20250514", + "tool_choice": { + "type": "tool", + "name": "get_weather" + }, + "tools": [ + { + "name": "get_weather", + "description": "Get weather by city", + "input_schema": { + "type": "object", + "properties": { + "city": { + "type": "string" + } + }, + "required": [ + "city" + ] + } + } + ] + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '334' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01Yac3xgAwuAo8q33U9YT8vC", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "tool_use", + "id": "toolu_01WYo8aAKBT31hEQzKnrK8Cq", + "name": "get_weather", + "input": { + "city": "San Francisco" + }, + "caller": { + "type": "direct" + } + } + ], + "stop_reason": "tool_use", + "stop_sequence": null, + "usage": { + "input_tokens": 386, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 34, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cd82e943b37c34b-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Fri, 13 Feb 2026 23:42:24 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-13T23:42:24Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-13T23:42:24Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-13T23:42:23Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-13T23:42:24Z' + cf-cache-status: + - DYNAMIC + content-length: + - '550' + request-id: + - req_011CY6xJYrdqFBdaoUS1yCre + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1345' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml index d958a76609..422482606a 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml @@ -135,4 +135,140 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '117' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01VidmfDPxA3g6UHvKJ94mKg", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello!" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 13, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 5, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cd82eebdf34ae4c-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Fri, 13 Feb 2026 23:42:38 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-13T23:42:38Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-13T23:42:38Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-13T23:42:37Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-13T23:42:38Z' + cf-cache-status: + - DYNAMIC + content-length: + - '441' + request-id: + - req_011CY6xKanVwLJ3oYYvwKQtD + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1561' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml index 2a82e7fe46..e2c2907390 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml @@ -1700,4 +1700,140 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '102' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_019sMwyH2n7xqwoqcvcnJrpn", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hi! How are you doing today?" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 10, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 11, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cd82e2d0d188815-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Fri, 13 Feb 2026 23:42:08 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-13T23:42:08Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-13T23:42:08Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-13T23:42:07Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-13T23:42:08Z' + cf-cache-status: + - DYNAMIC + content-length: + - '464' + request-id: + - req_011CY6xHLFadWrxbEc4Gq2h6 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1381' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml index 3d25891c09..a166429646 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml @@ -1150,4 +1150,136 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01ECD5aYyRDZwE7pLF57iur3","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}}} + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cd82e434e02187f-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Fri, 13 Feb 2026 23:42:11 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-13T23:42:10Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-13T23:42:10Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-13T23:42:10Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-13T23:42:10Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY6xHbVMziDESSCKs8LPU + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '878' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml index ff91ba37d3..e068bde45c 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml @@ -1150,4 +1150,136 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01VYEaknA5ZXjy22Sig9SWjN","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cd82e4b3c72432c-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Fri, 13 Feb 2026 23:42:12 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-13T23:42:11Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-13T23:42:11Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-13T23:42:11Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-13T23:42:11Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY6xHgwHTRxFXsS6rpDZD + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1131' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml index 56d736635a..4534a7fd64 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml @@ -1219,4 +1219,142 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '116' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_012e4YtASKobtskDRfzWPTD3","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"! How"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are you doing today?"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } + + event: message_stop + data: {"type":"message_stop"} + + headers: + CF-RAY: + - 9cd82e54eb8a1768-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Fri, 13 Feb 2026 23:42:14 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-13T23:42:13Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-13T23:42:13Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-13T23:42:13Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-13T23:42:13Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY6xHoXQudgmTiYH5BPvv + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1141' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml index 99c812ac23..920f05db59 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml @@ -1700,4 +1700,140 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Count to 5." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '106' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_017ELW7Px1dL94WeMFzhuzqt", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "1\n2\n3\n4\n5" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 12, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 13, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cd82e23fef3ffd0-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Fri, 13 Feb 2026 23:42:06 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-13T23:42:06Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-13T23:42:06Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-13T23:42:05Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-13T23:42:06Z' + cf-cache-status: + - DYNAMIC + content-length: + - '449' + request-id: + - req_011CY6xHE5Fo2oiAKNJvbd1E + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1108' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml index e0c1492b71..8c9e9d3424 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml @@ -1784,4 +1784,146 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 50, + "messages": [ + { + "role": "user", + "content": "Say hello." + } + ], + "model": "claude-sonnet-4-20250514", + "stop_sequences": [ + "STOP" + ], + "temperature": 0.7, + "top_k": 40, + "top_p": 0.9 + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '171' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01Ly9k5DaT77qrCaFbJcvXCB", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello! How are you doing today?" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 10, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 11, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cd82de9e935425d-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Fri, 13 Feb 2026 23:42:05 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-13T23:42:04Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-13T23:42:05Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-13T23:41:56Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-13T23:42:04Z' + cf-cache-status: + - DYNAMIC + content-length: + - '467' + request-id: + - req_011CY6xGYRY18pDRpFzqXtL9 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '8990' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml index 360923e784..56a6679846 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml @@ -1186,4 +1186,140 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01RmBQxjwg8mkrmo7K8ECbF7","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0} + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5}} + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cd82e672bb1de93-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Fri, 13 Feb 2026 23:42:21 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-13T23:42:16Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-13T23:42:16Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-13T23:42:16Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-13T23:42:16Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY6xJ22F2nKdk1tCjAuzK + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '5599' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_captures_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_captures_content.yaml index 203b1e6e3d..ec6f7c4b2c 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_captures_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_captures_content.yaml @@ -1186,4 +1186,140 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01VMJM8turEeKoG2yi2pfN5P","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":5,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5}} + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cd82e8cbab0b785-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Fri, 13 Feb 2026 23:42:23 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-13T23:42:22Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-13T23:42:22Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-13T23:42:22Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-13T23:42:22Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY6xJTiKeZoAjo7d698Lk + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '899' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_double_exit_idempotent.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_double_exit_idempotent.yaml index fc14c0b6e3..8864096ea6 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_double_exit_idempotent.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_double_exit_idempotent.yaml @@ -691,4 +691,143 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hi in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '128' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01Qaw9xzrXn2ZaNPHKd3Evi9","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0} + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cd82edae9e5f534-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Fri, 13 Feb 2026 23:42:35 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-13T23:42:34Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-13T23:42:34Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-13T23:42:34Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-13T23:42:34Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY6xKPCzEg7wiWgbyBJCf + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '984' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml index 97cc87b381..dd3840a6b0 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml @@ -1204,4 +1204,140 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Count to 3." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '120' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01RiA1BaibUZHLSZrmCCAcaf","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"1, 2, 3."} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":12} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cd82ed16f794270-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Fri, 13 Feb 2026 23:42:34 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-13T23:42:33Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-13T23:42:33Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-13T23:42:33Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-13T23:42:33Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY6xKGm3HwUNA9aoLvcxU + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1080' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml index a98166af39..bcd1242596 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml @@ -1291,4 +1291,152 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 50, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514", + "temperature": 0.7, + "top_k": 40, + "top_p": 0.9, + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '156' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-helper-method: + - stream + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-stream-helper: + - messages + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01EUi17pxB8x7VdVPwKUsA57","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"! How"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" you doing today?"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cd82ec7c840c64a-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Fri, 13 Feb 2026 23:42:32 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-13T23:42:31Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-13T23:42:31Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-13T23:42:31Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-13T23:42:31Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CY6xKA9RNLZvhYtUPteUo + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1020' + status: + code: 200 + message: OK version: 1 diff --git a/util/opentelemetry-util-genai/src/opentelemetry/util/genai/utils.py b/util/opentelemetry-util-genai/src/opentelemetry/util/genai/utils.py index 616d9ab471..3fb6417cee 100644 --- a/util/opentelemetry-util-genai/src/opentelemetry/util/genai/utils.py +++ b/util/opentelemetry-util-genai/src/opentelemetry/util/genai/utils.py @@ -111,6 +111,18 @@ def should_emit_event() -> bool: return False +def should_capture_content() -> bool: + """Return True when content conversion should be performed.""" + if not is_experimental_mode(): + return False + mode = get_content_capturing_mode() + if mode == ContentCapturingMode.NO_CONTENT: + return False + if mode == ContentCapturingMode.EVENT_ONLY and not should_emit_event(): + return False + return True + + class _GenAiJsonEncoder(json.JSONEncoder): def default(self, o: Any) -> Any: if isinstance(o, bytes): From 15d1b05629c747e80b2291954c53af7bc15ea6b4 Mon Sep 17 00:00:00 2001 From: Teja Date: Fri, 13 Feb 2026 18:55:47 -0500 Subject: [PATCH 18/35] unsetting the model. --- .../src/opentelemetry/instrumentation/anthropic/patch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py index c69c8681eb..422c682468 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py @@ -64,7 +64,7 @@ def traced_method( request_model = ( request_model_attribute if isinstance(request_model_attribute, str) - else params.model or "" + else params.model ) capture_content = should_capture_content() @@ -120,7 +120,7 @@ def traced_method( request_model = ( request_model_attribute if isinstance(request_model_attribute, str) - else params.model or "" + else params.model ) capture_content = should_capture_content() From 7800a0e3c15ca41a207f90b8657388bb4399bbdd Mon Sep 17 00:00:00 2001 From: Teja Date: Mon, 16 Feb 2026 17:56:03 -0500 Subject: [PATCH 19/35] Remove instrumentation for Messages.stream() and refactor related code. Introduced MessageWrapper and StreamWrapper classes for telemetry handling. Updated tests to reflect changes in instrumentation behavior. --- .../instrumentation/anthropic/__init__.py | 12 - .../instrumentation/anthropic/patch.py | 56 +-- .../instrumentation/anthropic/utils.py | 324 +----------------- .../instrumentation/anthropic/wrappers.py | 323 +++++++++++++++++ .../tests/test_sync_messages.py | 73 +--- 5 files changed, 343 insertions(+), 445 deletions(-) create mode 100644 instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/__init__.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/__init__.py index cac7db6d14..f5286438a4 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/__init__.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/__init__.py @@ -56,7 +56,6 @@ from opentelemetry.instrumentation.anthropic.package import _instruments from opentelemetry.instrumentation.anthropic.patch import ( messages_create, - messages_stream, ) from opentelemetry.instrumentation.instrumentor import BaseInstrumentor from opentelemetry.instrumentation.utils import unwrap @@ -107,13 +106,6 @@ def _instrument(self, **kwargs: Any) -> None: wrapper=messages_create(handler), ) - # Patch Messages.stream - wrap_function_wrapper( - module="anthropic.resources.messages", - name="Messages.stream", - wrapper=messages_stream(handler), - ) - def _uninstrument(self, **kwargs: Any) -> None: """Disable Anthropic instrumentation. @@ -125,7 +117,3 @@ def _uninstrument(self, **kwargs: Any) -> None: anthropic.resources.messages.Messages, # pyright: ignore[reportAttributeAccessIssue,reportUnknownMemberType,reportUnknownArgumentType] "create", ) - unwrap( - anthropic.resources.messages.Messages, # pyright: ignore[reportAttributeAccessIssue,reportUnknownMemberType,reportUnknownArgumentType] - "stream", - ) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py index 422c682468..c4007e6a46 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py @@ -22,10 +22,11 @@ from opentelemetry.util.genai.handler import TelemetryHandler from opentelemetry.util.genai.types import Error, LLMInvocation -from .utils import ( - MessageStreamManagerWrapper, +from .wrappers import ( MessageWrapper, StreamWrapper, +) +from .utils import ( extract_params, get_input_messages, get_llm_request_attributes, @@ -35,7 +36,6 @@ if TYPE_CHECKING: from anthropic._streaming import Stream - from anthropic.lib.streaming import MessageStreamManager from anthropic.resources.messages import Messages from anthropic.types import Message, RawMessageStreamEvent @@ -99,53 +99,3 @@ def traced_method( raise return traced_method # type: ignore[return-value] - - -def messages_stream( - handler: TelemetryHandler, -) -> Callable[..., "MessageStreamManager"]: - """Wrap the `stream` method of the `Messages` class to trace it.""" - - def traced_method( - wrapped: Callable[..., "MessageStreamManager"], - instance: "Messages", - args: tuple[Any, ...], - kwargs: dict[str, Any], - ) -> MessageStreamManagerWrapper: - params = extract_params(*args, **kwargs) - attributes = get_llm_request_attributes(params, instance) - request_model_attribute = attributes.get( - GenAIAttributes.GEN_AI_REQUEST_MODEL - ) - request_model = ( - request_model_attribute - if isinstance(request_model_attribute, str) - else params.model - ) - - capture_content = should_capture_content() - invocation = LLMInvocation( - request_model=request_model, - provider=ANTHROPIC, - input_messages=get_input_messages(params.messages) - if capture_content - else [], - system_instruction=get_system_instruction(params.system) - if capture_content - else [], - attributes=attributes, - ) - - # Start the span before calling the wrapped method - handler.start_llm(invocation) - try: - result = wrapped(*args, **kwargs) - # Return wrapped MessageStreamManager - return MessageStreamManagerWrapper(result, handler, invocation) - except Exception as exc: - handler.fail_llm( - invocation, Error(message=str(exc), type=type(exc)) - ) - raise - - return traced_method # type: ignore[return-value] diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py index 67e6a691e1..def97159d6 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py @@ -20,7 +20,7 @@ import json import logging from dataclasses import dataclass -from typing import TYPE_CHECKING, Any, Iterator, Optional, Sequence, cast +from typing import TYPE_CHECKING, Any, Optional, Sequence, cast from urllib.parse import urlparse from opentelemetry.semconv._incubating.attributes import ( @@ -29,12 +29,9 @@ from opentelemetry.semconv._incubating.attributes import ( server_attributes as ServerAttributes, ) -from opentelemetry.util.genai.handler import TelemetryHandler from opentelemetry.util.genai.types import ( Blob, - Error, InputMessage, - LLMInvocation, MessagePart, OutputMessage, Reasoning, @@ -48,13 +45,8 @@ from opentelemetry.util.types import AttributeValue if TYPE_CHECKING: - from anthropic._streaming import Stream - from anthropic.lib.streaming import ( - MessageStream, - MessageStreamManager, - ) from anthropic.resources.messages import Messages - from anthropic.types import Message, RawMessageStreamEvent + from anthropic.types import Message _logger = logging.getLogger(__name__) @@ -435,315 +427,3 @@ def get_llm_request_attributes( # Filter out None values return {k: v for k, v in attributes.items() if v is not None} - - -class MessageWrapper: - """Wrapper for non-streaming Message response that handles telemetry. - - This wrapper extracts telemetry data from the response and finalizes - the span immediately since the response is complete. - """ - - def __init__(self, message: "Message"): - self._message = message - - def extract_into(self, invocation: LLMInvocation) -> None: - """Extract response data into the invocation.""" - if self._message.model: - invocation.response_model_name = self._message.model - - if self._message.id: - invocation.response_id = self._message.id - - finish_reason = _normalize_finish_reason(self._message.stop_reason) - if finish_reason: - invocation.finish_reasons = [finish_reason] - - if self._message.usage: - ( - input_tokens, - output_tokens, - cache_creation_input_tokens, - cache_read_input_tokens, - ) = _extract_usage_tokens(self._message.usage) - invocation.input_tokens = input_tokens - invocation.output_tokens = output_tokens - if cache_creation_input_tokens is not None: - invocation.attributes[ - _GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS - ] = cache_creation_input_tokens - if cache_read_input_tokens is not None: - invocation.attributes[ - _GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS - ] = cache_read_input_tokens - - if should_capture_content(): - invocation.output_messages = get_output_messages_from_message( - self._message - ) - - @property - def message(self) -> "Message": - """Return the wrapped Message object.""" - return self._message - - -class StreamWrapper(Iterator["RawMessageStreamEvent"]): - """Wrapper for Anthropic Stream that handles telemetry. - - This wrapper wraps Stream[RawMessageStreamEvent] returned by - Messages.create(stream=True). It processes streaming chunks, - extracts telemetry data, and ensures the span is properly ended - when the stream is consumed. - """ - - def __init__( - self, - stream: "Stream[RawMessageStreamEvent]", - handler: TelemetryHandler, - invocation: LLMInvocation, - ): - self._stream = stream - self._handler = handler - self._invocation = invocation - self._response_id: Optional[str] = None - self._response_model: Optional[str] = None - self._stop_reason: Optional[str] = None - self._input_tokens: Optional[int] = None - self._output_tokens: Optional[int] = None - self._cache_creation_input_tokens: Optional[int] = None - self._cache_read_input_tokens: Optional[int] = None - self._capture_content = should_capture_content() - self._content_blocks: dict[int, dict[str, Any]] = {} - self._finalized = False - - def _update_usage(self, usage: Any | None) -> None: - ( - input_tokens, - output_tokens, - cache_creation_input_tokens, - cache_read_input_tokens, - ) = _extract_usage_tokens(usage) - if input_tokens is not None: - self._input_tokens = input_tokens - if output_tokens is not None: - self._output_tokens = output_tokens - if cache_creation_input_tokens is not None: - self._cache_creation_input_tokens = cache_creation_input_tokens - if cache_read_input_tokens is not None: - self._cache_read_input_tokens = cache_read_input_tokens - - def _process_chunk(self, chunk: "RawMessageStreamEvent") -> None: - """Extract telemetry data from a streaming chunk.""" - # Handle message_start event - contains initial message info - if chunk.type == "message_start": - message = getattr(chunk, "message", None) - if message: - if hasattr(message, "id") and message.id: - self._response_id = message.id - if hasattr(message, "model") and message.model: - self._response_model = message.model - # message_start also contains initial usage with input_tokens - if hasattr(message, "usage") and message.usage: - self._update_usage(message.usage) - - # Handle message_delta event - contains stop_reason and output token usage - elif chunk.type == "message_delta": - delta = getattr(chunk, "delta", None) - if delta and hasattr(delta, "stop_reason") and delta.stop_reason: - self._stop_reason = _normalize_finish_reason(delta.stop_reason) - # message_delta contains usage with output_tokens (and may repeat input_tokens) - usage = getattr(chunk, "usage", None) - self._update_usage(usage) - elif self._capture_content and chunk.type == "content_block_start": - index = _get_field(chunk, "index") - content_block = _get_field(chunk, "content_block") - if isinstance(index, int): - self._content_blocks[index] = _create_stream_block_state( - content_block - ) - elif self._capture_content and chunk.type == "content_block_delta": - index = _get_field(chunk, "index") - delta = _get_field(chunk, "delta") - if isinstance(index, int) and delta is not None: - block = self._content_blocks.setdefault(index, {}) - _update_stream_block_state(block, delta) - - def _finalize_invocation(self) -> None: - """Update invocation with collected data and stop the span.""" - if self._finalized: - return - self._finalized = True - - if self._response_model: - self._invocation.response_model_name = self._response_model - if self._response_id: - self._invocation.response_id = self._response_id - if self._stop_reason: - self._invocation.finish_reasons = [self._stop_reason] - if self._input_tokens is not None: - self._invocation.input_tokens = self._input_tokens - if self._output_tokens is not None: - self._invocation.output_tokens = self._output_tokens - if self._cache_creation_input_tokens is not None: - self._invocation.attributes[ - _GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS - ] = self._cache_creation_input_tokens - if self._cache_read_input_tokens is not None: - self._invocation.attributes[ - _GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS - ] = self._cache_read_input_tokens - - if self._capture_content and self._content_blocks: - parts: list[MessagePart] = [] - for index in sorted(self._content_blocks): - part = _stream_block_state_to_part(self._content_blocks[index]) - if part is not None: - parts.append(part) - self._invocation.output_messages = [ - OutputMessage( - role="assistant", - parts=parts, - finish_reason=self._stop_reason or "", - ) - ] - - self._handler.stop_llm(self._invocation) - - def __iter__(self) -> "StreamWrapper": - return self - - def __next__(self) -> "RawMessageStreamEvent": - try: - chunk = next(self._stream) - self._process_chunk(chunk) - return chunk - except StopIteration: - self._finalize_invocation() - raise - except Exception as exc: - self._handler.fail_llm( - self._invocation, Error(message=str(exc), type=type(exc)) - ) - raise - - def __enter__(self) -> "StreamWrapper": - return self - - def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool: - self.close() - return False - - def close(self) -> None: - """Close the underlying stream and finalize telemetry.""" - if hasattr(self._stream, "close"): - self._stream.close() - self._finalize_invocation() - - -class MessageStreamManagerWrapper: - """Wrapper for MessageStreamManager that handles telemetry. - - This wrapper wraps the MessageStreamManager context manager returned by - Messages.stream(). It extracts telemetry data from the final message - when the context exits. - """ - - def __init__( - self, - stream_manager: "MessageStreamManager", - handler: TelemetryHandler, - invocation: LLMInvocation, - ): - self._stream_manager = stream_manager - self._handler = handler - self._invocation = invocation - self._message_stream: Optional["MessageStream"] = None - self._finalized = False - - def _finalize_success(self) -> None: - if self._finalized: - return - self._finalized = True - self._handler.stop_llm(self._invocation) - - def _finalize_error(self, exc_type: Any, exc_val: Any) -> None: - if self._finalized: - return - self._finalized = True - self._handler.fail_llm( - self._invocation, - Error( - message=str(exc_val) if exc_val else str(exc_type), - type=exc_type, - ), - ) - - def __enter__(self) -> "MessageStream": - """Enter the context and return the underlying MessageStream.""" - try: - self._message_stream = self._stream_manager.__enter__() - return self._message_stream - except Exception as exc: - # Handle errors during context entry (e.g., connection errors) - self._finalize_error(type(exc), exc) - raise - - def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool: - """Exit the context, extract telemetry, and finalize the span.""" - # Extract telemetry from the final message before exiting - if self._message_stream is not None and exc_type is None: - self._extract_telemetry_from_stream() - self._finalize_success() - elif exc_type is not None: - # Handle error case - self._finalize_error(exc_type, exc_val) - # Always exit the underlying stream manager - return self._stream_manager.__exit__(exc_type, exc_val, exc_tb) # type: ignore[return-value] - - def _extract_telemetry_from_stream(self) -> None: - """Extract telemetry data from the MessageStream's final message.""" - if self._message_stream is None: - return - - try: - # get_final_message() returns the accumulated Message object - final_message = self._message_stream.get_final_message() - - if final_message.model: - self._invocation.response_model_name = final_message.model - - if final_message.id: - self._invocation.response_id = final_message.id - - finish_reason = _normalize_finish_reason(final_message.stop_reason) - if finish_reason: - self._invocation.finish_reasons = [finish_reason] - - if final_message.usage: - ( - input_tokens, - output_tokens, - cache_creation_input_tokens, - cache_read_input_tokens, - ) = _extract_usage_tokens(final_message.usage) - self._invocation.input_tokens = input_tokens - self._invocation.output_tokens = output_tokens - if cache_creation_input_tokens is not None: - self._invocation.attributes[ - _GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS - ] = cache_creation_input_tokens - if cache_read_input_tokens is not None: - self._invocation.attributes[ - _GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS - ] = cache_read_input_tokens - if should_capture_content(): - self._invocation.output_messages = ( - get_output_messages_from_message(final_message) - ) - except Exception: # pylint: disable=broad-exception-caught - # If we can't get the final message, we still want to end the span - _logger.warning( - "Failed to extract telemetry from Anthropic MessageStream final message.", - exc_info=True, - ) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py new file mode 100644 index 0000000000..6bed13d0cd --- /dev/null +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py @@ -0,0 +1,323 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Iterator, Optional + +from opentelemetry.util.genai.handler import TelemetryHandler +from opentelemetry.util.genai.types import Error, LLMInvocation, MessagePart, OutputMessage +from opentelemetry.util.genai.utils import should_capture_content + +from .utils import ( + _GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS, + _GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS, + _create_stream_block_state, + _extract_usage_tokens, + _get_field, + _logger, + _normalize_finish_reason, + _stream_block_state_to_part, + _update_stream_block_state, + get_output_messages_from_message, +) + +if TYPE_CHECKING: + from anthropic._streaming import Stream + from anthropic.lib.streaming import ( + MessageStream, + MessageStreamManager, + ) + from anthropic.types import Message, RawMessageStreamEvent + + +class MessageWrapper: + """Wrapper for non-streaming Message response that handles telemetry.""" + + def __init__(self, message: "Message"): + self._message = message + + def extract_into(self, invocation: LLMInvocation) -> None: + """Extract response data into the invocation.""" + if self._message.model: + invocation.response_model_name = self._message.model + + if self._message.id: + invocation.response_id = self._message.id + + finish_reason = _normalize_finish_reason(self._message.stop_reason) + if finish_reason: + invocation.finish_reasons = [finish_reason] + + if self._message.usage: + ( + input_tokens, + output_tokens, + cache_creation_input_tokens, + cache_read_input_tokens, + ) = _extract_usage_tokens(self._message.usage) + invocation.input_tokens = input_tokens + invocation.output_tokens = output_tokens + if cache_creation_input_tokens is not None: + invocation.attributes[ + _GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS + ] = cache_creation_input_tokens + if cache_read_input_tokens is not None: + invocation.attributes[ + _GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS + ] = cache_read_input_tokens + + if should_capture_content(): + invocation.output_messages = get_output_messages_from_message( + self._message + ) + + @property + def message(self) -> "Message": + """Return the wrapped Message object.""" + return self._message + + +class StreamWrapper(Iterator["RawMessageStreamEvent"]): + """Wrapper for Anthropic Stream that handles telemetry.""" + + def __init__( + self, + stream: "Stream[RawMessageStreamEvent]", + handler: TelemetryHandler, + invocation: LLMInvocation, + ): + self._stream = stream + self._handler = handler + self._invocation = invocation + self._response_id: Optional[str] = None + self._response_model: Optional[str] = None + self._stop_reason: Optional[str] = None + self._input_tokens: Optional[int] = None + self._output_tokens: Optional[int] = None + self._cache_creation_input_tokens: Optional[int] = None + self._cache_read_input_tokens: Optional[int] = None + self._capture_content = should_capture_content() + self._content_blocks: dict[int, dict[str, Any]] = {} + self._finalized = False + + def _update_usage(self, usage: Any | None) -> None: + ( + input_tokens, + output_tokens, + cache_creation_input_tokens, + cache_read_input_tokens, + ) = _extract_usage_tokens(usage) + if input_tokens is not None: + self._input_tokens = input_tokens + if output_tokens is not None: + self._output_tokens = output_tokens + if cache_creation_input_tokens is not None: + self._cache_creation_input_tokens = cache_creation_input_tokens + if cache_read_input_tokens is not None: + self._cache_read_input_tokens = cache_read_input_tokens + + def _process_chunk(self, chunk: "RawMessageStreamEvent") -> None: + """Extract telemetry data from a streaming chunk.""" + if chunk.type == "message_start": + message = getattr(chunk, "message", None) + if message: + if hasattr(message, "id") and message.id: + self._response_id = message.id + if hasattr(message, "model") and message.model: + self._response_model = message.model + if hasattr(message, "usage") and message.usage: + self._update_usage(message.usage) + elif chunk.type == "message_delta": + delta = getattr(chunk, "delta", None) + if delta and hasattr(delta, "stop_reason") and delta.stop_reason: + self._stop_reason = _normalize_finish_reason(delta.stop_reason) + usage = getattr(chunk, "usage", None) + self._update_usage(usage) + elif self._capture_content and chunk.type == "content_block_start": + index = _get_field(chunk, "index") + content_block = _get_field(chunk, "content_block") + if isinstance(index, int): + self._content_blocks[index] = _create_stream_block_state( + content_block + ) + elif self._capture_content and chunk.type == "content_block_delta": + index = _get_field(chunk, "index") + delta = _get_field(chunk, "delta") + if isinstance(index, int) and delta is not None: + block = self._content_blocks.setdefault(index, {}) + _update_stream_block_state(block, delta) + + def _finalize_invocation(self) -> None: + if self._finalized: + return + self._finalized = True + + if self._response_model: + self._invocation.response_model_name = self._response_model + if self._response_id: + self._invocation.response_id = self._response_id + if self._stop_reason: + self._invocation.finish_reasons = [self._stop_reason] + if self._input_tokens is not None: + self._invocation.input_tokens = self._input_tokens + if self._output_tokens is not None: + self._invocation.output_tokens = self._output_tokens + if self._cache_creation_input_tokens is not None: + self._invocation.attributes[ + _GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS + ] = self._cache_creation_input_tokens + if self._cache_read_input_tokens is not None: + self._invocation.attributes[ + _GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS + ] = self._cache_read_input_tokens + + if self._capture_content and self._content_blocks: + parts: list[MessagePart] = [] + for index in sorted(self._content_blocks): + part = _stream_block_state_to_part(self._content_blocks[index]) + if part is not None: + parts.append(part) + self._invocation.output_messages = [ + OutputMessage( + role="assistant", + parts=parts, + finish_reason=self._stop_reason or "", + ) + ] + + self._handler.stop_llm(self._invocation) + + def __iter__(self) -> "StreamWrapper": + return self + + def __next__(self) -> "RawMessageStreamEvent": + try: + chunk = next(self._stream) + self._process_chunk(chunk) + return chunk + except StopIteration: + self._finalize_invocation() + raise + except Exception as exc: + self._handler.fail_llm( + self._invocation, Error(message=str(exc), type=type(exc)) + ) + raise + + def __enter__(self) -> "StreamWrapper": + return self + + def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool: + self.close() + return False + + def close(self) -> None: + if hasattr(self._stream, "close"): + self._stream.close() + self._finalize_invocation() + + +class MessageStreamManagerWrapper: + """Wrapper for MessageStreamManager that handles telemetry.""" + + def __init__( + self, + stream_manager: "MessageStreamManager", + handler: TelemetryHandler, + invocation: LLMInvocation, + ): + self._stream_manager = stream_manager + self._handler = handler + self._invocation = invocation + self._message_stream: Optional["MessageStream"] = None + self._finalized = False + + def _finalize_success(self) -> None: + if self._finalized: + return + self._finalized = True + self._handler.stop_llm(self._invocation) + + def _finalize_error(self, exc_type: Any, exc_val: Any) -> None: + if self._finalized: + return + self._finalized = True + self._handler.fail_llm( + self._invocation, + Error( + message=str(exc_val) if exc_val else str(exc_type), + type=exc_type, + ), + ) + + def __enter__(self) -> "MessageStream": + try: + self._message_stream = self._stream_manager.__enter__() + return self._message_stream + except Exception as exc: + self._finalize_error(type(exc), exc) + raise + + def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool: + if self._message_stream is not None and exc_type is None: + self._extract_telemetry_from_stream() + self._finalize_success() + elif exc_type is not None: + self._finalize_error(exc_type, exc_val) + return self._stream_manager.__exit__(exc_type, exc_val, exc_tb) # type: ignore[return-value] + + def _extract_telemetry_from_stream(self) -> None: + if self._message_stream is None: + return + + try: + final_message = self._message_stream.get_final_message() + + if final_message.model: + self._invocation.response_model_name = final_message.model + + if final_message.id: + self._invocation.response_id = final_message.id + + finish_reason = _normalize_finish_reason(final_message.stop_reason) + if finish_reason: + self._invocation.finish_reasons = [finish_reason] + + if final_message.usage: + ( + input_tokens, + output_tokens, + cache_creation_input_tokens, + cache_read_input_tokens, + ) = _extract_usage_tokens(final_message.usage) + self._invocation.input_tokens = input_tokens + self._invocation.output_tokens = output_tokens + if cache_creation_input_tokens is not None: + self._invocation.attributes[ + _GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS + ] = cache_creation_input_tokens + if cache_read_input_tokens is not None: + self._invocation.attributes[ + _GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS + ] = cache_read_input_tokens + if should_capture_content(): + self._invocation.output_messages = ( + get_output_messages_from_message(final_message) + ) + except Exception: # pylint: disable=broad-exception-caught + _logger.warning( + "Failed to extract telemetry from Anthropic MessageStream final message.", + exc_info=True, + ) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py index 122283c50b..5b39ac64e4 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py @@ -25,7 +25,7 @@ from anthropic.resources.messages import Messages as _Messages from opentelemetry.instrumentation.anthropic import AnthropicInstrumentor -from opentelemetry.instrumentation.anthropic.utils import ( +from opentelemetry.instrumentation.anthropic.wrappers import ( MessageWrapper, StreamWrapper, ) @@ -539,7 +539,7 @@ def test_sync_messages_create_streaming_connection_error( # ============================================================================= -# Tests for Messages.stream() method +# Tests for Messages.stream() method (not instrumented) # ============================================================================= @@ -547,7 +547,7 @@ def test_sync_messages_create_streaming_connection_error( def test_sync_messages_stream_basic( span_exporter, anthropic_client, instrument_no_content ): - """Test Messages.stream() produces correct span with context manager.""" + """Messages.stream() should not produce spans when uninstrumented.""" model = "claude-sonnet-4-20250514" messages = [{"role": "user", "content": "Say hello in one word."}] @@ -564,24 +564,14 @@ def test_sync_messages_stream_basic( assert response_text # Should have some text spans = span_exporter.get_finished_spans() - assert len(spans) == 1 - - assert_span_attributes( - spans[0], - request_model=model, - response_id=final_message.id, - response_model=final_message.model, - input_tokens=expected_input_tokens(final_message.usage), - output_tokens=final_message.usage.output_tokens, - finish_reasons=[normalize_stop_reason(final_message.stop_reason)], - ) + assert len(spans) == 0 @pytest.mark.vcr() def test_sync_messages_stream_captures_content( span_exporter, anthropic_client, instrument_with_content ): - """Test content capture on Messages.stream().""" + """Messages.stream() content capture should not emit spans.""" model = "claude-sonnet-4-20250514" messages = [{"role": "user", "content": "Say hello in one word."}] @@ -593,18 +583,7 @@ def test_sync_messages_stream_captures_content( _ = "".join(stream.text_stream) spans = span_exporter.get_finished_spans() - assert len(spans) == 1 - span = spans[0] - - input_messages = _load_span_messages( - span, GenAIAttributes.GEN_AI_INPUT_MESSAGES - ) - output_messages = _load_span_messages( - span, GenAIAttributes.GEN_AI_OUTPUT_MESSAGES - ) - assert input_messages[0]["role"] == "user" - assert output_messages[0]["role"] == "assistant" - assert output_messages[0]["parts"] + assert len(spans) == 0 @pytest.mark.vcr() @@ -847,7 +826,7 @@ def close(self): # pylint: disable=no-self-use def test_sync_messages_stream_with_params( span_exporter, anthropic_client, instrument_no_content ): - """Test Messages.stream() with additional parameters.""" + """Messages.stream() should remain uninstrumented with extra params.""" model = "claude-sonnet-4-20250514" messages = [{"role": "user", "content": "Say hi."}] @@ -863,21 +842,14 @@ def test_sync_messages_stream_with_params( _ = "".join(stream.text_stream) spans = span_exporter.get_finished_spans() - assert len(spans) == 1 - - span = spans[0] - assert span.attributes[GenAIAttributes.GEN_AI_REQUEST_MODEL] == model - assert span.attributes[GenAIAttributes.GEN_AI_REQUEST_MAX_TOKENS] == 50 - assert span.attributes[GenAIAttributes.GEN_AI_REQUEST_TEMPERATURE] == 0.7 - assert span.attributes[GenAIAttributes.GEN_AI_REQUEST_TOP_P] == 0.9 - assert span.attributes[GenAIAttributes.GEN_AI_REQUEST_TOP_K] == 40 + assert len(spans) == 0 @pytest.mark.vcr() def test_sync_messages_stream_token_usage( span_exporter, anthropic_client, instrument_no_content ): - """Test that Messages.stream() captures token usage correctly.""" + """Messages.stream() token usage should not be captured in spans.""" model = "claude-sonnet-4-20250514" messages = [{"role": "user", "content": "Count to 3."}] @@ -890,25 +862,15 @@ def test_sync_messages_stream_token_usage( final_message = stream.get_final_message() spans = span_exporter.get_finished_spans() - assert len(spans) == 1 - - span = spans[0] - assert GenAIAttributes.GEN_AI_USAGE_INPUT_TOKENS in span.attributes - assert GenAIAttributes.GEN_AI_USAGE_OUTPUT_TOKENS in span.attributes - assert span.attributes[ - GenAIAttributes.GEN_AI_USAGE_INPUT_TOKENS - ] == expected_input_tokens(final_message.usage) - assert ( - span.attributes[GenAIAttributes.GEN_AI_USAGE_OUTPUT_TOKENS] - == final_message.usage.output_tokens - ) + assert final_message.usage.output_tokens is not None + assert len(spans) == 0 @pytest.mark.vcr() def test_sync_messages_stream_double_exit_idempotent( span_exporter, anthropic_client, instrument_no_content ): - """Calling __exit__ twice should still emit only one span.""" + """Calling __exit__ twice should still emit no spans.""" model = "claude-sonnet-4-20250514" messages = [{"role": "user", "content": "Say hi in one word."}] @@ -923,14 +885,13 @@ def test_sync_messages_stream_double_exit_idempotent( manager.__exit__(None, None, None) # pylint: disable=unnecessary-dunder-call spans = span_exporter.get_finished_spans() - assert len(spans) == 1 - assert spans[0].attributes[GenAIAttributes.GEN_AI_REQUEST_MODEL] == model + assert len(spans) == 0 def test_sync_messages_stream_connection_error( span_exporter, instrument_no_content ): - """Test that connection errors in Messages.stream() are handled correctly.""" + """Connection errors in Messages.stream() should not create spans.""" model = "claude-sonnet-4-20250514" messages = [{"role": "user", "content": "Hello"}] @@ -948,11 +909,7 @@ def test_sync_messages_stream_connection_error( _ = "".join(stream.text_stream) spans = span_exporter.get_finished_spans() - assert len(spans) == 1 - - span = spans[0] - assert span.attributes[GenAIAttributes.GEN_AI_REQUEST_MODEL] == model - assert ErrorAttributes.ERROR_TYPE in span.attributes + assert len(spans) == 0 # ============================================================================= From df9911ef6a191fc6a196e788b57f218aa3dc7165 Mon Sep 17 00:00:00 2001 From: Teja Date: Mon, 16 Feb 2026 20:20:50 -0500 Subject: [PATCH 20/35] Refactor Anthropic instrumentation: reorganize imports, enhance utility functions, and update wrapper classes for better clarity and maintainability. Removed unused code and improved type safety in utility functions. Updated tests to reflect changes in the instrumentation behavior. --- .../instrumentation/anthropic/patch.py | 10 +- .../instrumentation/anthropic/utils.py | 55 +- .../instrumentation/anthropic/wrappers.py | 51 +- .../test_sync_messages_stream_basic.yaml | 1325 --------------- ...sync_messages_stream_captures_content.yaml | 1325 --------------- ...essages_stream_double_exit_idempotent.yaml | 833 ---------- ...test_sync_messages_stream_token_usage.yaml | 1343 --------------- ...test_sync_messages_stream_with_params.yaml | 1442 ----------------- .../tests/test_sync_messages.py | 138 -- 9 files changed, 56 insertions(+), 6466 deletions(-) delete mode 100644 instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml delete mode 100644 instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_captures_content.yaml delete mode 100644 instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_double_exit_idempotent.yaml delete mode 100644 instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml delete mode 100644 instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py index c4007e6a46..a343b9c2d0 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py @@ -21,17 +21,17 @@ ) from opentelemetry.util.genai.handler import TelemetryHandler from opentelemetry.util.genai.types import Error, LLMInvocation +from opentelemetry.util.genai.utils import should_capture_content -from .wrappers import ( - MessageWrapper, - StreamWrapper, -) from .utils import ( extract_params, get_input_messages, get_llm_request_attributes, get_system_instruction, - should_capture_content, +) +from .wrappers import ( + MessageWrapper, + StreamWrapper, ) if TYPE_CHECKING: diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py index def97159d6..1f97a1a8e9 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py @@ -18,7 +18,6 @@ import base64 import json -import logging from dataclasses import dataclass from typing import TYPE_CHECKING, Any, Optional, Sequence, cast from urllib.parse import urlparse @@ -39,16 +38,10 @@ ToolCall, ToolCallResponse, ) -from opentelemetry.util.genai.utils import ( - should_capture_content, -) from opentelemetry.util.types import AttributeValue if TYPE_CHECKING: from anthropic.resources.messages import Messages - from anthropic.types import Message - -_logger = logging.getLogger(__name__) @dataclass @@ -65,10 +58,10 @@ class MessageRequestParams: system: Any | None = None -_GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS = ( +GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS = ( "gen_ai.usage.cache_creation.input_tokens" ) -_GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS = "gen_ai.usage.cache_read.input_tokens" +GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS = "gen_ai.usage.cache_read.input_tokens" def _normalize_finish_reason(stop_reason: str | None) -> str | None: @@ -85,6 +78,20 @@ def _normalize_finish_reason(stop_reason: str | None) -> str | None: return normalized or stop_reason +def _get_field(obj: Any, name: str, default: Any = None) -> Any: + if isinstance(obj, dict): + return cast(dict[str, Any], obj).get(name, default) + return getattr(obj, name, default) + + +def _as_str(value: Any) -> str | None: + if value is None: + return None + if isinstance(value, str): + return value + return str(value) + + def _as_int(value: Any) -> int | None: if isinstance(value, bool): return None @@ -93,13 +100,10 @@ def _as_int(value: Any) -> int | None: return None -def _extract_usage_tokens( +def extract_usage_tokens( usage: Any | None, ) -> tuple[int | None, int | None, int | None, int | None]: - """Extract Anthropic usage fields and compute semconv input tokens. - - Returns `(total_input_tokens, output_tokens, cache_creation_input_tokens, cache_read_input_tokens)`. - """ + """Extract Anthropic usage fields and compute semconv input tokens.""" if usage is None: return None, None, None, None @@ -133,20 +137,6 @@ def _extract_usage_tokens( ) -def _get_field(obj: Any, name: str, default: Any = None) -> Any: - if isinstance(obj, dict): - return cast(dict[str, Any], obj).get(name, default) - return getattr(obj, name, default) - - -def _as_str(value: Any) -> str | None: - if value is None: - return None - if isinstance(value, str): - return value - return str(value) - - def _to_dict_if_possible(value: Any) -> Any: if isinstance(value, dict): return cast(dict[str, Any], value) @@ -261,7 +251,7 @@ def get_output_messages_from_message(message: Any) -> list[OutputMessage]: ] -def _create_stream_block_state(content_block: Any) -> dict[str, Any]: +def create_stream_block_state(content_block: Any) -> dict[str, Any]: block_type = _as_str(_get_field(content_block, "type")) or "text" state: dict[str, Any] = {"type": block_type} if block_type == "text": @@ -269,8 +259,7 @@ def _create_stream_block_state(content_block: Any) -> dict[str, Any]: elif block_type == "tool_use": state["id"] = _as_str(_get_field(content_block, "id")) state["name"] = _as_str(_get_field(content_block, "name")) or "" - input_value = _get_field(content_block, "input") - state["input"] = _to_dict_if_possible(input_value) + state["input"] = _get_field(content_block, "input") state["input_json"] = "" elif block_type in ("thinking", "redacted_thinking"): state["thinking"] = ( @@ -279,7 +268,7 @@ def _create_stream_block_state(content_block: Any) -> dict[str, Any]: return state -def _update_stream_block_state(state: dict[str, Any], delta: Any) -> None: +def update_stream_block_state(state: dict[str, Any], delta: Any) -> None: delta_type = _as_str(_get_field(delta, "type")) if delta_type == "text_delta": state["type"] = "text" @@ -303,7 +292,7 @@ def _update_stream_block_state(state: dict[str, Any], delta: Any) -> None: ) -def _stream_block_state_to_part(state: dict[str, Any]) -> MessagePart | None: +def stream_block_state_to_part(state: dict[str, Any]) -> MessagePart | None: block_type = _as_str(state.get("type")) if block_type == "text": return Text(content=_as_str(state.get("text")) or "") diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py index 6bed13d0cd..d6f5e78af6 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py @@ -14,23 +14,28 @@ from __future__ import annotations +import logging from typing import TYPE_CHECKING, Any, Iterator, Optional from opentelemetry.util.genai.handler import TelemetryHandler -from opentelemetry.util.genai.types import Error, LLMInvocation, MessagePart, OutputMessage +from opentelemetry.util.genai.types import ( + Error, + LLMInvocation, + MessagePart, + OutputMessage, +) from opentelemetry.util.genai.utils import should_capture_content from .utils import ( - _GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS, - _GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS, - _create_stream_block_state, - _extract_usage_tokens, + GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS, + GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS, _get_field, - _logger, _normalize_finish_reason, - _stream_block_state_to_part, - _update_stream_block_state, + create_stream_block_state, + extract_usage_tokens, get_output_messages_from_message, + stream_block_state_to_part, + update_stream_block_state, ) if TYPE_CHECKING: @@ -41,6 +46,8 @@ ) from anthropic.types import Message, RawMessageStreamEvent +_logger = logging.getLogger(__name__) + class MessageWrapper: """Wrapper for non-streaming Message response that handles telemetry.""" @@ -66,17 +73,17 @@ def extract_into(self, invocation: LLMInvocation) -> None: output_tokens, cache_creation_input_tokens, cache_read_input_tokens, - ) = _extract_usage_tokens(self._message.usage) + ) = extract_usage_tokens(self._message.usage) invocation.input_tokens = input_tokens invocation.output_tokens = output_tokens if cache_creation_input_tokens is not None: invocation.attributes[ - _GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS + GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS ] = cache_creation_input_tokens if cache_read_input_tokens is not None: - invocation.attributes[ - _GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS - ] = cache_read_input_tokens + invocation.attributes[GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS] = ( + cache_read_input_tokens + ) if should_capture_content(): invocation.output_messages = get_output_messages_from_message( @@ -118,7 +125,7 @@ def _update_usage(self, usage: Any | None) -> None: output_tokens, cache_creation_input_tokens, cache_read_input_tokens, - ) = _extract_usage_tokens(usage) + ) = extract_usage_tokens(usage) if input_tokens is not None: self._input_tokens = input_tokens if output_tokens is not None: @@ -149,7 +156,7 @@ def _process_chunk(self, chunk: "RawMessageStreamEvent") -> None: index = _get_field(chunk, "index") content_block = _get_field(chunk, "content_block") if isinstance(index, int): - self._content_blocks[index] = _create_stream_block_state( + self._content_blocks[index] = create_stream_block_state( content_block ) elif self._capture_content and chunk.type == "content_block_delta": @@ -157,7 +164,7 @@ def _process_chunk(self, chunk: "RawMessageStreamEvent") -> None: delta = _get_field(chunk, "delta") if isinstance(index, int) and delta is not None: block = self._content_blocks.setdefault(index, {}) - _update_stream_block_state(block, delta) + update_stream_block_state(block, delta) def _finalize_invocation(self) -> None: if self._finalized: @@ -176,17 +183,17 @@ def _finalize_invocation(self) -> None: self._invocation.output_tokens = self._output_tokens if self._cache_creation_input_tokens is not None: self._invocation.attributes[ - _GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS + GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS ] = self._cache_creation_input_tokens if self._cache_read_input_tokens is not None: self._invocation.attributes[ - _GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS + GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS ] = self._cache_read_input_tokens if self._capture_content and self._content_blocks: parts: list[MessagePart] = [] for index in sorted(self._content_blocks): - part = _stream_block_state_to_part(self._content_blocks[index]) + part = stream_block_state_to_part(self._content_blocks[index]) if part is not None: parts.append(part) self._invocation.output_messages = [ @@ -301,16 +308,16 @@ def _extract_telemetry_from_stream(self) -> None: output_tokens, cache_creation_input_tokens, cache_read_input_tokens, - ) = _extract_usage_tokens(final_message.usage) + ) = extract_usage_tokens(final_message.usage) self._invocation.input_tokens = input_tokens self._invocation.output_tokens = output_tokens if cache_creation_input_tokens is not None: self._invocation.attributes[ - _GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS + GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS ] = cache_creation_input_tokens if cache_read_input_tokens is not None: self._invocation.attributes[ - _GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS + GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS ] = cache_read_input_tokens if should_capture_content(): self._invocation.output_messages = ( diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml deleted file mode 100644 index 56a6679846..0000000000 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_basic.yaml +++ /dev/null @@ -1,1325 +0,0 @@ -interactions: -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01UtyS6wd4yzRVPNssPV1Wgg","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5}} - - event: message_stop - data: {"type":"message_stop"} - - headers: - CF-RAY: - - 9c72cf18d90042d7-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Sun, 01 Feb 2026 16:26:11 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '30000' - anthropic-ratelimit-input-tokens-remaining: - - '30000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-01T16:26:10Z' - anthropic-ratelimit-output-tokens-limit: - - '8000' - anthropic-ratelimit-output-tokens-remaining: - - '8000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-01T16:26:10Z' - anthropic-ratelimit-requests-limit: - - '50' - anthropic-ratelimit-requests-remaining: - - '49' - anthropic-ratelimit-requests-reset: - - '2026-02-01T16:26:12Z' - anthropic-ratelimit-tokens-limit: - - '38000' - anthropic-ratelimit-tokens-remaining: - - '38000' - anthropic-ratelimit-tokens-reset: - - '2026-02-01T16:26:10Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXhfLG1cM5qTFLjqKqPof - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1157' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "authentication_error", - "message": "invalid x-api-key" - }, - "request_id": "req_011CXwgSpckNmKSZ2zSSmGQe" - } - headers: - CF-RAY: - - 9cafd29a2a15edd5-EWR - Connection: - - keep-alive - Content-Length: - - '130' - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Mon, 09 Feb 2026 02:09:05 GMT - Server: - - cloudflare - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXwgSpckNmKSZ2zSSmGQe - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '11' - x-should-retry: - - 'false' - status: - code: 401 - message: Unauthorized -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01TYYPFFjh2MGYwMBT6dPtge","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cafd4877a208c99-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Mon, 09 Feb 2026 02:10:25 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-09T02:10:24Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-09T02:10:24Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-09T02:10:24Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-09T02:10:24Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXwgYe5evU3T1ocnZA3AN - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1116' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_013xhnC6x7oA5LvcJRG7U42t","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cb07f10cda0255d-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Mon, 09 Feb 2026 04:06:50 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-09T04:06:49Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-09T04:06:49Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-09T04:06:49Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-09T04:06:49Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXwqRYh4Vo9JgfndnBwzL - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1113' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01FSTci7pL3KTtDnAaqxTK7Z","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cb88a165a2fef9f-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Tue, 10 Feb 2026 03:32:29 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-10T03:32:27Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-10T03:32:27Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-10T03:32:27Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-10T03:32:27Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXygcRs4PZeVP1JqvbGoZ - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1885' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_014Rrw3BTA8R9AkwdwJ5rL7s","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cbfd2b7ddeaacc5-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Wed, 11 Feb 2026 00:45:23 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T00:45:22Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T00:45:22Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T00:45:22Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T00:45:22Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY1MgP15E4awNFDucwMoM - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '924' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01N6FeF1X4TkKZwjRVjXi9t6","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cc0d0fc5d98c338-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Wed, 11 Feb 2026 03:38:58 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T03:38:57Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T03:38:57Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T03:38:57Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T03:38:57Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY1av6kBJesRpLh98yFpz - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1012' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01RHawB9h7Wc5byj1Lnw87nh","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cc0d59a3b27f534-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Wed, 11 Feb 2026 03:42:07 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T03:42:06Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T03:42:06Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T03:42:06Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T03:42:06Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY1bA3Djmo1h7ryn18d1H - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '921' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01RsJuC6Y9KAXnjygdT2SMUF","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cc8c3737bbac54d-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Thu, 12 Feb 2026 02:47:49 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-12T02:47:49Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-12T02:47:49Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-12T02:47:49Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-12T02:47:49Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY3QpqWbUfUqudtPaQNEd - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '809' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01RmBQxjwg8mkrmo7K8ECbF7","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0} - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5}} - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cd82e672bb1de93-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Fri, 13 Feb 2026 23:42:21 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-13T23:42:16Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-13T23:42:16Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-13T23:42:16Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-13T23:42:16Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY6xJ22F2nKdk1tCjAuzK - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '5599' - status: - code: 200 - message: OK -version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_captures_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_captures_content.yaml deleted file mode 100644 index ec6f7c4b2c..0000000000 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_captures_content.yaml +++ /dev/null @@ -1,1325 +0,0 @@ -interactions: -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01UtyS6wd4yzRVPNssPV1Wgg","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5}} - - event: message_stop - data: {"type":"message_stop"} - - headers: - CF-RAY: - - 9c72cf18d90042d7-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Sun, 01 Feb 2026 16:26:11 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '30000' - anthropic-ratelimit-input-tokens-remaining: - - '30000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-01T16:26:10Z' - anthropic-ratelimit-output-tokens-limit: - - '8000' - anthropic-ratelimit-output-tokens-remaining: - - '8000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-01T16:26:10Z' - anthropic-ratelimit-requests-limit: - - '50' - anthropic-ratelimit-requests-remaining: - - '49' - anthropic-ratelimit-requests-reset: - - '2026-02-01T16:26:12Z' - anthropic-ratelimit-tokens-limit: - - '38000' - anthropic-ratelimit-tokens-remaining: - - '38000' - anthropic-ratelimit-tokens-reset: - - '2026-02-01T16:26:10Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXhfLG1cM5qTFLjqKqPof - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1157' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "authentication_error", - "message": "invalid x-api-key" - }, - "request_id": "req_011CXwgSpckNmKSZ2zSSmGQe" - } - headers: - CF-RAY: - - 9cafd29a2a15edd5-EWR - Connection: - - keep-alive - Content-Length: - - '130' - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Mon, 09 Feb 2026 02:09:05 GMT - Server: - - cloudflare - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXwgSpckNmKSZ2zSSmGQe - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '11' - x-should-retry: - - 'false' - status: - code: 401 - message: Unauthorized -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01TYYPFFjh2MGYwMBT6dPtge","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cafd4877a208c99-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Mon, 09 Feb 2026 02:10:25 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-09T02:10:24Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-09T02:10:24Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-09T02:10:24Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-09T02:10:24Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXwgYe5evU3T1ocnZA3AN - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1116' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_013xhnC6x7oA5LvcJRG7U42t","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cb07f10cda0255d-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Mon, 09 Feb 2026 04:06:50 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-09T04:06:49Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-09T04:06:49Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-09T04:06:49Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-09T04:06:49Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXwqRYh4Vo9JgfndnBwzL - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1113' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01FSTci7pL3KTtDnAaqxTK7Z","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cb88a165a2fef9f-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Tue, 10 Feb 2026 03:32:29 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-10T03:32:27Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-10T03:32:27Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-10T03:32:27Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-10T03:32:27Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXygcRs4PZeVP1JqvbGoZ - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1885' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01QHyqdCPMhKT8JybA83DdQn","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cbfd2bfacc59d36-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Wed, 11 Feb 2026 00:45:24 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T00:45:23Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T00:45:23Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T00:45:23Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T00:45:23Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY1MgUK4WEui52vVFk6jZ - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '899' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01Uu7K7FHX4eEwuhJ9CG7dWj","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"}} - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cc0d10508ea75b1-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Wed, 11 Feb 2026 03:38:59 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T03:38:58Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T03:38:58Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T03:38:58Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T03:38:58Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY1avCfNt24up33JfsVJk - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1035' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01GB8hHk17Jy8cwQrWdzTt7s","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5}} - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cc0d5a258613448-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Wed, 11 Feb 2026 03:42:09 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T03:42:08Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T03:42:08Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T03:42:08Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T03:42:08Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY1bA8qaVQbmaXKUc4KQX - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1373' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01GnHSTMpypTVe48XcA8Lr6j","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cc8c37aabd8862e-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Thu, 12 Feb 2026 02:47:51 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-12T02:47:50Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-12T02:47:50Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-12T02:47:50Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-12T02:47:50Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY3QpvRmmawqP6RzUgk9w - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1114' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01VMJM8turEeKoG2yi2pfN5P","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":5,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5}} - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cd82e8cbab0b785-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Fri, 13 Feb 2026 23:42:23 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-13T23:42:22Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-13T23:42:22Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-13T23:42:22Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-13T23:42:22Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY6xJTiKeZoAjo7d698Lk - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '899' - status: - code: 200 - message: OK -version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_double_exit_idempotent.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_double_exit_idempotent.yaml deleted file mode 100644 index 8864096ea6..0000000000 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_double_exit_idempotent.yaml +++ /dev/null @@ -1,833 +0,0 @@ -interactions: -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hi in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '128' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01TrsQqacXpj6Ud9M6oVYKft","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}} - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0} - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop"} - - headers: - CF-RAY: - - 9cb88a402f32c64a-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Tue, 10 Feb 2026 03:32:35 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-10T03:32:34Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-10T03:32:34Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-10T03:32:34Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-10T03:32:34Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXygcvS2mxUsiKQWWnxaA - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1117' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hi in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '128' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01St2f8sJGdRzHasYXE727z9","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cbfd2e3ad93b17b-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Wed, 11 Feb 2026 00:45:30 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T00:45:29Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T00:45:29Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T00:45:29Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T00:45:29Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY1MgtxPEexPaMCpXEpxe - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '908' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hi in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '128' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01XvFruh8TJ8ArXQ3SDSXNFv","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}} - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cc0d1391f6d9b29-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Wed, 11 Feb 2026 03:39:08 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T03:39:07Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T03:39:07Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T03:39:07Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T03:39:07Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY1avpHkeBCQGAPkf7Hza - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1066' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hi in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '128' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01BoKfvVZrunqFtSBj4S7YkK","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"!"}} - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cc0d5f45d2f7c9f-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Wed, 11 Feb 2026 03:42:21 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T03:42:20Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T03:42:20Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T03:42:20Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T03:42:20Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY1bB6qoYvgAiop4p1XWm - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '859' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hi in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '128' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_015Bir6aMGpKqmjBGTYzz33d","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"}} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cc8c3cccf9d33d5-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Thu, 12 Feb 2026 02:48:04 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-12T02:48:03Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-12T02:48:03Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-12T02:48:03Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-12T02:48:03Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY3QqtetfD18dHQSNmqrm - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1161' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hi in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '128' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01Qaw9xzrXn2ZaNPHKd3Evi9","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0} - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cd82edae9e5f534-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Fri, 13 Feb 2026 23:42:35 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-13T23:42:34Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-13T23:42:34Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-13T23:42:34Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-13T23:42:34Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY6xKPCzEg7wiWgbyBJCf - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '984' - status: - code: 200 - message: OK -version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml deleted file mode 100644 index dd3840a6b0..0000000000 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_token_usage.yaml +++ /dev/null @@ -1,1343 +0,0 @@ -interactions: -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Count to 3." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '120' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_017vXmL2yqaDeWBb7DqeSESe","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"1,"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" 2, 3."} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":12} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9c72cf2c0fd427f6-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Sun, 01 Feb 2026 16:26:15 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '30000' - anthropic-ratelimit-input-tokens-remaining: - - '30000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-01T16:26:14Z' - anthropic-ratelimit-output-tokens-limit: - - '8000' - anthropic-ratelimit-output-tokens-remaining: - - '8000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-01T16:26:14Z' - anthropic-ratelimit-requests-limit: - - '50' - anthropic-ratelimit-requests-remaining: - - '49' - anthropic-ratelimit-requests-reset: - - '2026-02-01T16:26:15Z' - anthropic-ratelimit-tokens-limit: - - '38000' - anthropic-ratelimit-tokens-remaining: - - '38000' - anthropic-ratelimit-tokens-reset: - - '2026-02-01T16:26:14Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXhfLVbfoCiVYmTTQgG8T - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1853' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Count to 3." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '120' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "authentication_error", - "message": "invalid x-api-key" - }, - "request_id": "req_011CXwgSrZLCiephBDm8GSG4" - } - headers: - CF-RAY: - - 9cafd29cfff5610c-EWR - Connection: - - keep-alive - Content-Length: - - '130' - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Mon, 09 Feb 2026 02:09:06 GMT - Server: - - cloudflare - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXwgSrZLCiephBDm8GSG4 - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '9' - x-should-retry: - - 'false' - status: - code: 401 - message: Unauthorized -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Count to 3." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '120' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01Di7hGD7Kjda9HtiLBmbQsG","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}}} - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"1, 2, 3."} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":12} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cafd49c781d624e-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Mon, 09 Feb 2026 02:10:28 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-09T02:10:28Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-09T02:10:28Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-09T02:10:28Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-09T02:10:28Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXwgYtTMCkfByoWq33gFZ - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '872' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Count to 3." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '120' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01Noe1B8RqrKd5c4Bz4G1Bez","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"1,"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" 2, 3"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cb07f2f498d49aa-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Mon, 09 Feb 2026 04:06:55 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-09T04:06:54Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-09T04:06:54Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-09T04:06:54Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-09T04:06:54Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXwqRuZBdBi9usrWNeXwM - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1152' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Count to 3." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '120' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_0175FsXWrcYiyPjWyX99tgfc","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"1"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"\n2\n3"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":9} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cb88a367be343c3-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Tue, 10 Feb 2026 03:32:33 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-10T03:32:32Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-10T03:32:32Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-10T03:32:32Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-10T03:32:32Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXygcpFhtQd8RjVgXcnVB - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1099' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Count to 3." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '120' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_019HzaVnWRVFS8veS41f4TSp","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"1,"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" 2, 3."} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":12} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cbfd2db2f8eacc5-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Wed, 11 Feb 2026 00:45:29 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T00:45:28Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T00:45:28Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T00:45:28Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T00:45:28Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY1Mgo7u39EipqBZrvYQh - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '976' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Count to 3." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '120' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01To6kPeqvjM1M1mbJmc32nB","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"1,"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" 2, 3."} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":12} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cc0d1310d1e0cc0-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Wed, 11 Feb 2026 03:39:06 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T03:39:05Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T03:39:05Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T03:39:05Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T03:39:05Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY1avincJvVrcduD2TMkx - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '845' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Count to 3." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '120' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01X1qhGSJt1fAfBSigbNhMUq","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"1, 2, 3"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cc0d5eb5d181705-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Wed, 11 Feb 2026 03:42:20 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T03:42:19Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T03:42:19Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T03:42:19Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T03:42:19Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY1bAzgxzQ8YMScVDCeS1 - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1024' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Count to 3." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '120' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01BnnAcU5gZLrsARmcACoPQj","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"1,"}} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" 2, 3"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cc8c3c4a96b438b-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Thu, 12 Feb 2026 02:48:02 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-12T02:48:02Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-12T02:48:02Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-12T02:48:02Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-12T02:48:02Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY3Qqo6mcmVdxkDiXWn69 - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '858' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Count to 3." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '120' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01RiA1BaibUZHLSZrmCCAcaf","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"1, 2, 3."} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":12,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":12} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cd82ed16f794270-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Fri, 13 Feb 2026 23:42:34 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-13T23:42:33Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-13T23:42:33Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-13T23:42:33Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-13T23:42:33Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY6xKGm3HwUNA9aoLvcxU - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1080' - status: - code: 200 - message: OK -version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml deleted file mode 100644 index bcd1242596..0000000000 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_stream_with_params.yaml +++ /dev/null @@ -1,1442 +0,0 @@ -interactions: -- request: - body: |- - { - "max_tokens": 50, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514", - "temperature": 0.7, - "top_k": 40, - "top_p": 0.9, - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '156' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_019Q4ndJ258iGw2TVyZV2CXu","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"!"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" How"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are you doing today?"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9c72cf21ff3ab9c6-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Sun, 01 Feb 2026 16:26:13 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '30000' - anthropic-ratelimit-input-tokens-remaining: - - '30000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-01T16:26:12Z' - anthropic-ratelimit-output-tokens-limit: - - '8000' - anthropic-ratelimit-output-tokens-remaining: - - '8000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-01T16:26:12Z' - anthropic-ratelimit-requests-limit: - - '50' - anthropic-ratelimit-requests-remaining: - - '49' - anthropic-ratelimit-requests-reset: - - '2026-02-01T16:26:13Z' - anthropic-ratelimit-tokens-limit: - - '38000' - anthropic-ratelimit-tokens-remaining: - - '38000' - anthropic-ratelimit-tokens-reset: - - '2026-02-01T16:26:12Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXhfLNFQGNJKZHNzk85AF - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1193' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 50, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514", - "temperature": 0.7, - "top_k": 40, - "top_p": 0.9, - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '156' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "authentication_error", - "message": "invalid x-api-key" - }, - "request_id": "req_011CXwgSqc2vZhH457PgSe2s" - } - headers: - CF-RAY: - - 9cafd29b9e514349-EWR - Connection: - - keep-alive - Content-Length: - - '130' - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Mon, 09 Feb 2026 02:09:05 GMT - Server: - - cloudflare - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXwgSqc2vZhH457PgSe2s - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '10' - x-should-retry: - - 'false' - status: - code: 401 - message: Unauthorized -- request: - body: |- - { - "max_tokens": 50, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514", - "temperature": 0.7, - "top_k": 40, - "top_p": 0.9, - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '156' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01JmJj8s976RDGr3bgLsG8my","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"}} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"!"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" How"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are you doing today?"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cafd490a8da9cb4-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Mon, 09 Feb 2026 02:10:27 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-09T02:10:26Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-09T02:10:26Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-09T02:10:26Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-09T02:10:26Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXwgYkRABneUfKwVLEWhv - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1272' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 50, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514", - "temperature": 0.7, - "top_k": 40, - "top_p": 0.9, - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '156' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01Xn5esvQrnMFQiahr6QsZdK","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"!"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" How"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" you doing today?"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cb07f21c8d243dc-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Mon, 09 Feb 2026 04:06:54 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-09T04:06:52Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-09T04:06:52Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-09T04:06:52Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-09T04:06:52Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXwqRkkrNN5FqY3bv5qNt - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1530' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 50, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514", - "temperature": 0.7, - "top_k": 40, - "top_p": 0.9, - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '156' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01WjabTqNX9CP6M4pYmaoaNg","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"! How"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" you doing today?"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } - - event: message_stop - data: {"type":"message_stop"} - - headers: - CF-RAY: - - 9cb88a2eeb244b05-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Tue, 10 Feb 2026 03:32:31 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-10T03:32:31Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-10T03:32:31Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-10T03:32:31Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-10T03:32:31Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXygcidsTv149v7gXLDdt - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '746' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 50, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514", - "temperature": 0.7, - "top_k": 40, - "top_p": 0.9, - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '156' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01DqGRL1X5HHQHC7bECxd7uF","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"!"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" How"}} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" you doing today?"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cbfd2d17c884289-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Wed, 11 Feb 2026 00:45:27 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T00:45:26Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T00:45:26Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T00:45:26Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T00:45:26Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY1MggXGvfEPvtvh1y9Rg - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1040' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 50, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514", - "temperature": 0.7, - "top_k": 40, - "top_p": 0.9, - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '156' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01HrgfLzAtLcSTFiSQE7RB4n","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"!"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" How"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are you doing today?"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cc0d1276eba6a52-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Wed, 11 Feb 2026 03:39:05 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T03:39:04Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T03:39:04Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T03:39:04Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T03:39:04Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY1avcAjvdWiJtaVA79ei - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1070' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 50, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514", - "temperature": 0.7, - "top_k": 40, - "top_p": 0.9, - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '156' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01DYfSiMg927w9EkviLFmji5","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}}} - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"!"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" How"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" you doing today?"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cc0d5de692cc327-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Wed, 11 Feb 2026 03:42:18 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T03:42:17Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T03:42:17Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T03:42:17Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T03:42:17Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY1bAqr9ecmPKhkrzFegW - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1084' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 50, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514", - "temperature": 0.7, - "top_k": 40, - "top_p": 0.9, - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '156' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01QD2kpos8jPR1zTUSnYscYE","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"! How"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are you doing today?"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cc8c3bc5ac7eef5-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Thu, 12 Feb 2026 02:48:01 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-12T02:48:00Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-12T02:48:00Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-12T02:48:00Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-12T02:48:00Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY3QqhPihXbU8w8ovz969 - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '877' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 50, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514", - "temperature": 0.7, - "top_k": 40, - "top_p": 0.9, - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '156' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-helper-method: - - stream - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-stream-helper: - - messages - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01EUi17pxB8x7VdVPwKUsA57","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"! How"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" you doing today?"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cd82ec7c840c64a-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Fri, 13 Feb 2026 23:42:32 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-13T23:42:31Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-13T23:42:31Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-13T23:42:31Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-13T23:42:31Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY6xKA9RNLZvhYtUPteUo - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1020' - status: - code: 200 - message: OK -version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py index 5b39ac64e4..eda6956b19 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py @@ -538,54 +538,6 @@ def test_sync_messages_create_streaming_connection_error( assert "APIConnectionError" in span.attributes[ErrorAttributes.ERROR_TYPE] -# ============================================================================= -# Tests for Messages.stream() method (not instrumented) -# ============================================================================= - - -@pytest.mark.vcr() -def test_sync_messages_stream_basic( - span_exporter, anthropic_client, instrument_no_content -): - """Messages.stream() should not produce spans when uninstrumented.""" - model = "claude-sonnet-4-20250514" - messages = [{"role": "user", "content": "Say hello in one word."}] - - with anthropic_client.messages.stream( - model=model, - max_tokens=100, - messages=messages, - ) as stream: - # Consume the stream using text_stream - response_text = "".join(stream.text_stream) - # Get the final message for assertions - final_message = stream.get_final_message() - - assert response_text # Should have some text - - spans = span_exporter.get_finished_spans() - assert len(spans) == 0 - - -@pytest.mark.vcr() -def test_sync_messages_stream_captures_content( - span_exporter, anthropic_client, instrument_with_content -): - """Messages.stream() content capture should not emit spans.""" - model = "claude-sonnet-4-20250514" - messages = [{"role": "user", "content": "Say hello in one word."}] - - with anthropic_client.messages.stream( - model=model, - max_tokens=100, - messages=messages, - ) as stream: - _ = "".join(stream.text_stream) - - spans = span_exporter.get_finished_spans() - assert len(spans) == 0 - - @pytest.mark.vcr() @pytest.mark.skipif( not _has_tools_param, @@ -822,96 +774,6 @@ def close(self): # pylint: disable=no-self-use assert invocation.attributes["gen_ai.usage.cache_read.input_tokens"] == 4 -@pytest.mark.vcr() -def test_sync_messages_stream_with_params( - span_exporter, anthropic_client, instrument_no_content -): - """Messages.stream() should remain uninstrumented with extra params.""" - model = "claude-sonnet-4-20250514" - messages = [{"role": "user", "content": "Say hi."}] - - with anthropic_client.messages.stream( - model=model, - max_tokens=50, - messages=messages, - temperature=0.7, - top_p=0.9, - top_k=40, - ) as stream: - # Consume the stream - _ = "".join(stream.text_stream) - - spans = span_exporter.get_finished_spans() - assert len(spans) == 0 - - -@pytest.mark.vcr() -def test_sync_messages_stream_token_usage( - span_exporter, anthropic_client, instrument_no_content -): - """Messages.stream() token usage should not be captured in spans.""" - model = "claude-sonnet-4-20250514" - messages = [{"role": "user", "content": "Count to 3."}] - - with anthropic_client.messages.stream( - model=model, - max_tokens=100, - messages=messages, - ) as stream: - _ = "".join(stream.text_stream) - final_message = stream.get_final_message() - - spans = span_exporter.get_finished_spans() - assert final_message.usage.output_tokens is not None - assert len(spans) == 0 - - -@pytest.mark.vcr() -def test_sync_messages_stream_double_exit_idempotent( - span_exporter, anthropic_client, instrument_no_content -): - """Calling __exit__ twice should still emit no spans.""" - model = "claude-sonnet-4-20250514" - messages = [{"role": "user", "content": "Say hi in one word."}] - - manager = anthropic_client.messages.stream( - model=model, - max_tokens=100, - messages=messages, - ) - stream = manager.__enter__() # pylint: disable=unnecessary-dunder-call - _ = "".join(stream.text_stream) - manager.__exit__(None, None, None) # pylint: disable=unnecessary-dunder-call - manager.__exit__(None, None, None) # pylint: disable=unnecessary-dunder-call - - spans = span_exporter.get_finished_spans() - assert len(spans) == 0 - - -def test_sync_messages_stream_connection_error( - span_exporter, instrument_no_content -): - """Connection errors in Messages.stream() should not create spans.""" - model = "claude-sonnet-4-20250514" - messages = [{"role": "user", "content": "Hello"}] - - # Create client with invalid endpoint - client = Anthropic(base_url="http://localhost:9999") - - with pytest.raises(APIConnectionError): - with client.messages.stream( - model=model, - max_tokens=100, - messages=messages, - timeout=0.1, - ) as stream: - # Try to consume the stream - _ = "".join(stream.text_stream) - - spans = span_exporter.get_finished_spans() - assert len(spans) == 0 - - # ============================================================================= # Tests for EVENT_ONLY content capture mode # ============================================================================= From 2590274f1d3c477b9977141e0b076c7c23a6a2f2 Mon Sep 17 00:00:00 2001 From: Teja Date: Mon, 16 Feb 2026 21:15:46 -0500 Subject: [PATCH 21/35] Add message extractors for Anthropic instrumentation. --- .../anthropic/messages_extractors.py | 204 ++++++++++++++++ .../instrumentation/anthropic/patch.py | 2 +- .../instrumentation/anthropic/utils.py | 220 +----------------- .../instrumentation/anthropic/wrappers.py | 16 +- ...st_stream_wrapper_finalize_idempotent.yaml | 132 +++++++++++ .../test_sync_messages_create_api_error.yaml | 96 ++++++++ .../test_sync_messages_create_basic.yaml | 136 +++++++++++ ...sync_messages_create_captures_content.yaml | 136 +++++++++++ ...ages_create_captures_thinking_content.yaml | 145 ++++++++++++ ...ages_create_captures_tool_use_content.yaml | 164 +++++++++++++ ..._create_event_only_no_content_in_span.yaml | 136 +++++++++++ ...test_sync_messages_create_stop_reason.yaml | 136 +++++++++++ .../test_sync_messages_create_streaming.yaml | 132 +++++++++++ ...ges_create_streaming_captures_content.yaml | 132 +++++++++++ ...c_messages_create_streaming_iteration.yaml | 138 +++++++++++ ...test_sync_messages_create_token_usage.yaml | 136 +++++++++++ ..._sync_messages_create_with_all_params.yaml | 142 +++++++++++ 17 files changed, 1980 insertions(+), 223 deletions(-) create mode 100644 instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/messages_extractors.py diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/messages_extractors.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/messages_extractors.py new file mode 100644 index 0000000000..f952df9f16 --- /dev/null +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/messages_extractors.py @@ -0,0 +1,204 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Get/extract helpers for Anthropic Messages instrumentation.""" + +from __future__ import annotations + +from dataclasses import dataclass +from typing import TYPE_CHECKING, Any, Optional, Sequence, cast +from urllib.parse import urlparse + +from opentelemetry.semconv._incubating.attributes import ( + gen_ai_attributes as GenAIAttributes, +) +from opentelemetry.semconv._incubating.attributes import ( + server_attributes as ServerAttributes, +) +from opentelemetry.util.genai.types import ( + InputMessage, + MessagePart, + OutputMessage, +) +from opentelemetry.util.types import AttributeValue + +from .utils import ( + as_int, + _as_str, + convert_content_to_parts, + _get_field, + normalize_finish_reason, +) + +if TYPE_CHECKING: + from anthropic.resources.messages import Messages + + +@dataclass +class MessageRequestParams: + model: str | None = None + max_tokens: int | None = None + temperature: float | None = None + top_k: int | None = None + top_p: float | None = None + stop_sequences: Sequence[str] | None = None + messages: Any | None = None + system: Any | None = None + + +GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS = ( + "gen_ai.usage.cache_creation.input_tokens" +) +GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS = "gen_ai.usage.cache_read.input_tokens" + + +def extract_usage_tokens( + usage: Any | None, +) -> tuple[int | None, int | None, int | None, int | None]: + if usage is None: + return None, None, None, None + + input_tokens = as_int(getattr(usage, "input_tokens", None)) + cache_creation_input_tokens = as_int( + getattr(usage, "cache_creation_input_tokens", None) + ) + cache_read_input_tokens = as_int( + getattr(usage, "cache_read_input_tokens", None) + ) + output_tokens = as_int(getattr(usage, "output_tokens", None)) + + if ( + input_tokens is None + and cache_creation_input_tokens is None + and cache_read_input_tokens is None + ): + total_input_tokens = None + else: + total_input_tokens = ( + (input_tokens or 0) + + (cache_creation_input_tokens or 0) + + (cache_read_input_tokens or 0) + ) + + return ( + total_input_tokens, + output_tokens, + cache_creation_input_tokens, + cache_read_input_tokens, + ) + + +def get_input_messages(messages: Any) -> list[InputMessage]: + if not isinstance(messages, list): + return [] + + result: list[InputMessage] = [] + for message in cast(list[Any], messages): + role = _as_str(_get_field(message, "role")) or "user" + parts = convert_content_to_parts(_get_field(message, "content")) + result.append(InputMessage(role=role, parts=parts)) + return result + + +def get_system_instruction(system: Any) -> list[MessagePart]: + return convert_content_to_parts(system) + + +def get_output_messages_from_message(message: Any) -> list[OutputMessage]: + if message is None: + return [] + + parts = convert_content_to_parts(_get_field(message, "content")) + finish_reason = normalize_finish_reason( + _get_field(message, "stop_reason") + ) + return [ + OutputMessage( + role=_as_str(_get_field(message, "role")) or "assistant", + parts=parts, + finish_reason=finish_reason or "", + ) + ] + + +def extract_params( # pylint: disable=too-many-locals + *, + max_tokens: int | None = None, + messages: Any | None = None, + model: str | None = None, + metadata: Any | None = None, + service_tier: Any | None = None, + stop_sequences: Sequence[str] | None = None, + stream: Any | None = None, + system: Any | None = None, + temperature: float | None = None, + thinking: Any | None = None, + tool_choice: Any | None = None, + tools: Any | None = None, + top_k: int | None = None, + top_p: float | None = None, + extra_headers: Any | None = None, + extra_query: Any | None = None, + extra_body: Any | None = None, + timeout: Any | None = None, + **_kwargs: Any, +) -> MessageRequestParams: + return MessageRequestParams( + model=model, + max_tokens=max_tokens, + temperature=temperature, + top_p=top_p, + top_k=top_k, + stop_sequences=stop_sequences, + messages=messages, + system=system, + ) + + +def _set_server_address_and_port( + client_instance: "Messages", attributes: dict[str, Any] +) -> None: + base_client = getattr(client_instance, "_client", None) + base_url = getattr(base_client, "base_url", None) + if not base_url: + return + + port: Optional[int] = None + if hasattr(base_url, "host"): + attributes[ServerAttributes.SERVER_ADDRESS] = base_url.host + port = getattr(base_url, "port", None) + elif isinstance(base_url, str): + url = urlparse(base_url) + attributes[ServerAttributes.SERVER_ADDRESS] = url.hostname + port = url.port + + if port and port != 443 and port > 0: + attributes[ServerAttributes.SERVER_PORT] = port + + +def get_llm_request_attributes( + params: MessageRequestParams, client_instance: "Messages" +) -> dict[str, AttributeValue]: + attributes = { + GenAIAttributes.GEN_AI_OPERATION_NAME: GenAIAttributes.GenAiOperationNameValues.CHAT.value, + GenAIAttributes.GEN_AI_SYSTEM: GenAIAttributes.GenAiSystemValues.ANTHROPIC.value, # pyright: ignore[reportDeprecated] + GenAIAttributes.GEN_AI_REQUEST_MODEL: params.model, + GenAIAttributes.GEN_AI_REQUEST_MAX_TOKENS: params.max_tokens, + GenAIAttributes.GEN_AI_REQUEST_TEMPERATURE: params.temperature, + GenAIAttributes.GEN_AI_REQUEST_TOP_P: params.top_p, + GenAIAttributes.GEN_AI_REQUEST_TOP_K: params.top_k, + GenAIAttributes.GEN_AI_REQUEST_STOP_SEQUENCES: params.stop_sequences, + } + _set_server_address_and_port(client_instance, attributes) + return {k: v for k, v in attributes.items() if v is not None} diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py index a343b9c2d0..8e4a0825eb 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py @@ -23,7 +23,7 @@ from opentelemetry.util.genai.types import Error, LLMInvocation from opentelemetry.util.genai.utils import should_capture_content -from .utils import ( +from .messages_extractors import ( extract_params, get_input_messages, get_llm_request_attributes, diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py index 1f97a1a8e9..4e26de26da 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py @@ -12,63 +12,27 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""Utility functions for Anthropic instrumentation.""" +"""Shared helper utilities for Anthropic instrumentation.""" from __future__ import annotations import base64 import json -from dataclasses import dataclass -from typing import TYPE_CHECKING, Any, Optional, Sequence, cast -from urllib.parse import urlparse +from typing import Any, cast -from opentelemetry.semconv._incubating.attributes import ( - gen_ai_attributes as GenAIAttributes, -) -from opentelemetry.semconv._incubating.attributes import ( - server_attributes as ServerAttributes, -) from opentelemetry.util.genai.types import ( Blob, - InputMessage, MessagePart, - OutputMessage, Reasoning, Text, ToolCall, ToolCallResponse, ) -from opentelemetry.util.types import AttributeValue - -if TYPE_CHECKING: - from anthropic.resources.messages import Messages - - -@dataclass -class MessageRequestParams: - """Parameters extracted from Anthropic Messages API calls.""" - - model: str | None = None - max_tokens: int | None = None - temperature: float | None = None - top_k: int | None = None - top_p: float | None = None - stop_sequences: Sequence[str] | None = None - messages: Any | None = None - system: Any | None = None -GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS = ( - "gen_ai.usage.cache_creation.input_tokens" -) -GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS = "gen_ai.usage.cache_read.input_tokens" - - -def _normalize_finish_reason(stop_reason: str | None) -> str | None: - """Map Anthropic stop reasons to GenAI semantic convention values.""" +def normalize_finish_reason(stop_reason: str | None) -> str | None: if stop_reason is None: return None - normalized = { "end_turn": "stop", "stop_sequence": "stop", @@ -92,7 +56,7 @@ def _as_str(value: Any) -> str | None: return str(value) -def _as_int(value: Any) -> int | None: +def as_int(value: Any) -> int | None: if isinstance(value, bool): return None if isinstance(value, int): @@ -100,43 +64,6 @@ def _as_int(value: Any) -> int | None: return None -def extract_usage_tokens( - usage: Any | None, -) -> tuple[int | None, int | None, int | None, int | None]: - """Extract Anthropic usage fields and compute semconv input tokens.""" - if usage is None: - return None, None, None, None - - input_tokens = _as_int(getattr(usage, "input_tokens", None)) - cache_creation_input_tokens = _as_int( - getattr(usage, "cache_creation_input_tokens", None) - ) - cache_read_input_tokens = _as_int( - getattr(usage, "cache_read_input_tokens", None) - ) - output_tokens = _as_int(getattr(usage, "output_tokens", None)) - - if ( - input_tokens is None - and cache_creation_input_tokens is None - and cache_read_input_tokens is None - ): - total_input_tokens = None - else: - total_input_tokens = ( - (input_tokens or 0) - + (cache_creation_input_tokens or 0) - + (cache_read_input_tokens or 0) - ) - - return ( - total_input_tokens, - output_tokens, - cache_creation_input_tokens, - cache_read_input_tokens, - ) - - def _to_dict_if_possible(value: Any) -> Any: if isinstance(value, dict): return cast(dict[str, Any], value) @@ -202,7 +129,7 @@ def _convert_content_block_to_part(content_block: Any) -> MessagePart | None: return result -def _convert_content_to_parts(content: Any) -> list[MessagePart]: +def convert_content_to_parts(content: Any) -> list[MessagePart]: if content is None: return [] if isinstance(content, str): @@ -218,39 +145,6 @@ def _convert_content_to_parts(content: Any) -> list[MessagePart]: return [part] if part is not None else [] -def get_input_messages(messages: Any) -> list[InputMessage]: - if not isinstance(messages, list): - return [] - - result: list[InputMessage] = [] - for message in cast(list[Any], messages): - role = _as_str(_get_field(message, "role")) or "user" - parts = _convert_content_to_parts(_get_field(message, "content")) - result.append(InputMessage(role=role, parts=parts)) - return result - - -def get_system_instruction(system: Any) -> list[MessagePart]: - return _convert_content_to_parts(system) - - -def get_output_messages_from_message(message: Any) -> list[OutputMessage]: - if message is None: - return [] - - parts = _convert_content_to_parts(_get_field(message, "content")) - finish_reason = _normalize_finish_reason( - _get_field(message, "stop_reason") - ) - return [ - OutputMessage( - role=_as_str(_get_field(message, "role")) or "assistant", - parts=parts, - finish_reason=finish_reason or "", - ) - ] - - def create_stream_block_state(content_block: Any) -> dict[str, Any]: block_type = _as_str(_get_field(content_block, "type")) or "text" state: dict[str, Any] = {"type": block_type} @@ -312,107 +206,3 @@ def stream_block_state_to_part(state: dict[str, Any]) -> MessagePart | None: if block_type in ("thinking", "redacted_thinking"): return Reasoning(content=_as_str(state.get("thinking")) or "") return None - - -# Use parameter signature from -# https://github.com/anthropics/anthropic-sdk-python/blob/9b5ab24ba17bcd5e762e5a5fd69bb3c17b100aaa/src/anthropic/resources/messages/messages.py#L896 -# https://github.com/anthropics/anthropic-sdk-python/blob/9b5ab24ba17bcd5e762e5a5fd69bb3c17b100aaa/src/anthropic/resources/messages/messages.py#L963 -# to handle named vs positional args robustly -def extract_params( # pylint: disable=too-many-locals - *, - max_tokens: int | None = None, - messages: Any | None = None, - model: str | None = None, - metadata: Any | None = None, - service_tier: Any | None = None, - stop_sequences: Sequence[str] | None = None, - stream: Any | None = None, - system: Any | None = None, - temperature: float | None = None, - thinking: Any | None = None, - tool_choice: Any | None = None, - tools: Any | None = None, - top_k: int | None = None, - top_p: float | None = None, - extra_headers: Any | None = None, - extra_query: Any | None = None, - extra_body: Any | None = None, - timeout: Any | None = None, - **_kwargs: Any, -) -> MessageRequestParams: - """Extract relevant parameters from Anthropic Messages API arguments.""" - return MessageRequestParams( - model=model, - max_tokens=max_tokens, - temperature=temperature, - top_p=top_p, - top_k=top_k, - stop_sequences=stop_sequences, - messages=messages, - system=system, - ) - - -def set_server_address_and_port( - client_instance: "Messages", attributes: dict[str, Any] -) -> None: - """Extract server address and port from the Anthropic client instance.""" - base_client = getattr(client_instance, "_client", None) - base_url = getattr(base_client, "base_url", None) - if not base_url: - return - - port: Optional[int] = None - if hasattr(base_url, "host"): - # httpx.URL object - attributes[ServerAttributes.SERVER_ADDRESS] = base_url.host - port = getattr(base_url, "port", None) - elif isinstance(base_url, str): - url = urlparse(base_url) - attributes[ServerAttributes.SERVER_ADDRESS] = url.hostname - port = url.port - - if port and port != 443 and port > 0: - attributes[ServerAttributes.SERVER_PORT] = port - - -def get_llm_request_attributes( - params: MessageRequestParams, client_instance: "Messages" -) -> dict[str, AttributeValue]: - """Extract LLM request attributes from MessageRequestParams. - - Returns a dictionary of OpenTelemetry semantic convention attributes for LLM requests. - The attributes follow the GenAI semantic conventions (gen_ai.*) and server semantic - conventions (server.*) as defined in the OpenTelemetry specification. - - GenAI attributes included: - - gen_ai.operation.name: The operation name (e.g., "chat") - - gen_ai.system: The GenAI system identifier (e.g., "anthropic") - - gen_ai.request.model: The model identifier - - gen_ai.request.max_tokens: Maximum tokens in the request - - gen_ai.request.temperature: Sampling temperature - - gen_ai.request.top_p: Top-p sampling parameter - - gen_ai.request.top_k: Top-k sampling parameter - - gen_ai.request.stop_sequences: Stop sequences for the request - - Server attributes included (if available): - - server.address: The server hostname - - server.port: The server port (if not default 443) - - Only non-None values are included in the returned dictionary. - """ - attributes = { - GenAIAttributes.GEN_AI_OPERATION_NAME: GenAIAttributes.GenAiOperationNameValues.CHAT.value, - GenAIAttributes.GEN_AI_SYSTEM: GenAIAttributes.GenAiSystemValues.ANTHROPIC.value, # pyright: ignore[reportDeprecated] - GenAIAttributes.GEN_AI_REQUEST_MODEL: params.model, - GenAIAttributes.GEN_AI_REQUEST_MAX_TOKENS: params.max_tokens, - GenAIAttributes.GEN_AI_REQUEST_TEMPERATURE: params.temperature, - GenAIAttributes.GEN_AI_REQUEST_TOP_P: params.top_p, - GenAIAttributes.GEN_AI_REQUEST_TOP_K: params.top_k, - GenAIAttributes.GEN_AI_REQUEST_STOP_SEQUENCES: params.stop_sequences, - } - - set_server_address_and_port(client_instance, attributes) - - # Filter out None values - return {k: v for k, v in attributes.items() if v is not None} diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py index d6f5e78af6..09efa08ba8 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py @@ -26,14 +26,16 @@ ) from opentelemetry.util.genai.utils import should_capture_content -from .utils import ( +from .messages_extractors import ( GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS, GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS, - _get_field, - _normalize_finish_reason, - create_stream_block_state, extract_usage_tokens, get_output_messages_from_message, +) +from .utils import ( + _get_field, + create_stream_block_state, + normalize_finish_reason, stream_block_state_to_part, update_stream_block_state, ) @@ -63,7 +65,7 @@ def extract_into(self, invocation: LLMInvocation) -> None: if self._message.id: invocation.response_id = self._message.id - finish_reason = _normalize_finish_reason(self._message.stop_reason) + finish_reason = normalize_finish_reason(self._message.stop_reason) if finish_reason: invocation.finish_reasons = [finish_reason] @@ -149,7 +151,7 @@ def _process_chunk(self, chunk: "RawMessageStreamEvent") -> None: elif chunk.type == "message_delta": delta = getattr(chunk, "delta", None) if delta and hasattr(delta, "stop_reason") and delta.stop_reason: - self._stop_reason = _normalize_finish_reason(delta.stop_reason) + self._stop_reason = normalize_finish_reason(delta.stop_reason) usage = getattr(chunk, "usage", None) self._update_usage(usage) elif self._capture_content and chunk.type == "content_block_start": @@ -298,7 +300,7 @@ def _extract_telemetry_from_stream(self) -> None: if final_message.id: self._invocation.response_id = final_message.id - finish_reason = _normalize_finish_reason(final_message.stop_reason) + finish_reason = normalize_finish_reason(final_message.stop_reason) if finish_reason: self._invocation.finish_reasons = [finish_reason] diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml index 453b1b74a3..1ae8990f09 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml @@ -923,4 +923,136 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_014THuCM45iRU3MupG3pt955","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop"} + + headers: + CF-RAY: + - 9cf1c3a1181125dc-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Tue, 17 Feb 2026 02:13:13 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-17T02:13:12Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-17T02:13:12Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-17T02:13:12Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-17T02:13:12Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CYCqELy7fkvXkCs7Wpzi2 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '880' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml index 19b2eb1355..33e5cff51c 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml @@ -1386,4 +1386,100 @@ interactions: status: code: 404 message: Not Found +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Hello" + } + ], + "model": "invalid-model-name" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '94' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "type": "error", + "error": { + "type": "not_found_error", + "message": "model: invalid-model-name" + }, + "request_id": "req_011CYCqDM72PdYVSdNNnm5wk" + } + headers: + CF-RAY: + - 9cf1c34c7c2080cd-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Tue, 17 Feb 2026 02:12:59 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + cf-cache-status: + - DYNAMIC + content-length: + - '133' + request-id: + - req_011CYCqDM72PdYVSdNNnm5wk + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '43' + x-should-retry: + - 'false' + status: + code: 404 + message: Not Found version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml index f4366c102a..eea574ef51 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml @@ -2155,4 +2155,140 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '117' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01Ri56T96cpJAKozeW8gefxy", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello!" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 13, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 5, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cf1c311186e7274-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Tue, 17 Feb 2026 02:12:50 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-17T02:12:50Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-17T02:12:50Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-17T02:12:49Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-17T02:12:50Z' + cf-cache-status: + - DYNAMIC + content-length: + - '441' + request-id: + - req_011CYCqCeV1qT1zNjME6Fofk + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1033' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml index 519badff61..c5b7f5a715 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml @@ -2155,4 +2155,140 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '117' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01Dfz5hrj8TTUfkjrhoiL5Tw", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello!" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 13, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 5, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cf1c319c85f6a4f-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Tue, 17 Feb 2026 02:12:52 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-17T02:12:51Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-17T02:12:52Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-17T02:12:50Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-17T02:12:51Z' + cf-cache-status: + - DYNAMIC + content-length: + - '441' + request-id: + - req_011CYCqCkRCpVR2hWPAdB42j + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1300' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml index 51ca4cce14..dfd5e11214 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml @@ -535,4 +535,149 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 16000, + "messages": [ + { + "role": "user", + "content": "What is 17*19? Think first." + } + ], + "model": "claude-sonnet-4-20250514", + "thinking": { + "type": "enabled", + "budget_tokens": 10000 + } + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '176' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01AiRbEV12LGD5w8ksreTXsZ", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "thinking", + "thinking": "I need to calculate 17 \u00d7 19.\n\nLet me think about this step by step. I can use the standard multiplication method or look for patterns.\n\nOne approach is to use the fact that these are close to nice round numbers:\n17 \u00d7 19\n\nI could think of this as:\n(20 - 3) \u00d7 (20 - 1)\n= 20 \u00d7 20 - 20 \u00d7 1 - 3 \u00d7 20 + 3 \u00d7 1\n= 400 - 20 - 60 + 3\n= 400 - 80 + 3\n= 323\n\nLet me double-check this with standard multiplication:\n 17\n\u00d7 19\n____\n\n17 \u00d7 9 = 153\n17 \u00d7 10 = 170\nSo 17 \u00d7 19 = 153 + 170 = 323\n\nYes, that's correct.", + "signature": "EqEFCkYICxgCKkCTb0eqjVwAQqSdzth/z5wnh9Re4uF/nNNJ4QxO4Qcvq/+ykTFIlHyGXI5sQm9hLRovp8m7kk4MWmviFTdovEpoEgyH/kgYBImJl4spznAaDNdM5awpIz+mGQ3o0yIw6H5DQrACn9AMKgpiWGXbEJgjXs3yDuXIbrKm3zYr7J4uHyUhVlA9yomatx9ngcf8KogEV6Rw/A+B/wQ2TJRDhe7zIgMvtAVbEmJsT0wJWUoByEMoL7cm8mhni7bNAl/LKJDiAG0R1g7pJAnN37MXwy0/njjtUCsWaPWhSHJYdYhgF/T48IehHnCUNQCOhQGUAYVBJpqI+gaFdHe3hzNpmTlPCJBUmJtKGf1wSzY/9QkhzO5nWh3AsueKxZoIhxLln/XLpXwvvSgt7zwWzUzpxLeXJTW+Oc6WIPzR1AD2Su+yY1M79QUyoIrEtvKXOod1c9DVILnLk51eHGuZguq6Lq8zxbcXRd7Uz98d8Uzvm/EerejDWoTfDBBiakxGczWXrCy/tUouQXlfGIwGbzXcgPDAXCI/gY0pSAvke/kTgz6hmmGZ45zcSnQEzqtsfeaHSB/TJO5tQL5Hl1gP8VbuOXSlIuv2PTprIeXXfYGQYduBEy80NDDLpIs6h9b006IoGT6DhwS80GzMFMWZo//qK3Rqj00QE3PLTKaMEpvKM/dfTd0k2IBQ79snY7KCHrKi2/TIoUU0yoOZAVVJKLRQ0U8tSNg2mY/OiQx94LntPhWRprPAukFIlTsWMhnwumwnUTL2L7gsfe+2PcW5E5qWtICI8naWyvFCiwVnld9RR5jRLc2ZEA2PSAQSihqMeD0Ct8WYDLr+MwsJMGjrkOgqiSt/935Snc39RoMcjNxJPGBf34bUxdUwqpuCuBgB" + }, + { + "type": "text", + "text": "I need to calculate 17 \u00d7 19.\n\nLet me use a helpful approach since both numbers are close to 20:\n17 \u00d7 19 = (20 - 3) \u00d7 (20 - 1)\n\nUsing the formula (a - b)(a - c) = a\u00b2 - a(b + c) + bc:\n= 20\u00b2 - 20(3 + 1) + (3 \u00d7 1)\n= 400 - 20(4) + 3\n= 400 - 80 + 3\n= 323\n\nTherefore, 17 \u00d7 19 = 323." + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 46, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 365, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cf1c37a8b2b0f3a-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Tue, 17 Feb 2026 02:13:12 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-17T02:13:07Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-17T02:13:12Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-17T02:13:06Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-17T02:13:07Z' + cf-cache-status: + - DYNAMIC + content-length: + - '2210' + request-id: + - req_011CYCqDtcMKEbbhhvgjfGwR + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '5889' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml index 69e9943bd1..ddfc4f2d5d 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml @@ -646,4 +646,168 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 256, + "messages": [ + { + "role": "user", + "content": "What is the weather in SF?" + } + ], + "model": "claude-sonnet-4-20250514", + "tool_choice": { + "type": "tool", + "name": "get_weather" + }, + "tools": [ + { + "name": "get_weather", + "description": "Get weather by city", + "input_schema": { + "type": "object", + "properties": { + "city": { + "type": "string" + } + }, + "required": [ + "city" + ] + } + } + ] + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '334' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_017Xjn1Q1m3tfcVWWyHdyQFz", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "tool_use", + "id": "toolu_01V2k9nPLtNMV1Jtqqm4B17D", + "name": "get_weather", + "input": { + "city": "San Francisco" + }, + "caller": { + "type": "direct" + } + } + ], + "stop_reason": "tool_use", + "stop_sequence": null, + "usage": { + "input_tokens": 386, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 34, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cf1c36fd8960ca2-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Tue, 17 Feb 2026 02:13:06 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-17T02:13:05Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-17T02:13:06Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-17T02:13:04Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-17T02:13:05Z' + cf-cache-status: + - DYNAMIC + content-length: + - '550' + request-id: + - req_011CYCqDmGpwsQ4qG5mXxzJ1 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1441' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml index 422482606a..5e2f776241 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml @@ -271,4 +271,140 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '117' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01TTpjVNerrMQvGoMvgVQW3s", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello!" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 13, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 5, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cf1c3a8afc1ef9d-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Tue, 17 Feb 2026 02:13:14 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-17T02:13:14Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-17T02:13:14Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-17T02:13:13Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-17T02:13:14Z' + cf-cache-status: + - DYNAMIC + content-length: + - '441' + request-id: + - req_011CYCqES7vXoyukqo4Divwa + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1048' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml index e2c2907390..251aa0e265 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml @@ -1836,4 +1836,140 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '102' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01QabVhwFhxmCLn3zE8qFgXi", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hi! How are you doing today?" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 10, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 11, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cf1c33b3f44425f-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Tue, 17 Feb 2026 02:12:57 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-17T02:12:57Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-17T02:12:57Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-17T02:12:56Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-17T02:12:57Z' + cf-cache-status: + - DYNAMIC + content-length: + - '464' + request-id: + - req_011CYCqD9KbrQfHVHKYwkJJi + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1156' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml index a166429646..d87de779b1 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml @@ -1282,4 +1282,136 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_018kVwSv5McDqGb49NRcyCKB","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cf1c34e4cad43b5-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Tue, 17 Feb 2026 02:13:00 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-17T02:12:59Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-17T02:12:59Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-17T02:12:59Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-17T02:12:59Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CYCqDNLw9NwvMaLnrcft4 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '810' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml index e068bde45c..7ebf1b2228 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml @@ -1282,4 +1282,136 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_015yjvSJ5PzmJPZLM8BXMUFH","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cf1c355f9ab4385-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Tue, 17 Feb 2026 02:13:01 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-17T02:13:00Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-17T02:13:00Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-17T02:13:00Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-17T02:13:00Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CYCqDTgeuTDxWBoPw1kQi + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '920' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml index 4534a7fd64..aaac645bd0 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml @@ -1357,4 +1357,142 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '116' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01NFPZNyvNoXBVe7xMc18XNq","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"! How"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are you doing today?"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9cf1c35e997bc54d-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Tue, 17 Feb 2026 02:13:02 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-17T02:13:01Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-17T02:13:01Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-17T02:13:02Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-17T02:13:01Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CYCqDZTvF6cNWtrStmFB3 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1046' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml index 920f05db59..ba572f40b0 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml @@ -1836,4 +1836,140 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Count to 5." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '106' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01KXKRGvCArYurAWdi9yTPZ4", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "1\n2\n3\n4\n5" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 12, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 13, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cf1c330b8527c96-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Tue, 17 Feb 2026 02:12:55 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-17T02:12:55Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-17T02:12:55Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-17T02:12:54Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-17T02:12:55Z' + cf-cache-status: + - DYNAMIC + content-length: + - '449' + request-id: + - req_011CYCqD281dvCxydEgB7wau + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1364' + status: + code: 200 + message: OK version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml index 8c9e9d3424..7205734fac 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml @@ -1926,4 +1926,146 @@ interactions: status: code: 200 message: OK +- request: + body: |- + { + "max_tokens": 50, + "messages": [ + { + "role": "user", + "content": "Say hello." + } + ], + "model": "claude-sonnet-4-20250514", + "stop_sequences": [ + "STOP" + ], + "temperature": 0.7, + "top_k": 40, + "top_p": 0.9 + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '171' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01TCKet1V1E6SxQECvAymQf7", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello! It's nice to meet you. How are you doing today?" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 10, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 18, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9cf1c323dd48a0fb-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Tue, 17 Feb 2026 02:12:54 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-17T02:12:53Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-17T02:12:54Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-17T02:12:52Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-17T02:12:53Z' + cf-cache-status: + - DYNAMIC + content-length: + - '490' + request-id: + - req_011CYCqCsGx9mcjm1KGGQZTT + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1777' + status: + code: 200 + message: OK version: 1 From b4adeec6a94abe87b1f8a56f112fc1278eeb4a27 Mon Sep 17 00:00:00 2001 From: Teja Date: Mon, 16 Feb 2026 21:26:41 -0500 Subject: [PATCH 22/35] Refactor message extractors in Anthropic instrumentation: reorganize imports and streamline finish reason normalization for improved clarity and maintainability. --- .../instrumentation/anthropic/messages_extractors.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/messages_extractors.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/messages_extractors.py index f952df9f16..43d01feeff 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/messages_extractors.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/messages_extractors.py @@ -34,10 +34,10 @@ from opentelemetry.util.types import AttributeValue from .utils import ( - as_int, _as_str, - convert_content_to_parts, _get_field, + as_int, + convert_content_to_parts, normalize_finish_reason, ) @@ -120,9 +120,7 @@ def get_output_messages_from_message(message: Any) -> list[OutputMessage]: return [] parts = convert_content_to_parts(_get_field(message, "content")) - finish_reason = normalize_finish_reason( - _get_field(message, "stop_reason") - ) + finish_reason = normalize_finish_reason(_get_field(message, "stop_reason")) return [ OutputMessage( role=_as_str(_get_field(message, "role")) or "assistant", From e9c235af0e3bfae40d5bf672bd26b7d0c60cb0d7 Mon Sep 17 00:00:00 2001 From: Teja Date: Wed, 18 Feb 2026 08:04:46 -0500 Subject: [PATCH 23/35] Update test cassettes for Anthropic instrumentation: streamline request and response structures, enhance error handling scenarios, and ensure consistency in message formats across various test cases. Removed outdated data and improved clarity in test interactions. --- ...st_stream_wrapper_finalize_idempotent.yaml | 950 +------ .../test_sync_messages_create_api_error.yaml | 1397 +---------- .../test_sync_messages_create_basic.yaml | 2174 +---------------- ...sync_messages_create_captures_content.yaml | 2174 +---------------- ...ages_create_captures_thinking_content.yaml | 564 +---- ...ages_create_captures_tool_use_content.yaml | 667 +---- ..._create_event_only_no_content_in_span.yaml | 290 +-- ...test_sync_messages_create_stop_reason.yaml | 1855 +------------- .../test_sync_messages_create_streaming.yaml | 1309 +--------- ...ges_create_streaming_captures_content.yaml | 1309 +--------- ...c_messages_create_streaming_iteration.yaml | 1388 +---------- ...test_sync_messages_create_token_usage.yaml | 1855 +------------- ..._sync_messages_create_with_all_params.yaml | 1945 +-------------- 13 files changed, 137 insertions(+), 17740 deletions(-) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml index 1ae8990f09..77701a25ee 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml @@ -57,953 +57,29 @@ interactions: body: string: |+ event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01BGX5ApzM8DLmEKxRo1YKfw","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":5,"service_tier":"standard","inference_geo":"not_available"}} } + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01KXozW1kPToWN1CHMiuZ2p7","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } event: ping data: {"type": "ping"} event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop"} - - headers: - CF-RAY: - - 9cb07f1998c1c5e7-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Mon, 09 Feb 2026 04:06:52 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-09T04:06:51Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-09T04:06:51Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-09T04:06:51Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-09T04:06:51Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXwqReiTcD4qYBSa9FJu2 - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1020' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01L2adFyfDDLTDx7dTiMxebU","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } + data: {"type":"content_block_stop","index":0 } event: message_delta data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cb88a23d8f1f78d-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Tue, 10 Feb 2026 03:32:30 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-10T03:32:29Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-10T03:32:29Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-10T03:32:29Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-10T03:32:29Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXygcb5wc3EEzoQ7LZTuz - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1268' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_019X4aWwBgmn42vLbcKV1qQh","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cbfd2c778c2269c-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Wed, 11 Feb 2026 00:45:26 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T00:45:25Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T00:45:25Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T00:45:25Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T00:45:25Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY1MgZhWFdBJcfgxAcyWK - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1180' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01JNAaVLt4SnAKmdQyPanbek","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cc0d11f0b2997d5-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Wed, 11 Feb 2026 03:39:03 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T03:39:02Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T03:39:02Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T03:39:03Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T03:39:02Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY1avWRiNqSZhMGCEtyuE - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '996' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01Wer2xYPqQ9zRHAieCRCtkn","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}} - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cc0d5d56e2c1705-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Wed, 11 Feb 2026 03:42:16 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T03:42:15Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T03:42:15Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T03:42:16Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T03:42:15Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY1bAjhpBL3zGuBYmG9c4 - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1047' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01VT1R2Lzjsn7AMCTQNjnsqP","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5}} - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cc8c3b38889ac6e-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Thu, 12 Feb 2026 02:48:00 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-12T02:47:59Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-12T02:47:59Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-12T02:47:59Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-12T02:47:59Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY3QqbKbhrR9YVDAF6en4 - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1022' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_017HqurdrPRjjcJk9VmHy3BN","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}}} - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cd82ebecf4b6180-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Fri, 13 Feb 2026 23:42:31 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-13T23:42:30Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-13T23:42:30Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-13T23:42:30Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-13T23:42:30Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY6xK3zLotRudMjixxsHz - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1042' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_014THuCM45iRU3MupG3pt955","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop"} + data: {"type":"message_stop" } headers: CF-RAY: - - 9cf1c3a1181125dc-EWR + - 9cfdb96fcd97ae20-EWR Cache-Control: - no-cache Connection: @@ -1013,7 +89,7 @@ interactions: Content-Type: - text/event-stream; charset=utf-8 Date: - - Tue, 17 Feb 2026 02:13:13 GMT + - Wed, 18 Feb 2026 13:03:25 GMT Server: - cloudflare Transfer-Encoding: @@ -1025,33 +101,33 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-17T02:13:12Z' + - '2026-02-18T13:03:24Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-17T02:13:12Z' + - '2026-02-18T13:03:24Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-17T02:13:12Z' + - '2026-02-18T13:03:24Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-17T02:13:12Z' + - '2026-02-18T13:03:24Z' cf-cache-status: - DYNAMIC request-id: - - req_011CYCqELy7fkvXkCs7Wpzi2 + - req_011CYFacyYRKYZEYsdXjb9WU strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '880' + - '1043' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml index 33e5cff51c..878f9f07b1 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml @@ -1,1391 +1,4 @@ interactions: -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Hello" - } - ], - "model": "invalid-model-name" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '110' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python - x-api-key: - - test_anthropic_api_key - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "not_found_error", - "message": "model: invalid-model-name" - } - } - headers: - Connection: - - keep-alive - Content-Type: - - application/json - Date: - - Mon, 15 Dec 2024 10:00:04 GMT - Server: - - cloudflare - content-length: - - '105' - status: - code: 404 - message: Not Found -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Hello" - } - ], - "model": "invalid-model-name" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '94' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "authentication_error", - "message": "invalid x-api-key" - }, - "request_id": "req_011CX88XGWSm82bN96ZkDWcr" - } - headers: - CF-RAY: - - 9be0e03eff016e28-EWR - Connection: - - keep-alive - Content-Length: - - '130' - Content-Type: - - application/json - Date: - - Wed, 14 Jan 2026 23:22:32 GMT - Server: - - cloudflare - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - request-id: - - req_011CX88XGWSm82bN96ZkDWcr - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '13' - x-should-retry: - - 'false' - status: - code: 401 - message: Unauthorized -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Hello" - } - ], - "model": "invalid-model-name" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '94' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "invalid_request_error", - "message": "Your credit balance is too low to access the Anthropic API. Please go to Plans & Billing to upgrade or purchase credits." - }, - "request_id": "req_011CX88ZmBumGkvj7aK6Gqzx" - } - headers: - CF-RAY: - - 9be0e1127fd1b1bc-EWR - Connection: - - keep-alive - Content-Length: - - '234' - Content-Type: - - application/json - Date: - - Wed, 14 Jan 2026 23:23:06 GMT - Server: - - cloudflare - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - request-id: - - req_011CX88ZmBumGkvj7aK6Gqzx - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '59' - x-should-retry: - - 'false' - status: - code: 400 - message: Bad Request -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Hello" - } - ], - "model": "invalid-model-name" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '94' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "not_found_error", - "message": "model: invalid-model-name" - }, - "request_id": "req_011CX89f9XqPgyRJC1ASfAab" - } - headers: - CF-RAY: - - 9be0f610add5b89f-EWR - Connection: - - keep-alive - Content-Type: - - application/json - Date: - - Wed, 14 Jan 2026 23:37:25 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - content-length: - - '133' - request-id: - - req_011CX89f9XqPgyRJC1ASfAab - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '27' - x-should-retry: - - 'false' - status: - code: 404 - message: Not Found -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Hello" - } - ], - "model": "invalid-model-name" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '94' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "not_found_error", - "message": "model: invalid-model-name" - }, - "request_id": "req_011CX89kiWcGNsjEPrPGA42x" - } - headers: - CF-RAY: - - 9be0f7e8dbf70ab9-EWR - Connection: - - keep-alive - Content-Type: - - application/json - Date: - - Wed, 14 Jan 2026 23:38:41 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - content-length: - - '133' - request-id: - - req_011CX89kiWcGNsjEPrPGA42x - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '78' - x-should-retry: - - 'false' - status: - code: 404 - message: Not Found -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Hello" - } - ], - "model": "invalid-model-name" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '94' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "not_found_error", - "message": "model: invalid-model-name" - }, - "request_id": "req_011CXhfKv2Kqp1zrqDWj6dqv" - } - headers: - CF-RAY: - - 9c72cefb9caf7c6c-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Sun, 01 Feb 2026 16:26:06 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - content-length: - - '133' - request-id: - - req_011CXhfKv2Kqp1zrqDWj6dqv - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '126' - x-should-retry: - - 'false' - status: - code: 404 - message: Not Found -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Hello" - } - ], - "model": "invalid-model-name" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '94' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "authentication_error", - "message": "invalid x-api-key" - }, - "request_id": "req_011CXwgSgGhfxSJTkXNcN1Zz" - } - headers: - CF-RAY: - - 9cafd28dfa24069b-EWR - Connection: - - keep-alive - Content-Length: - - '130' - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Mon, 09 Feb 2026 02:09:03 GMT - Server: - - cloudflare - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXwgSgGhfxSJTkXNcN1Zz - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '7' - x-should-retry: - - 'false' - status: - code: 401 - message: Unauthorized -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Hello" - } - ], - "model": "invalid-model-name" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '94' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "not_found_error", - "message": "model: invalid-model-name" - }, - "request_id": "req_011CXwgYHa7w1jGDtLgoGbQB" - } - headers: - CF-RAY: - - 9cafd4697bb8429e-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Mon, 09 Feb 2026 02:10:19 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - content-length: - - '133' - request-id: - - req_011CXwgYHa7w1jGDtLgoGbQB - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '59' - x-should-retry: - - 'false' - status: - code: 404 - message: Not Found -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Hello" - } - ], - "model": "invalid-model-name" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '94' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "not_found_error", - "message": "model: invalid-model-name" - }, - "request_id": "req_011CXwqREDoqGA4tDpEHMNK6" - } - headers: - CF-RAY: - - 9cb07ef5cb058ae3-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Mon, 09 Feb 2026 04:06:45 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - content-length: - - '133' - request-id: - - req_011CXwqREDoqGA4tDpEHMNK6 - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '67' - x-should-retry: - - 'false' - status: - code: 404 - message: Not Found -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Hello" - } - ], - "model": "invalid-model-name" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '94' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "not_found_error", - "message": "model: invalid-model-name" - }, - "request_id": "req_011CXygc6hPiqrWctdPWryki" - } - headers: - CF-RAY: - - 9cb889fa58d33d3e-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Tue, 10 Feb 2026 03:32:22 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - content-length: - - '133' - request-id: - - req_011CXygc6hPiqrWctdPWryki - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '76' - x-should-retry: - - 'false' - status: - code: 404 - message: Not Found -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Hello" - } - ], - "model": "invalid-model-name" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '94' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "not_found_error", - "message": "model: invalid-model-name" - }, - "request_id": "req_011CY1MfySypEhzBWMDLVBss" - } - headers: - CF-RAY: - - 9cbfd2956f048c2d-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Wed, 11 Feb 2026 00:45:17 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - content-length: - - '133' - request-id: - - req_011CY1MfySypEhzBWMDLVBss - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '81' - x-should-retry: - - 'false' - status: - code: 404 - message: Not Found -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Hello" - } - ], - "model": "invalid-model-name" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '94' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "not_found_error", - "message": "model: invalid-model-name" - }, - "request_id": "req_011CY1auecJy4eAmB9yJCs65" - } - headers: - CF-RAY: - - 9cc0d0d61bc780d9-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Wed, 11 Feb 2026 03:38:51 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - content-length: - - '133' - request-id: - - req_011CY1auecJy4eAmB9yJCs65 - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '165' - x-should-retry: - - 'false' - status: - code: 404 - message: Not Found -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Hello" - } - ], - "model": "invalid-model-name" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '94' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "not_found_error", - "message": "model: invalid-model-name" - }, - "request_id": "req_011CY1b9bzwEJaSGKv2SnKNe" - } - headers: - CF-RAY: - - 9cc0d57569c8acc5-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Wed, 11 Feb 2026 03:42:00 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - content-length: - - '133' - request-id: - - req_011CY1b9bzwEJaSGKv2SnKNe - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '49' - x-should-retry: - - 'false' - status: - code: 404 - message: Not Found -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Hello" - } - ], - "model": "invalid-model-name" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '94' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "not_found_error", - "message": "model: invalid-model-name" - }, - "request_id": "req_011CY3QpP6cMeGR736sN44u9" - } - headers: - CF-RAY: - - 9cc8c34cca225e7e-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Thu, 12 Feb 2026 02:47:42 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - content-length: - - '133' - request-id: - - req_011CY3QpP6cMeGR736sN44u9 - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '47' - x-should-retry: - - 'false' - status: - code: 404 - message: Not Found -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Hello" - } - ], - "model": "invalid-model-name" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '94' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "not_found_error", - "message": "model: invalid-model-name" - }, - "request_id": "req_011CY6xHZmvghhuS5mgC2ByE" - } - headers: - CF-RAY: - - 9cd82e409e0d8c27-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Fri, 13 Feb 2026 23:42:10 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - content-length: - - '133' - request-id: - - req_011CY6xHZmvghhuS5mgC2ByE - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '194' - x-should-retry: - - 'false' - status: - code: 404 - message: Not Found - request: body: |- { @@ -1448,11 +61,11 @@ interactions: "type": "not_found_error", "message": "model: invalid-model-name" }, - "request_id": "req_011CYCqDM72PdYVSdNNnm5wk" + "request_id": "req_011CYFabrqa2YA8WSpkzwYiU" } headers: CF-RAY: - - 9cf1c34c7c2080cd-EWR + - 9cfdb9112935e640-EWR Connection: - keep-alive Content-Security-Policy: @@ -1460,7 +73,7 @@ interactions: Content-Type: - application/json Date: - - Tue, 17 Feb 2026 02:12:59 GMT + - Wed, 18 Feb 2026 13:03:09 GMT Server: - cloudflare Transfer-Encoding: @@ -1472,11 +85,11 @@ interactions: content-length: - '133' request-id: - - req_011CYCqDM72PdYVSdNNnm5wk + - req_011CYFabrqa2YA8WSpkzwYiU strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '43' + - '53' x-should-retry: - 'false' status: diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml index eea574ef51..6b262d29ed 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml @@ -1,2160 +1,4 @@ interactions: -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-3-5-sonnet-20241022" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '128' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python - x-api-key: - - test_anthropic_api_key - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "id": "msg_01XFDUDYJgAACzvnptvVoYEL", - "type": "message", - "role": "assistant", - "model": "claude-3-5-sonnet-20241022", - "content": [ - { - "type": "text", - "text": "Hello!" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 14, - "output_tokens": 4 - } - } - headers: - Connection: - - keep-alive - Content-Type: - - application/json - Date: - - Mon, 15 Dec 2024 10:00:00 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - content-length: - - '350' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-3-5-sonnet-20241022" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '119' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "authentication_error", - "message": "invalid x-api-key" - }, - "request_id": "req_011CX88X7DM3SrsuuERgZeYJ" - } - headers: - CF-RAY: - - 9be0e0315fa2a02c-EWR - Connection: - - keep-alive - Content-Length: - - '130' - Content-Type: - - application/json - Date: - - Wed, 14 Jan 2026 23:22:30 GMT - Server: - - cloudflare - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - request-id: - - req_011CX88X7DM3SrsuuERgZeYJ - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '13' - x-should-retry: - - 'false' - status: - code: 401 - message: Unauthorized -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-3-5-sonnet-20241022" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '119' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "invalid_request_error", - "message": "Your credit balance is too low to access the Anthropic API. Please go to Plans & Billing to upgrade or purchase credits." - }, - "request_id": "req_011CX88Zakc7NS5rDAkMMK45" - } - headers: - CF-RAY: - - 9be0e1032e73ace5-EWR - Connection: - - keep-alive - Content-Length: - - '234' - Content-Type: - - application/json - Date: - - Wed, 14 Jan 2026 23:23:03 GMT - Server: - - cloudflare - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - request-id: - - req_011CX88Zakc7NS5rDAkMMK45 - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '30' - x-should-retry: - - 'false' - status: - code: 400 - message: Bad Request -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-3-5-sonnet-20241022" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '119' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "invalid_request_error", - "message": "Your credit balance is too low to access the Anthropic API. Please go to Plans & Billing to upgrade or purchase credits." - }, - "request_id": "req_011CX88qYh2YvHnk7Hp8vCR7" - } - headers: - CF-RAY: - - 9be0e64cc92eb4c6-EWR - Connection: - - keep-alive - Content-Length: - - '234' - Content-Type: - - application/json - Date: - - Wed, 14 Jan 2026 23:26:40 GMT - Server: - - cloudflare - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - request-id: - - req_011CX88qYh2YvHnk7Hp8vCR7 - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '20' - x-should-retry: - - 'false' - status: - code: 400 - message: Bad Request -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-3-5-sonnet-20241022" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '119' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "not_found_error", - "message": "model: claude-3-5-sonnet-20241022" - }, - "request_id": "req_011CX89Wba1H8DoNZMAq5M9M" - } - headers: - CF-RAY: - - 9be0f33baa01cdf0-EWR - Connection: - - keep-alive - Content-Type: - - application/json - Date: - - Wed, 14 Jan 2026 23:35:29 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - content-length: - - '141' - request-id: - - req_011CX89Wba1H8DoNZMAq5M9M - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '28' - x-should-retry: - - 'false' - status: - code: 404 - message: Not Found -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '117' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01ChhLEFb4TSQWHpQzFqEQsj", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello!" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 13, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 5, - "service_tier": "standard" - } - } - headers: - CF-RAY: - - 9be0f55b2b560866-EWR - Connection: - - keep-alive - Content-Type: - - application/json - Date: - - Wed, 14 Jan 2026 23:36:58 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '30000' - anthropic-ratelimit-input-tokens-remaining: - - '30000' - anthropic-ratelimit-input-tokens-reset: - - '2026-01-14T23:36:58Z' - anthropic-ratelimit-output-tokens-limit: - - '8000' - anthropic-ratelimit-output-tokens-remaining: - - '8000' - anthropic-ratelimit-output-tokens-reset: - - '2026-01-14T23:36:58Z' - anthropic-ratelimit-requests-limit: - - '50' - anthropic-ratelimit-requests-remaining: - - '49' - anthropic-ratelimit-requests-reset: - - '2026-01-14T23:36:58Z' - anthropic-ratelimit-tokens-limit: - - '38000' - anthropic-ratelimit-tokens-remaining: - - '38000' - anthropic-ratelimit-tokens-reset: - - '2026-01-14T23:36:58Z' - cf-cache-status: - - DYNAMIC - content-length: - - '409' - request-id: - - req_011CX89d1Mu8qapBc5y9KdXf - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1596' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '117' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01W7B22k9o9QrCqiEWmU1v9G", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello!" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 13, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 5, - "service_tier": "standard" - } - } - headers: - CF-RAY: - - 9be0f5d0cffcdcde-EWR - Connection: - - keep-alive - Content-Type: - - application/json - Date: - - Wed, 14 Jan 2026 23:37:17 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '30000' - anthropic-ratelimit-input-tokens-remaining: - - '30000' - anthropic-ratelimit-input-tokens-reset: - - '2026-01-14T23:37:16Z' - anthropic-ratelimit-output-tokens-limit: - - '8000' - anthropic-ratelimit-output-tokens-remaining: - - '8000' - anthropic-ratelimit-output-tokens-reset: - - '2026-01-14T23:37:17Z' - anthropic-ratelimit-requests-limit: - - '50' - anthropic-ratelimit-requests-remaining: - - '49' - anthropic-ratelimit-requests-reset: - - '2026-01-14T23:37:16Z' - anthropic-ratelimit-tokens-limit: - - '38000' - anthropic-ratelimit-tokens-remaining: - - '38000' - anthropic-ratelimit-tokens-reset: - - '2026-01-14T23:37:16Z' - cf-cache-status: - - DYNAMIC - content-length: - - '409' - request-id: - - req_011CX89ePqXjam4ByzovDWC6 - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1516' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '117' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01MpMMdwiz43MhCffJBjWRZP", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello!" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 13, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 5, - "service_tier": "standard" - } - } - headers: - CF-RAY: - - 9be0f7a98b01b734-EWR - Connection: - - keep-alive - Content-Type: - - application/json - Date: - - Wed, 14 Jan 2026 23:38:33 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '30000' - anthropic-ratelimit-input-tokens-remaining: - - '30000' - anthropic-ratelimit-input-tokens-reset: - - '2026-01-14T23:38:33Z' - anthropic-ratelimit-output-tokens-limit: - - '8000' - anthropic-ratelimit-output-tokens-remaining: - - '8000' - anthropic-ratelimit-output-tokens-reset: - - '2026-01-14T23:38:33Z' - anthropic-ratelimit-requests-limit: - - '50' - anthropic-ratelimit-requests-remaining: - - '49' - anthropic-ratelimit-requests-reset: - - '2026-01-14T23:38:32Z' - anthropic-ratelimit-tokens-limit: - - '38000' - anthropic-ratelimit-tokens-remaining: - - '38000' - anthropic-ratelimit-tokens-reset: - - '2026-01-14T23:38:33Z' - cf-cache-status: - - DYNAMIC - content-length: - - '409' - request-id: - - req_011CX89jyLYwphKuArFEcRij - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1970' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '117' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01CuxDqMnML7sFP6212a2j1b", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello!" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 13, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 5, - "service_tier": "standard" - } - } - headers: - CF-RAY: - - 9c72cec25ed742e8-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Sun, 01 Feb 2026 16:25:58 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '30000' - anthropic-ratelimit-input-tokens-remaining: - - '30000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-01T16:25:58Z' - anthropic-ratelimit-output-tokens-limit: - - '8000' - anthropic-ratelimit-output-tokens-remaining: - - '8000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-01T16:25:58Z' - anthropic-ratelimit-requests-limit: - - '50' - anthropic-ratelimit-requests-remaining: - - '49' - anthropic-ratelimit-requests-reset: - - '2026-02-01T16:25:58Z' - anthropic-ratelimit-tokens-limit: - - '38000' - anthropic-ratelimit-tokens-remaining: - - '38000' - anthropic-ratelimit-tokens-reset: - - '2026-02-01T16:25:58Z' - cf-cache-status: - - DYNAMIC - content-length: - - '409' - request-id: - - req_011CXhfKErNmxjcBp7mFqHdT - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1389' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '117' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "authentication_error", - "message": "invalid x-api-key" - }, - "request_id": "req_011CXwgSWJgAcLFshZ7pUbDp" - } - headers: - CF-RAY: - - 9cafd27f580a0f3b-EWR - Connection: - - keep-alive - Content-Length: - - '130' - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Mon, 09 Feb 2026 02:09:01 GMT - Server: - - cloudflare - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXwgSWJgAcLFshZ7pUbDp - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '8' - x-should-retry: - - 'false' - status: - code: 401 - message: Unauthorized -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '117' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_015EPMmo3gLS7YCe6TUktZb2", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello!" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 13, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 5, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cafd43a2e3c434b-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Mon, 09 Feb 2026 02:10:13 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-09T02:10:13Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-09T02:10:13Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-09T02:10:12Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-09T02:10:13Z' - cf-cache-status: - - DYNAMIC - content-length: - - '441' - request-id: - - req_011CXwgXjCCuSo8UFXeQUi1U - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1414' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '117' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01LoJKhArRbNU3Y8k1CfjFy7", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello!" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 13, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 5, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cb07ec4ddfb80d3-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Mon, 09 Feb 2026 04:06:38 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-09T04:06:38Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-09T04:06:38Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-09T04:06:37Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-09T04:06:38Z' - cf-cache-status: - - DYNAMIC - content-length: - - '441' - request-id: - - req_011CXwqQeivmMsTHWupX7Guh - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1242' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '117' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01K78vKWGf2VjiHfBeMUqzLd", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello!" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 13, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 5, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cb889c988ef41af-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Tue, 10 Feb 2026 03:32:16 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-10T03:32:15Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-10T03:32:16Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-10T03:32:15Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-10T03:32:15Z' - cf-cache-status: - - DYNAMIC - content-length: - - '441' - request-id: - - req_011CXygbXLC4RW3sUycx3X7f - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1103' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '117' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_015udupaxNYisb19LJvnZxJc", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello!" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 13, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 5, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cbfd259be8d7ac0-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Wed, 11 Feb 2026 00:45:08 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T00:45:08Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T00:45:08Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T00:45:07Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T00:45:08Z' - cf-cache-status: - - DYNAMIC - content-length: - - '441' - request-id: - - req_011CY1MfGaLewP6aLtFmrcRT - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1051' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '117' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01YVqgfLP7JT2f6Hd8R6ZfjV", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello!" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 13, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 5, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cc0d0985cd01c6b-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Wed, 11 Feb 2026 03:38:42 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T03:38:42Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T03:38:42Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T03:38:41Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T03:38:42Z' - cf-cache-status: - - DYNAMIC - content-length: - - '441' - request-id: - - req_011CY1atvJ6mBthoAaepY2DL - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1143' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '117' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_015aToGJFxMx7DiBQ9FjP2zM", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello." - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 13, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 5, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cc0d53b79f7da80-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Wed, 11 Feb 2026 03:41:52 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T03:41:52Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T03:41:52Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T03:41:51Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T03:41:52Z' - cf-cache-status: - - DYNAMIC - content-length: - - '441' - request-id: - - req_011CY1b8vPCXdC5TtHiX5tbV - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1044' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '117' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01WwXmU84NdpiiUXuz2Qda3E", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello!" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 13, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 5, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cc8c315ab2d9187-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Thu, 12 Feb 2026 02:47:34 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-12T02:47:34Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-12T02:47:34Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-12T02:47:34Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-12T02:47:34Z' - cf-cache-status: - - DYNAMIC - content-length: - - '441' - request-id: - - req_011CY3QojMjQ3bQGJeiU1Lur - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '939' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '117' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01HpCE3eMAt15ZVvxtYwAdVv", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello!" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 13, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 5, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cd82dd6fb394fb3-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Fri, 13 Feb 2026 23:41:54 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-13T23:41:54Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-13T23:41:54Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-13T23:41:53Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-13T23:41:54Z' - cf-cache-status: - - DYNAMIC - content-length: - - '441' - request-id: - - req_011CY6xGKPxjLJpdDmNXrKfY - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1182' - status: - code: 200 - message: OK - request: body: |- { @@ -2213,7 +57,7 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_01Ri56T96cpJAKozeW8gefxy", + "id": "msg_01VdhCzYwXoK615zbBaimYhX", "type": "message", "role": "assistant", "content": [ @@ -2239,7 +83,7 @@ interactions: } headers: CF-RAY: - - 9cf1c311186e7274-EWR + - 9cfdb8d73a447564-EWR Connection: - keep-alive Content-Security-Policy: @@ -2247,7 +91,7 @@ interactions: Content-Type: - application/json Date: - - Tue, 17 Feb 2026 02:12:50 GMT + - Wed, 18 Feb 2026 13:03:00 GMT Server: - cloudflare Transfer-Encoding: @@ -2259,35 +103,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-17T02:12:50Z' + - '2026-02-18T13:03:00Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-17T02:12:50Z' + - '2026-02-18T13:03:00Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-17T02:12:49Z' + - '2026-02-18T13:02:59Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-17T02:12:50Z' + - '2026-02-18T13:03:00Z' cf-cache-status: - DYNAMIC content-length: - '441' request-id: - - req_011CYCqCeV1qT1zNjME6Fofk + - req_011CYFabBBrKEaMTgAcq7Kcx strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1033' + - '1027' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml index c5b7f5a715..23aa755c56 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml @@ -1,2160 +1,4 @@ interactions: -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-3-5-sonnet-20241022" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '128' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python - x-api-key: - - test_anthropic_api_key - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "id": "msg_01XFDUDYJgAACzvnptvVoYEL", - "type": "message", - "role": "assistant", - "model": "claude-3-5-sonnet-20241022", - "content": [ - { - "type": "text", - "text": "Hello!" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 14, - "output_tokens": 4 - } - } - headers: - Connection: - - keep-alive - Content-Type: - - application/json - Date: - - Mon, 15 Dec 2024 10:00:00 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - content-length: - - '350' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-3-5-sonnet-20241022" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '119' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "authentication_error", - "message": "invalid x-api-key" - }, - "request_id": "req_011CX88X7DM3SrsuuERgZeYJ" - } - headers: - CF-RAY: - - 9be0e0315fa2a02c-EWR - Connection: - - keep-alive - Content-Length: - - '130' - Content-Type: - - application/json - Date: - - Wed, 14 Jan 2026 23:22:30 GMT - Server: - - cloudflare - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - request-id: - - req_011CX88X7DM3SrsuuERgZeYJ - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '13' - x-should-retry: - - 'false' - status: - code: 401 - message: Unauthorized -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-3-5-sonnet-20241022" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '119' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "invalid_request_error", - "message": "Your credit balance is too low to access the Anthropic API. Please go to Plans & Billing to upgrade or purchase credits." - }, - "request_id": "req_011CX88Zakc7NS5rDAkMMK45" - } - headers: - CF-RAY: - - 9be0e1032e73ace5-EWR - Connection: - - keep-alive - Content-Length: - - '234' - Content-Type: - - application/json - Date: - - Wed, 14 Jan 2026 23:23:03 GMT - Server: - - cloudflare - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - request-id: - - req_011CX88Zakc7NS5rDAkMMK45 - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '30' - x-should-retry: - - 'false' - status: - code: 400 - message: Bad Request -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-3-5-sonnet-20241022" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '119' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "invalid_request_error", - "message": "Your credit balance is too low to access the Anthropic API. Please go to Plans & Billing to upgrade or purchase credits." - }, - "request_id": "req_011CX88qYh2YvHnk7Hp8vCR7" - } - headers: - CF-RAY: - - 9be0e64cc92eb4c6-EWR - Connection: - - keep-alive - Content-Length: - - '234' - Content-Type: - - application/json - Date: - - Wed, 14 Jan 2026 23:26:40 GMT - Server: - - cloudflare - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - request-id: - - req_011CX88qYh2YvHnk7Hp8vCR7 - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '20' - x-should-retry: - - 'false' - status: - code: 400 - message: Bad Request -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-3-5-sonnet-20241022" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '119' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "not_found_error", - "message": "model: claude-3-5-sonnet-20241022" - }, - "request_id": "req_011CX89Wba1H8DoNZMAq5M9M" - } - headers: - CF-RAY: - - 9be0f33baa01cdf0-EWR - Connection: - - keep-alive - Content-Type: - - application/json - Date: - - Wed, 14 Jan 2026 23:35:29 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - content-length: - - '141' - request-id: - - req_011CX89Wba1H8DoNZMAq5M9M - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '28' - x-should-retry: - - 'false' - status: - code: 404 - message: Not Found -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '117' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01ChhLEFb4TSQWHpQzFqEQsj", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello!" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 13, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 5, - "service_tier": "standard" - } - } - headers: - CF-RAY: - - 9be0f55b2b560866-EWR - Connection: - - keep-alive - Content-Type: - - application/json - Date: - - Wed, 14 Jan 2026 23:36:58 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '30000' - anthropic-ratelimit-input-tokens-remaining: - - '30000' - anthropic-ratelimit-input-tokens-reset: - - '2026-01-14T23:36:58Z' - anthropic-ratelimit-output-tokens-limit: - - '8000' - anthropic-ratelimit-output-tokens-remaining: - - '8000' - anthropic-ratelimit-output-tokens-reset: - - '2026-01-14T23:36:58Z' - anthropic-ratelimit-requests-limit: - - '50' - anthropic-ratelimit-requests-remaining: - - '49' - anthropic-ratelimit-requests-reset: - - '2026-01-14T23:36:58Z' - anthropic-ratelimit-tokens-limit: - - '38000' - anthropic-ratelimit-tokens-remaining: - - '38000' - anthropic-ratelimit-tokens-reset: - - '2026-01-14T23:36:58Z' - cf-cache-status: - - DYNAMIC - content-length: - - '409' - request-id: - - req_011CX89d1Mu8qapBc5y9KdXf - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1596' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '117' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01W7B22k9o9QrCqiEWmU1v9G", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello!" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 13, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 5, - "service_tier": "standard" - } - } - headers: - CF-RAY: - - 9be0f5d0cffcdcde-EWR - Connection: - - keep-alive - Content-Type: - - application/json - Date: - - Wed, 14 Jan 2026 23:37:17 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '30000' - anthropic-ratelimit-input-tokens-remaining: - - '30000' - anthropic-ratelimit-input-tokens-reset: - - '2026-01-14T23:37:16Z' - anthropic-ratelimit-output-tokens-limit: - - '8000' - anthropic-ratelimit-output-tokens-remaining: - - '8000' - anthropic-ratelimit-output-tokens-reset: - - '2026-01-14T23:37:17Z' - anthropic-ratelimit-requests-limit: - - '50' - anthropic-ratelimit-requests-remaining: - - '49' - anthropic-ratelimit-requests-reset: - - '2026-01-14T23:37:16Z' - anthropic-ratelimit-tokens-limit: - - '38000' - anthropic-ratelimit-tokens-remaining: - - '38000' - anthropic-ratelimit-tokens-reset: - - '2026-01-14T23:37:16Z' - cf-cache-status: - - DYNAMIC - content-length: - - '409' - request-id: - - req_011CX89ePqXjam4ByzovDWC6 - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1516' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '117' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01MpMMdwiz43MhCffJBjWRZP", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello!" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 13, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 5, - "service_tier": "standard" - } - } - headers: - CF-RAY: - - 9be0f7a98b01b734-EWR - Connection: - - keep-alive - Content-Type: - - application/json - Date: - - Wed, 14 Jan 2026 23:38:33 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '30000' - anthropic-ratelimit-input-tokens-remaining: - - '30000' - anthropic-ratelimit-input-tokens-reset: - - '2026-01-14T23:38:33Z' - anthropic-ratelimit-output-tokens-limit: - - '8000' - anthropic-ratelimit-output-tokens-remaining: - - '8000' - anthropic-ratelimit-output-tokens-reset: - - '2026-01-14T23:38:33Z' - anthropic-ratelimit-requests-limit: - - '50' - anthropic-ratelimit-requests-remaining: - - '49' - anthropic-ratelimit-requests-reset: - - '2026-01-14T23:38:32Z' - anthropic-ratelimit-tokens-limit: - - '38000' - anthropic-ratelimit-tokens-remaining: - - '38000' - anthropic-ratelimit-tokens-reset: - - '2026-01-14T23:38:33Z' - cf-cache-status: - - DYNAMIC - content-length: - - '409' - request-id: - - req_011CX89jyLYwphKuArFEcRij - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1970' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '117' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01CuxDqMnML7sFP6212a2j1b", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello!" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 13, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 5, - "service_tier": "standard" - } - } - headers: - CF-RAY: - - 9c72cec25ed742e8-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Sun, 01 Feb 2026 16:25:58 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '30000' - anthropic-ratelimit-input-tokens-remaining: - - '30000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-01T16:25:58Z' - anthropic-ratelimit-output-tokens-limit: - - '8000' - anthropic-ratelimit-output-tokens-remaining: - - '8000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-01T16:25:58Z' - anthropic-ratelimit-requests-limit: - - '50' - anthropic-ratelimit-requests-remaining: - - '49' - anthropic-ratelimit-requests-reset: - - '2026-02-01T16:25:58Z' - anthropic-ratelimit-tokens-limit: - - '38000' - anthropic-ratelimit-tokens-remaining: - - '38000' - anthropic-ratelimit-tokens-reset: - - '2026-02-01T16:25:58Z' - cf-cache-status: - - DYNAMIC - content-length: - - '409' - request-id: - - req_011CXhfKErNmxjcBp7mFqHdT - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1389' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '117' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "authentication_error", - "message": "invalid x-api-key" - }, - "request_id": "req_011CXwgSWJgAcLFshZ7pUbDp" - } - headers: - CF-RAY: - - 9cafd27f580a0f3b-EWR - Connection: - - keep-alive - Content-Length: - - '130' - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Mon, 09 Feb 2026 02:09:01 GMT - Server: - - cloudflare - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXwgSWJgAcLFshZ7pUbDp - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '8' - x-should-retry: - - 'false' - status: - code: 401 - message: Unauthorized -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '117' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_015EPMmo3gLS7YCe6TUktZb2", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello!" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 13, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 5, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cafd43a2e3c434b-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Mon, 09 Feb 2026 02:10:13 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-09T02:10:13Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-09T02:10:13Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-09T02:10:12Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-09T02:10:13Z' - cf-cache-status: - - DYNAMIC - content-length: - - '441' - request-id: - - req_011CXwgXjCCuSo8UFXeQUi1U - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1414' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '117' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01LoJKhArRbNU3Y8k1CfjFy7", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello!" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 13, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 5, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cb07ec4ddfb80d3-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Mon, 09 Feb 2026 04:06:38 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-09T04:06:38Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-09T04:06:38Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-09T04:06:37Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-09T04:06:38Z' - cf-cache-status: - - DYNAMIC - content-length: - - '441' - request-id: - - req_011CXwqQeivmMsTHWupX7Guh - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1242' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '117' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01K78vKWGf2VjiHfBeMUqzLd", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello!" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 13, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 5, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cb889c988ef41af-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Tue, 10 Feb 2026 03:32:16 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-10T03:32:15Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-10T03:32:16Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-10T03:32:15Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-10T03:32:15Z' - cf-cache-status: - - DYNAMIC - content-length: - - '441' - request-id: - - req_011CXygbXLC4RW3sUycx3X7f - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1103' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '117' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01S7Kzp6RYADbosUzujiwSvK", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello!" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 13, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 5, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cbfd2622e1942df-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Wed, 11 Feb 2026 00:45:09 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T00:45:09Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T00:45:09Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T00:45:08Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T00:45:09Z' - cf-cache-status: - - DYNAMIC - content-length: - - '441' - request-id: - - req_011CY1MfNP672aPFNTMycTox - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '977' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '117' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01RDp61PCLrmSt6BgktY8ssL", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello!" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 13, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 5, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cc0d0a1da6b0ab9-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Wed, 11 Feb 2026 03:38:44 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T03:38:43Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T03:38:43Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T03:38:42Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T03:38:43Z' - cf-cache-status: - - DYNAMIC - content-length: - - '441' - request-id: - - req_011CY1au2q1TkDQD8f3szYsW - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1126' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '117' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01EDcFRbbaDj8g97D8EbVrju", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello!" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 13, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 5, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cc0d543eff2db49-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Wed, 11 Feb 2026 03:41:53 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T03:41:53Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T03:41:53Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T03:41:52Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T03:41:53Z' - cf-cache-status: - - DYNAMIC - content-length: - - '441' - request-id: - - req_011CY1b92ADR8pULetRW4uPf - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1079' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '117' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01GfhPDczEhZYwihvH74pt3E", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello!" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 13, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 5, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cc8c31d982a8d3f-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Thu, 12 Feb 2026 02:47:36 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-12T02:47:36Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-12T02:47:36Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-12T02:47:35Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-12T02:47:36Z' - cf-cache-status: - - DYNAMIC - content-length: - - '441' - request-id: - - req_011CY3QopoQXN5AS8qDP8eCJ - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1268' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '117' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01ASX8rG4atqMREVf7tYuJFG", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello!" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 13, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 5, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cd82de07fb54544-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Fri, 13 Feb 2026 23:41:55 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-13T23:41:55Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-13T23:41:55Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-13T23:41:54Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-13T23:41:55Z' - cf-cache-status: - - DYNAMIC - content-length: - - '441' - request-id: - - req_011CY6xGRstfeY6iyeKp3W2T - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1234' - status: - code: 200 - message: OK - request: body: |- { @@ -2213,7 +57,7 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_01Dfz5hrj8TTUfkjrhoiL5Tw", + "id": "msg_01CnATbLCi3YseMs7jDaaVeG", "type": "message", "role": "assistant", "content": [ @@ -2239,7 +83,7 @@ interactions: } headers: CF-RAY: - - 9cf1c319c85f6a4f-EWR + - 9cfdb8deffb7423d-EWR Connection: - keep-alive Content-Security-Policy: @@ -2247,7 +91,7 @@ interactions: Content-Type: - application/json Date: - - Tue, 17 Feb 2026 02:12:52 GMT + - Wed, 18 Feb 2026 13:03:02 GMT Server: - cloudflare Transfer-Encoding: @@ -2259,35 +103,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-17T02:12:51Z' + - '2026-02-18T13:03:01Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-17T02:12:52Z' + - '2026-02-18T13:03:01Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-17T02:12:50Z' + - '2026-02-18T13:03:01Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-17T02:12:51Z' + - '2026-02-18T13:03:01Z' cf-cache-status: - DYNAMIC content-length: - '441' request-id: - - req_011CYCqCkRCpVR2hWPAdB42j + - req_011CYFabGWKybEHmHfoTW69x strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1300' + - '1111' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml index dfd5e11214..fe482fbfd5 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml @@ -1,540 +1,4 @@ interactions: -- request: - body: |- - { - "max_tokens": 16000, - "messages": [ - { - "role": "user", - "content": "What is 17*19? Think first." - } - ], - "model": "claude-sonnet-4-20250514", - "thinking": { - "type": "enabled", - "budget_tokens": 10000 - } - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '195' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01ThinkingTest123", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "thinking", - "thinking": "Let me calculate 17 times 19. I can break this down: 17 * 19 = 17 * 20 - 17 = 340 - 17 = 323." - }, - { - "type": "text", - "text": "17 \u00d7 19 = **323**" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 18, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "output_tokens": 42, - "service_tier": "standard" - } - } - headers: - Connection: - - keep-alive - Content-Type: - - application/json - Date: - - Wed, 11 Feb 2026 04:00:00 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - content-length: - - '580' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 16000, - "messages": [ - { - "role": "user", - "content": "What is 17*19? Think first." - } - ], - "model": "claude-sonnet-4-20250514", - "thinking": { - "type": "enabled", - "budget_tokens": 10000 - } - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '176' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01R2Wyw6D8vK1yD6jBK1g9C7", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "thinking", - "thinking": "I need to calculate 17 * 19.\n\nLet me think about this step by step.\n\nOne way is to use the standard multiplication:\n17 * 19\n\nI can break this down:\n17 * 19 = 17 * (20 - 1) = 17 * 20 - 17 * 1 = 340 - 17 = 323\n\nLet me double-check this another way:\n19 * 17 = 19 * (10 + 7) = 19 * 10 + 19 * 7 = 190 + 133\n\nNow I need to calculate 19 * 7:\n19 * 7 = (20 - 1) * 7 = 20 * 7 - 1 * 7 = 140 - 7 = 133\n\nSo 19 * 17 = 190 + 133 = 323\n\nBoth methods give me 323, so that should be correct.", - "signature": "EoIFCkYICxgCKkAzrBHkSvp2t+O6FeldCSOZG6sRsBctId9L5ZKp7KPHthia6QKTS11mYuN5Uyb2Yx4WV7FIHtbUSbkEqbPqnjRGEgxzQGA5fiVU00cGq0UaDLQ1BTDI8043Aw1W1CIwgE/ounmA8v9rxn+Pnyf0hdd0FvMOC57oedMKS8aAm8uf3hlbqAnYkvwf4SxHIbDXKukD/m9nFQLSY0yZBzfIoI8w9OMD3SldlcEo3HofmOq2huaOMBY6YZXY5MDulFXMJiGHS267Le+NVB0OmS5r3dih0dIuUXnpgP9DXH8YuP4QSVwFnmDtfWMQWGx8FzpaH2Miq/JWp1wN2Ulu7vFxGnnt9uOORCj0LXII9QAXBmNVEFGY8eZTO9OjvZY6AGswnlOWrlQZKzIkt9wVpCprcOcFarIhxnQhNIR115PG+iH4OhedCuXzKVaD/MyEV2k5CIdpHZFLWz2y2xyUQV5XZv3m0nXB4u+GlRbHMTLcl5Do5LbhcKiU30PLxdwsawGN2LKJY+n2fjrQjX7xcmEQvStOOTlNzCrAd63H8sa+GzVpFGd3wnG3RK5bOxMI2GuNXKI1XOHGd1ODqQcjm67nB1vmUkR8BVbm94k5u4hspYCiRePqGtfkIFyMa4W93YfFKszviMlOBHSGbEulQZhIoQ0e5+y7ftF5VtSJijGH93K5I4WrVI+/pHh5j5RsjUX7wIU+Zq3brBttE+mHZnGnSiB73m8qk0H/woW/9Ck83leRw2Zuy44U4Wto9gQaNaWRjq0AsUxhx9s6MqpOoNrDDjIKFpZHScMMU6AL9rKPinWwA581af5tCMXXQCg58+OUCyxKPBBYIXfqAswFGAE=" - }, - { - "type": "text", - "text": "I need to calculate 17 \u00d7 19.\n\nLet me use the distributive property to make this easier:\n17 \u00d7 19 = 17 \u00d7 (20 - 1) = 17 \u00d7 20 - 17 \u00d7 1 = 340 - 17 = 323\n\nLet me verify with another approach:\n19 \u00d7 17 = 19 \u00d7 (10 + 7) = 190 + (19 \u00d7 7) = 190 + 133 = 323\n\nTherefore, 17 \u00d7 19 = 323." - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 46, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 380, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cc0d5b61a4c643e-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Wed, 11 Feb 2026 03:42:15 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T03:42:11Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T03:42:15Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T03:42:11Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T03:42:11Z' - cf-cache-status: - - DYNAMIC - content-length: - - '2129' - request-id: - - req_011CY1bANHDGDVtTXtSLNAXN - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '4812' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 16000, - "messages": [ - { - "role": "user", - "content": "What is 17*19? Think first." - } - ], - "model": "claude-sonnet-4-20250514", - "thinking": { - "type": "enabled", - "budget_tokens": 10000 - } - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '176' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01QZXwbxRaiRGHtU7xxooHTc", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "thinking", - "thinking": "I need to calculate 17 \u00d7 19.\n\nLet me think about this step by step. I can use the standard multiplication method or look for patterns.\n\nOne approach is to use the fact that both numbers are close to 20:\n17 \u00d7 19 = (20 - 3) \u00d7 (20 - 1)\n= 20\u00b2 - 20\u00d71 - 20\u00d73 + 3\u00d71\n= 400 - 20 - 60 + 3\n= 400 - 80 + 3\n= 320 + 3\n= 323\n\nLet me double-check this with standard multiplication:\n 17\n \u00d7 19\n ----\n 153 (17 \u00d7 9)\n 170 (17 \u00d7 10, shifted one place)\n ----\n 323\n\nLet me verify the first line: 17 \u00d7 9\n17 \u00d7 9 = 17 \u00d7 (10 - 1) = 170 - 17 = 153 \u2713\n\nAnd 17 \u00d7 10 = 170 \u2713\n\nSo 153 + 170 = 323 \u2713\n\nBoth methods give me 323.", - "signature": "EpgGCkYICxgCKkC23dGy4G89aOB/G0AEgl/YoxyYjLLQNjXsCMrWZqc/ZMQq9gAOMRpteSezIYWTc07F31ORVASHDaLNe2Ty0sGkEgwQprMbHAucH973U0waDBkRzLZZgddLcuk5QCIwuuII2T6wylsLsD4fRwA3CHaSCZrO4LJiK874yGjSa2acy10XGjwXXS3tVOQbxwETKv8EBeIp6G7y5QRorylUQVwMQxo6ZUpk6KQObHK8nJRqltBxsrYkvCpCI/102k+2Liq/5cZEXWHt0rbozb4J3qfn0YsMprV2WoiO5D0bllZBt9DzoVnxarTWv1thNbrwoUMcPgb50uNarNGC4S/hKSWrgv/uA0HaGFHnXHLTTIpCLvjLIaVNHeYG9NRFJcbYf1Y5CwP6V1JlKIuFO7y+9dkAQySneuyg1UkhxJptEs498MN62OQVul7MffRdmOiqkqxArtNIz9eLQDAx0O15E/5MY1YR3q/vtv2swtVWBvL4D+DaDKvIjiA81aLzVaUP9EHPe5Jy/aHzKxLodgl0+lAH3t9MNoapk40UQALM85hU+rkSFbWUWXG0ViTLAhZIC4LtZZpbXw5GucGgHqkwy7xVUI46ebuePM1ejTgLIkJOqEAvHsR+7W2s4gy1eehC4bA3dU/9V9fEVuEm8V4NjnRWEVvj3fL5Qio1lO9yXzNlkRx2CNP8BOsk3qYPZDa+1fxUNI9mFtMs9vsPUdoSQ1VGc+RPp6QSUaBIa2p5dmdaaWLBU9IVmh7Dke5I7digHFj2Y9JfP/4cL/p71xDp5ylj+GjTzejPRsyvhewiLMcTseV9+zFXeAK6LnvON63MxBAp2YbEoKKTpVo/wcff5Syg6QKLunKZo15wl8OKcYMxdfmpNqvDz3XNcDOvvanuC7gID2jWJut4gnQjVp0kjUGTZCEnum8Or17xTI6mirb+WGF+Bt1Zng/4JqBR60iN9y2m+n2LI3/ofDe5xcxfa7ZuYvRqrPcVBX+/wfQQfM+gyYsB9vCw365/A2GwYEzohwSY9oMxlScJTBr9CAzNJT9NGAE=" - }, - { - "type": "text", - "text": "Let me work through 17 \u00d7 19 step by step.\n\nI can use the standard multiplication method:\n```\n 17\n \u00d7 19\n ----\n 153 (17 \u00d7 9)\n 170 (17 \u00d7 10)\n ----\n 323\n```\n\nOr I can use the fact that both numbers are close to 20:\n17 \u00d7 19 = (20 - 3) \u00d7 (20 - 1) = 400 - 20 - 60 + 3 = 323\n\nTherefore, 17 \u00d7 19 = 323." - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 46, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 431, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cc8c38c49eb5017-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Thu, 12 Feb 2026 02:47:59 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-12T02:47:53Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-12T02:47:59Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-12T02:47:53Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-12T02:47:53Z' - cf-cache-status: - - DYNAMIC - content-length: - - '2530' - request-id: - - req_011CY3Qq8Uoq7QhpK5b2KnAy - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '6043' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 16000, - "messages": [ - { - "role": "user", - "content": "What is 17*19? Think first." - } - ], - "model": "claude-sonnet-4-20250514", - "thinking": { - "type": "enabled", - "budget_tokens": 10000 - } - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '176' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01DcB32cwfGMHtiDGUBij77d", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "thinking", - "thinking": "I need to calculate 17 * 19.\n\nLet me think about this step by step.\n\nI can use the standard multiplication method:\n17 * 19\n\nOne way is to break this down:\n17 * 19 = 17 * (20 - 1) = 17 * 20 - 17 * 1 = 340 - 17 = 323\n\nLet me double-check this another way:\n19 * 17 = 19 * (10 + 7) = 19 * 10 + 19 * 7 = 190 + 133\n\nNow I need to calculate 19 * 7:\n19 * 7 = (20 - 1) * 7 = 20 * 7 - 1 * 7 = 140 - 7 = 133\n\nSo: 190 + 133 = 323\n\nBoth methods give me 323, so that should be correct.", - "signature": "EoAFCkYICxgCKkBXcBjcMdTOeEo8YcimnUeQ6/5AWg0k7fc7hWm28+twAOyMSpID9V8deQAcscFb03tg/oJhlDlowC+4qpccFMDiEgzV/xet2tQ877zlQlgaDGk+lfb8EHdSSw/vHCIw4Jj5mnz2Sp9j/+r9FPnPCqq6DJyAGYLA3kIq8KUbi0/BcTWpaAuFXOk9MBARTnfXKucD1Cw8HNx+RbgKx7ab7T2eb5m6ZBE4oL4D++UBS4bky7dUEEWux+CYZVnnn8w+DBQS/hAwXJritlIF8W0/E3VVdmFnsHfzKNNIxiHbyqIh+jJfRqF9tmYTDro/07Xgn1O9NqOreF8t4uq6SVicy7gUUJcliFC3tJUoHG29HAS3SdCtjiZTpj9YDWj2ZbyLehsKyY4/F4xRur/fe+oyrX1/BHwC4Q16UE95MRtIpqc4X/xbw5NFI1nGPBeP1EVISiqAr+E6OGteJMhbBUX54Zv4B9WduabUidsR4WB5A512Dfz7ozgRMOlZwbYGtHULxK0plAHQqSAmwsVkNBrWXwYscUUCPIHCd+pKy5rRqgV6HnpTBy/S3sziy30PapARjdaJjh0L1wwusjh8G2zretOsxHerWajsJoNJNu32E6kPkeItg5XxK9sx2E9iEdqCq6bAp2Wb67HLdVynO1A/45toa5ayM6vYOWtG/Ko/7M4PDJKDTSOl7TqXpZMvJVsCne3Jr7ia5McdSeYtTdqsgp4HlBWKuQ1Up+hpb46w2xcvzIeQzKfbLH+PLps4INaiRljqv/PYvTNiH4cxfqX+9th/Xz9EcLzRIrU7WvyxFT4TSAmOUVBxh+SkScn/tfVp8ShyCBzUixbVdRgB" - }, - { - "type": "text", - "text": "Let me work through this multiplication step by step.\n\n17 \u00d7 19\n\nI can break this down using the distributive property:\n17 \u00d7 19 = 17 \u00d7 (20 - 1)\n= 17 \u00d7 20 - 17 \u00d7 1\n= 340 - 17\n= 323\n\nLet me verify with another approach:\n17 \u00d7 19 = (10 + 7) \u00d7 19\n= 10 \u00d7 19 + 7 \u00d7 19\n= 190 + 133\n= 323\n\nTherefore, 17 \u00d7 19 = 323." - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 46, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 383, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cd82e9ddc1419c7-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Fri, 13 Feb 2026 23:42:30 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-13T23:42:25Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-13T23:42:30Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-13T23:42:25Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-13T23:42:25Z' - cf-cache-status: - - DYNAMIC - content-length: - - '2165' - request-id: - - req_011CY6xJfRXgTVmeCFV7sX15 - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '5055' - status: - code: 200 - message: OK - request: body: |- { @@ -597,18 +61,18 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_01AiRbEV12LGD5w8ksreTXsZ", + "id": "msg_01YYhGREUae6du1iWeqioVVG", "type": "message", "role": "assistant", "content": [ { "type": "thinking", - "thinking": "I need to calculate 17 \u00d7 19.\n\nLet me think about this step by step. I can use the standard multiplication method or look for patterns.\n\nOne approach is to use the fact that these are close to nice round numbers:\n17 \u00d7 19\n\nI could think of this as:\n(20 - 3) \u00d7 (20 - 1)\n= 20 \u00d7 20 - 20 \u00d7 1 - 3 \u00d7 20 + 3 \u00d7 1\n= 400 - 20 - 60 + 3\n= 400 - 80 + 3\n= 323\n\nLet me double-check this with standard multiplication:\n 17\n\u00d7 19\n____\n\n17 \u00d7 9 = 153\n17 \u00d7 10 = 170\nSo 17 \u00d7 19 = 153 + 170 = 323\n\nYes, that's correct.", - "signature": "EqEFCkYICxgCKkCTb0eqjVwAQqSdzth/z5wnh9Re4uF/nNNJ4QxO4Qcvq/+ykTFIlHyGXI5sQm9hLRovp8m7kk4MWmviFTdovEpoEgyH/kgYBImJl4spznAaDNdM5awpIz+mGQ3o0yIw6H5DQrACn9AMKgpiWGXbEJgjXs3yDuXIbrKm3zYr7J4uHyUhVlA9yomatx9ngcf8KogEV6Rw/A+B/wQ2TJRDhe7zIgMvtAVbEmJsT0wJWUoByEMoL7cm8mhni7bNAl/LKJDiAG0R1g7pJAnN37MXwy0/njjtUCsWaPWhSHJYdYhgF/T48IehHnCUNQCOhQGUAYVBJpqI+gaFdHe3hzNpmTlPCJBUmJtKGf1wSzY/9QkhzO5nWh3AsueKxZoIhxLln/XLpXwvvSgt7zwWzUzpxLeXJTW+Oc6WIPzR1AD2Su+yY1M79QUyoIrEtvKXOod1c9DVILnLk51eHGuZguq6Lq8zxbcXRd7Uz98d8Uzvm/EerejDWoTfDBBiakxGczWXrCy/tUouQXlfGIwGbzXcgPDAXCI/gY0pSAvke/kTgz6hmmGZ45zcSnQEzqtsfeaHSB/TJO5tQL5Hl1gP8VbuOXSlIuv2PTprIeXXfYGQYduBEy80NDDLpIs6h9b006IoGT6DhwS80GzMFMWZo//qK3Rqj00QE3PLTKaMEpvKM/dfTd0k2IBQ79snY7KCHrKi2/TIoUU0yoOZAVVJKLRQ0U8tSNg2mY/OiQx94LntPhWRprPAukFIlTsWMhnwumwnUTL2L7gsfe+2PcW5E5qWtICI8naWyvFCiwVnld9RR5jRLc2ZEA2PSAQSihqMeD0Ct8WYDLr+MwsJMGjrkOgqiSt/935Snc39RoMcjNxJPGBf34bUxdUwqpuCuBgB" + "thinking": "I need to calculate 17 \u00d7 19.\n\nLet me think about this step by step. I can use the standard multiplication method or look for patterns.\n\nOne way is to use the distributive property:\n17 \u00d7 19 = 17 \u00d7 (20 - 1) = 17 \u00d7 20 - 17 \u00d7 1 = 340 - 17 = 323\n\nOr I could do it the other way:\n17 \u00d7 19 = (20 - 3) \u00d7 19 = 20 \u00d7 19 - 3 \u00d7 19 = 380 - 57 = 323\n\nLet me double-check this with standard multiplication:\n 17\n\u00d7 19\n----\n 153 (17 \u00d7 9)\n170 (17 \u00d7 10)\n----\n323\n\nSo 17 \u00d7 9 = 153\nAnd 17 \u00d7 10 = 170\n153 + 170 = 323\n\nYes, that's correct.", + "signature": "ErwFCkYICxgCKkAIyFnVyRLtMaBCLiVKWlkhL8SYinMf/zEwhjv4st3JDPdO0jm+Ld8SZZA8bnRj4vrqMhms4/iO/HYrfUFHsCa/Egxaf/VZi9E7zirZDZIaDDzYRgMY7t+cvg7EdSIwmvdX+u8Gv+uxcu7oKtHQE9dfrZL66SfsDOSWr8aRrt4CdpvfJEcS5Epb4iKJ8ix6KqMEoWAEhCQpZk7AMB4ITt5fCU96O5XrCEsAydYMdeZMdt+OhCWE6O7CYuidCtEPyd0UmOxiG6ZcSv9mDj2dXe77C4FBTqU8zrtlp8Fvu5RcWdLrjJTujKW8Sqv+lBt5HOPgTmouflucoS884UbR5fknJeOiAyljXYc2OcifNZd/tCgsSd7WaSwWhiKx95VFt3Gwz+cNI5IGB29v7uUo4EGUxmbHHzE3Mk7dOh97vk50ejiW5/2XMlkZ6TBqYaEpCwCtrFpymSTcfYYyWeXGaIXImZCQOUmpcev6gJ1WFI8/8/bP4OYtXXnCyJyfBAgXasOcHUIiGF9ipe6OaPKvYS6A3fqavvZnblqxVf4Y10lurRUieCU5jsnmu+SML0VFrexfqe9i5IdMuCHFRJuhzP++b5Tc+tMK9ndmtwT1SVEULWL27HL7Skg3qn1QphZKn0ZQ/JRMR/Rmkau4LL6PC7Ql7YDBmh1mRRTO0b5sTA1x3LhSQUWjX9Ne1zvuCySOLNiatqeA2aERsob02eyqFNuy6dtzD66EaZq7LzmRjlt5jbycmn1axYCQ1EB4I4l2xEA30kNHUzO04YYvnc17W+Ew8MI2l1lNgVH3NaYq2fiSE+FshKz4nM9Omha6pX72vTT3tbeC9tcbpfEbu1B8T+To0uFzjLsIuzjrhaZC1jkamGBp1fsD6TGS6S9eU6zY3xI7+Dju0JXRhS9U4sq4hWh4oV4/khgB" }, { "type": "text", - "text": "I need to calculate 17 \u00d7 19.\n\nLet me use a helpful approach since both numbers are close to 20:\n17 \u00d7 19 = (20 - 3) \u00d7 (20 - 1)\n\nUsing the formula (a - b)(a - c) = a\u00b2 - a(b + c) + bc:\n= 20\u00b2 - 20(3 + 1) + (3 \u00d7 1)\n= 400 - 20(4) + 3\n= 400 - 80 + 3\n= 323\n\nTherefore, 17 \u00d7 19 = 323." + "text": "I need to calculate 17 \u00d7 19.\n\nLet me use the distributive property to make this easier:\n17 \u00d7 19 = 17 \u00d7 (20 - 1) = 17 \u00d7 20 - 17 \u00d7 1 = 340 - 17 = 323\n\nTo verify: I can also think of it as (20 - 3) \u00d7 19 = 20 \u00d7 19 - 3 \u00d7 19 = 380 - 57 = 323\n\nTherefore, 17 \u00d7 19 = 323." } ], "stop_reason": "end_turn", @@ -621,14 +85,14 @@ interactions: "ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0 }, - "output_tokens": 365, + "output_tokens": 376, "service_tier": "standard", "inference_geo": "not_available" } } headers: CF-RAY: - - 9cf1c37a8b2b0f3a-EWR + - 9cfdb94b5cc20cbe-EWR Connection: - keep-alive Content-Security-Policy: @@ -636,7 +100,7 @@ interactions: Content-Type: - application/json Date: - - Tue, 17 Feb 2026 02:13:12 GMT + - Wed, 18 Feb 2026 13:03:23 GMT Server: - cloudflare Transfer-Encoding: @@ -648,35 +112,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-17T02:13:07Z' + - '2026-02-18T13:03:19Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-17T02:13:12Z' + - '2026-02-18T13:03:24Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-17T02:13:06Z' + - '2026-02-18T13:03:18Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-17T02:13:07Z' + - '2026-02-18T13:03:19Z' cf-cache-status: - DYNAMIC content-length: - - '2210' + - '2258' request-id: - - req_011CYCqDtcMKEbbhhvgjfGwR + - req_011CYFacYeTZZTq1MwZRjGzo strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '5889' + - '5637' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml index ddfc4f2d5d..0791d96447 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml @@ -78,660 +78,13 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_013sXaTjCSez5pHDYPvRromP", + "id": "msg_01BTv19CzPqf44Mv3vfQtxEW", "type": "message", "role": "assistant", "content": [ { "type": "tool_use", - "id": "toolu_01DKptrcYW8pczGw82pgshof", - "name": "get_weather", - "input": { - "city": "San Francisco" - } - } - ], - "stop_reason": "tool_use", - "stop_sequence": null, - "usage": { - "input_tokens": 386, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 34, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cc0d10dda96cb2e-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Wed, 11 Feb 2026 03:39:02 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T03:39:02Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T03:39:02Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T03:39:00Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T03:39:02Z' - cf-cache-status: - - DYNAMIC - content-length: - - '523' - request-id: - - req_011CY1avJnEG3TGWYKaBxHSZ - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '2216' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 256, - "messages": [ - { - "role": "user", - "content": "What is the weather in SF?" - } - ], - "model": "claude-sonnet-4-20250514", - "tool_choice": { - "type": "tool", - "name": "get_weather" - }, - "tools": [ - { - "name": "get_weather", - "description": "Get weather by city", - "input_schema": { - "type": "object", - "properties": { - "city": { - "type": "string" - } - }, - "required": [ - "city" - ] - } - } - ] - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '334' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01WD8aRCAvkA54hdDwKKn9HH", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "tool_use", - "id": "toolu_01RdT9XeaCzrDHtCMgjWntbB", - "name": "get_weather", - "input": { - "city": "San Francisco" - } - } - ], - "stop_reason": "tool_use", - "stop_sequence": null, - "usage": { - "input_tokens": 386, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 34, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cc0d5ad481f3788-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Wed, 11 Feb 2026 03:42:10 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T03:42:10Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T03:42:10Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T03:42:09Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T03:42:10Z' - cf-cache-status: - - DYNAMIC - content-length: - - '523' - request-id: - - req_011CY1bAGDahii5NHGYK85GR - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1203' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 256, - "messages": [ - { - "role": "user", - "content": "What is the weather in SF?" - } - ], - "model": "claude-sonnet-4-20250514", - "tool_choice": { - "type": "tool", - "name": "get_weather" - }, - "tools": [ - { - "name": "get_weather", - "description": "Get weather by city", - "input_schema": { - "type": "object", - "properties": { - "city": { - "type": "string" - } - }, - "required": [ - "city" - ] - } - } - ] - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '334' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_011JS9iWt1o4R56eqeZFnHtY", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "tool_use", - "id": "toolu_01W6DT6AwaJh7JkcXYdEiTbh", - "name": "get_weather", - "input": { - "city": "San Francisco" - } - } - ], - "stop_reason": "tool_use", - "stop_sequence": null, - "usage": { - "input_tokens": 386, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 34, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cc8c3843c76efa9-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Thu, 12 Feb 2026 02:47:52 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-12T02:47:52Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-12T02:47:52Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-12T02:47:51Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-12T02:47:52Z' - cf-cache-status: - - DYNAMIC - content-length: - - '523' - request-id: - - req_011CY3Qq2yfbk2hzays52LaG - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1098' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 256, - "messages": [ - { - "role": "user", - "content": "What is the weather in SF?" - } - ], - "model": "claude-sonnet-4-20250514", - "tool_choice": { - "type": "tool", - "name": "get_weather" - }, - "tools": [ - { - "name": "get_weather", - "description": "Get weather by city", - "input_schema": { - "type": "object", - "properties": { - "city": { - "type": "string" - } - }, - "required": [ - "city" - ] - } - } - ] - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '334' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01Yac3xgAwuAo8q33U9YT8vC", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "tool_use", - "id": "toolu_01WYo8aAKBT31hEQzKnrK8Cq", - "name": "get_weather", - "input": { - "city": "San Francisco" - }, - "caller": { - "type": "direct" - } - } - ], - "stop_reason": "tool_use", - "stop_sequence": null, - "usage": { - "input_tokens": 386, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 34, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cd82e943b37c34b-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Fri, 13 Feb 2026 23:42:24 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-13T23:42:24Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-13T23:42:24Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-13T23:42:23Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-13T23:42:24Z' - cf-cache-status: - - DYNAMIC - content-length: - - '550' - request-id: - - req_011CY6xJYrdqFBdaoUS1yCre - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1345' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 256, - "messages": [ - { - "role": "user", - "content": "What is the weather in SF?" - } - ], - "model": "claude-sonnet-4-20250514", - "tool_choice": { - "type": "tool", - "name": "get_weather" - }, - "tools": [ - { - "name": "get_weather", - "description": "Get weather by city", - "input_schema": { - "type": "object", - "properties": { - "city": { - "type": "string" - } - }, - "required": [ - "city" - ] - } - } - ] - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '334' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_017Xjn1Q1m3tfcVWWyHdyQFz", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "tool_use", - "id": "toolu_01V2k9nPLtNMV1Jtqqm4B17D", + "id": "toolu_01EUaABXVkdmAGsMCwv76XKm", "name": "get_weather", "input": { "city": "San Francisco" @@ -758,7 +111,7 @@ interactions: } headers: CF-RAY: - - 9cf1c36fd8960ca2-EWR + - 9cfdb9416a164345-EWR Connection: - keep-alive Content-Security-Policy: @@ -766,7 +119,7 @@ interactions: Content-Type: - application/json Date: - - Tue, 17 Feb 2026 02:13:06 GMT + - Wed, 18 Feb 2026 13:03:18 GMT Server: - cloudflare Transfer-Encoding: @@ -778,35 +131,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-17T02:13:05Z' + - '2026-02-18T13:03:18Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-17T02:13:06Z' + - '2026-02-18T13:03:18Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-17T02:13:04Z' + - '2026-02-18T13:03:16Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-17T02:13:05Z' + - '2026-02-18T13:03:18Z' cf-cache-status: - DYNAMIC content-length: - '550' request-id: - - req_011CYCqDmGpwsQ4qG5mXxzJ1 + - req_011CYFacRqga3Xmm6ToDthnG strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1441' + - '1444' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml index 5e2f776241..3df9807ef4 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml @@ -57,7 +57,7 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_01QiwQEGrr3tagonEdoVhPre", + "id": "msg_01FgtC8QCmPVu51wiSK2JBx5", "type": "message", "role": "assistant", "content": [ @@ -83,7 +83,7 @@ interactions: } headers: CF-RAY: - - 9cc8c3df0c0da5f1-EWR + - 9cfdb978acb072b1-EWR Connection: - keep-alive Content-Security-Policy: @@ -91,7 +91,7 @@ interactions: Content-Type: - application/json Date: - - Thu, 12 Feb 2026 02:48:07 GMT + - Wed, 18 Feb 2026 13:03:26 GMT Server: - cloudflare Transfer-Encoding: @@ -103,307 +103,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-12T02:48:07Z' + - '2026-02-18T13:03:26Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-12T02:48:07Z' + - '2026-02-18T13:03:26Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-12T02:48:06Z' + - '2026-02-18T13:03:25Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-12T02:48:07Z' + - '2026-02-18T13:03:26Z' cf-cache-status: - DYNAMIC content-length: - '441' request-id: - - req_011CY3Qr76FPTFGyXuAkm1oT + - req_011CYFad5co5Bv4yah8Qv7i9 strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1067' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '117' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01VidmfDPxA3g6UHvKJ94mKg", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello!" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 13, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 5, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cd82eebdf34ae4c-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Fri, 13 Feb 2026 23:42:38 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-13T23:42:38Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-13T23:42:38Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-13T23:42:37Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-13T23:42:38Z' - cf-cache-status: - - DYNAMIC - content-length: - - '441' - request-id: - - req_011CY6xKanVwLJ3oYYvwKQtD - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1561' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '117' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01TTpjVNerrMQvGoMvgVQW3s", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello!" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 13, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 5, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cf1c3a8afc1ef9d-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Tue, 17 Feb 2026 02:13:14 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-17T02:13:14Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-17T02:13:14Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-17T02:13:13Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-17T02:13:14Z' - cf-cache-status: - - DYNAMIC - content-length: - - '441' - request-id: - - req_011CYCqES7vXoyukqo4Divwa - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1048' + - '1222' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml index 251aa0e265..4a6bf95b3a 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml @@ -1,1841 +1,4 @@ interactions: -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-3-5-sonnet-20241022" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '114' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python - x-api-key: - - test_anthropic_api_key - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "id": "msg_04AGDUDYJgAACzvnptvVoYEL", - "type": "message", - "role": "assistant", - "model": "claude-3-5-sonnet-20241022", - "content": [ - { - "type": "text", - "text": "Hi!" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 10, - "output_tokens": 3 - } - } - headers: - Connection: - - keep-alive - Content-Type: - - application/json - Date: - - Mon, 15 Dec 2024 10:00:03 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - content-length: - - '340' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-3-5-sonnet-20241022" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '104' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "authentication_error", - "message": "invalid x-api-key" - }, - "request_id": "req_011CX88XA9TbQ5AUJfKb95H1" - } - headers: - CF-RAY: - - 9be0e035a86cc60f-EWR - Connection: - - keep-alive - Content-Length: - - '130' - Content-Type: - - application/json - Date: - - Wed, 14 Jan 2026 23:22:30 GMT - Server: - - cloudflare - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - request-id: - - req_011CX88XA9TbQ5AUJfKb95H1 - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '14' - x-should-retry: - - 'false' - status: - code: 401 - message: Unauthorized -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-3-5-sonnet-20241022" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '104' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "invalid_request_error", - "message": "Your credit balance is too low to access the Anthropic API. Please go to Plans & Billing to upgrade or purchase credits." - }, - "request_id": "req_011CX88Ze7X2Hzt93cQSJVwx" - } - headers: - CF-RAY: - - 9be0e1081e29cb6b-EWR - Connection: - - keep-alive - Content-Length: - - '234' - Content-Type: - - application/json - Date: - - Wed, 14 Jan 2026 23:23:04 GMT - Server: - - cloudflare - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - request-id: - - req_011CX88Ze7X2Hzt93cQSJVwx - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '32' - x-should-retry: - - 'false' - status: - code: 400 - message: Bad Request -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '102' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_0179PsyreizP7wUuiZek9cY1", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hi! How are you doing today?" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 10, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 11, - "service_tier": "standard" - } - } - headers: - CF-RAY: - - 9be0f5f8dbb9c484-EWR - Connection: - - keep-alive - Content-Type: - - application/json - Date: - - Wed, 14 Jan 2026 23:37:24 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '30000' - anthropic-ratelimit-input-tokens-remaining: - - '30000' - anthropic-ratelimit-input-tokens-reset: - - '2026-01-14T23:37:23Z' - anthropic-ratelimit-output-tokens-limit: - - '8000' - anthropic-ratelimit-output-tokens-remaining: - - '8000' - anthropic-ratelimit-output-tokens-reset: - - '2026-01-14T23:37:24Z' - anthropic-ratelimit-requests-limit: - - '50' - anthropic-ratelimit-requests-remaining: - - '49' - anthropic-ratelimit-requests-reset: - - '2026-01-14T23:37:23Z' - anthropic-ratelimit-tokens-limit: - - '38000' - anthropic-ratelimit-tokens-remaining: - - '38000' - anthropic-ratelimit-tokens-reset: - - '2026-01-14T23:37:23Z' - cf-cache-status: - - DYNAMIC - content-length: - - '432' - request-id: - - req_011CX89esEoi7zVpEaWsLZc8 - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '2140' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '102' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_015tg8KmiFK3cef86zqT6mbU", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hi! How are you doing today?" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 10, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 11, - "service_tier": "standard" - } - } - headers: - CF-RAY: - - 9be0f7d4490ae55d-EWR - Connection: - - keep-alive - Content-Type: - - application/json - Date: - - Wed, 14 Jan 2026 23:38:39 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '30000' - anthropic-ratelimit-input-tokens-remaining: - - '30000' - anthropic-ratelimit-input-tokens-reset: - - '2026-01-14T23:38:39Z' - anthropic-ratelimit-output-tokens-limit: - - '8000' - anthropic-ratelimit-output-tokens-remaining: - - '8000' - anthropic-ratelimit-output-tokens-reset: - - '2026-01-14T23:38:39Z' - anthropic-ratelimit-requests-limit: - - '50' - anthropic-ratelimit-requests-remaining: - - '49' - anthropic-ratelimit-requests-reset: - - '2026-01-14T23:38:39Z' - anthropic-ratelimit-tokens-limit: - - '38000' - anthropic-ratelimit-tokens-remaining: - - '38000' - anthropic-ratelimit-tokens-reset: - - '2026-01-14T23:38:39Z' - cf-cache-status: - - DYNAMIC - content-length: - - '432' - request-id: - - req_011CX89kUUFsmSE8auY18PrD - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1745' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '102' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01WZGDeH8YFY9wyqm7sL4n1o", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hi! How are you doing today?" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 10, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 11, - "service_tier": "standard" - } - } - headers: - CF-RAY: - - 9c72cee56e637ac0-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Sun, 01 Feb 2026 16:26:04 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '30000' - anthropic-ratelimit-input-tokens-remaining: - - '30000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-01T16:26:03Z' - anthropic-ratelimit-output-tokens-limit: - - '8000' - anthropic-ratelimit-output-tokens-remaining: - - '8000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-01T16:26:04Z' - anthropic-ratelimit-requests-limit: - - '50' - anthropic-ratelimit-requests-remaining: - - '49' - anthropic-ratelimit-requests-reset: - - '2026-02-01T16:26:03Z' - anthropic-ratelimit-tokens-limit: - - '38000' - anthropic-ratelimit-tokens-remaining: - - '38000' - anthropic-ratelimit-tokens-reset: - - '2026-02-01T16:26:03Z' - cf-cache-status: - - DYNAMIC - content-length: - - '432' - request-id: - - req_011CXhfKepmyNSxwSrTaXZ4L - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1917' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '102' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "authentication_error", - "message": "invalid x-api-key" - }, - "request_id": "req_011CXwgSa1AxGMtGd5XzdLen" - } - headers: - CF-RAY: - - 9cafd284cbd141b5-EWR - Connection: - - keep-alive - Content-Length: - - '130' - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Mon, 09 Feb 2026 02:09:02 GMT - Server: - - cloudflare - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXwgSa1AxGMtGd5XzdLen - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '7' - x-should-retry: - - 'false' - status: - code: 401 - message: Unauthorized -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '102' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01K7sVffGTWcSPty9YFESayA", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hi! How are you doing today?" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 10, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 11, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cafd4580dc9e55d-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Mon, 09 Feb 2026 02:10:18 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-09T02:10:17Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-09T02:10:18Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-09T02:10:17Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-09T02:10:17Z' - cf-cache-status: - - DYNAMIC - content-length: - - '464' - request-id: - - req_011CXwgY5eXH1H2GjpRV41H1 - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1045' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '102' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01QBMLAiUoeut6fBz8vGFvJT", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hi! How are you doing today?" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 10, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 11, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cb07ee279e9daac-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Mon, 09 Feb 2026 04:06:43 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-09T04:06:43Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-09T04:06:43Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-09T04:06:42Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-09T04:06:43Z' - cf-cache-status: - - DYNAMIC - content-length: - - '464' - request-id: - - req_011CXwqR1156Euh9aZyJgEac - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1464' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '102' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01Sq9dhxjKKX1FCrg1eDTDui", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hi! How are you doing today?" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 10, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 11, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cb889e62e1e2f65-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Tue, 10 Feb 2026 03:32:21 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-10T03:32:20Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-10T03:32:21Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-10T03:32:19Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-10T03:32:20Z' - cf-cache-status: - - DYNAMIC - content-length: - - '464' - request-id: - - req_011CXygbrtvjUXsii1Y146gj - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1635' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '102' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01QkMfxdENJsSAdg89asyjPS", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hi! How are you doing today?" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 10, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 11, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cbfd28298bc8465-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Wed, 11 Feb 2026 00:45:15 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T00:45:15Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T00:45:15Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T00:45:14Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T00:45:15Z' - cf-cache-status: - - DYNAMIC - content-length: - - '464' - request-id: - - req_011CY1MfkZLeSpsrk6Wnhb42 - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1311' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '102' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01KpPuYdUUBsFSMC4YFAhejS", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hi! How are you doing today?" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 10, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 11, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cc0d0c49ffad826-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Wed, 11 Feb 2026 03:38:49 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T03:38:49Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T03:38:49Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T03:38:48Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T03:38:49Z' - cf-cache-status: - - DYNAMIC - content-length: - - '464' - request-id: - - req_011CY1auSb1ACRDz6yT5P3Du - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1212' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '102' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01W5pBhYzMpo9pNVuKeQjc9E", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hi! How are you doing today?" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 10, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 11, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cc0d562eb7eb4c6-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Wed, 11 Feb 2026 03:41:58 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T03:41:58Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T03:41:58Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T03:41:57Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T03:41:58Z' - cf-cache-status: - - DYNAMIC - content-length: - - '464' - request-id: - - req_011CY1b9PNRF9QtcWWkZgDbM - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1338' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '102' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_015bDxsCC482eLwW9VQmPvMY", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hi! How are you doing today?" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 10, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 11, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cc8c33b4e95de9c-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Thu, 12 Feb 2026 02:47:41 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-12T02:47:40Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-12T02:47:41Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-12T02:47:40Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-12T02:47:40Z' - cf-cache-status: - - DYNAMIC - content-length: - - '464' - request-id: - - req_011CY3QpB5Z2mPessQ4wQfC9 - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1135' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '102' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_019sMwyH2n7xqwoqcvcnJrpn", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hi! How are you doing today?" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 10, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 11, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cd82e2d0d188815-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Fri, 13 Feb 2026 23:42:08 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-13T23:42:08Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-13T23:42:08Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-13T23:42:07Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-13T23:42:08Z' - cf-cache-status: - - DYNAMIC - content-length: - - '464' - request-id: - - req_011CY6xHLFadWrxbEc4Gq2h6 - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1381' - status: - code: 200 - message: OK - request: body: |- { @@ -1894,7 +57,7 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_01QabVhwFhxmCLn3zE8qFgXi", + "id": "msg_01KVUfQS8uK6f1tRbPsQ4ktb", "type": "message", "role": "assistant", "content": [ @@ -1920,7 +83,7 @@ interactions: } headers: CF-RAY: - - 9cf1c33b3f44425f-EWR + - 9cfdb9003a8299cb-EWR Connection: - keep-alive Content-Security-Policy: @@ -1928,7 +91,7 @@ interactions: Content-Type: - application/json Date: - - Tue, 17 Feb 2026 02:12:57 GMT + - Wed, 18 Feb 2026 13:03:07 GMT Server: - cloudflare Transfer-Encoding: @@ -1940,35 +103,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-17T02:12:57Z' + - '2026-02-18T13:03:07Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-17T02:12:57Z' + - '2026-02-18T13:03:07Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-17T02:12:56Z' + - '2026-02-18T13:03:06Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-17T02:12:57Z' + - '2026-02-18T13:03:07Z' cf-cache-status: - DYNAMIC content-length: - '464' request-id: - - req_011CYCqD9KbrQfHVHKYwkJJi + - req_011CYFabfFJk35kvqvHeTs4L strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1156' + - '1323' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml index d87de779b1..c79275391a 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml @@ -57,1158 +57,7 @@ interactions: body: string: |+ event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01L4V8w9WcTqy9XqeSGMvtmU","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard"}}} - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"}} - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9c72cefdb96f5e71-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Sun, 01 Feb 2026 16:26:07 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '30000' - anthropic-ratelimit-input-tokens-remaining: - - '30000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-01T16:26:06Z' - anthropic-ratelimit-output-tokens-limit: - - '8000' - anthropic-ratelimit-output-tokens-remaining: - - '8000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-01T16:26:06Z' - anthropic-ratelimit-requests-limit: - - '50' - anthropic-ratelimit-requests-remaining: - - '49' - anthropic-ratelimit-requests-reset: - - '2026-02-01T16:26:07Z' - anthropic-ratelimit-tokens-limit: - - '38000' - anthropic-ratelimit-tokens-remaining: - - '38000' - anthropic-ratelimit-tokens-reset: - - '2026-02-01T16:26:06Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXhfKwTQ5cLbB8jmLW9Td - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1221' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "authentication_error", - "message": "invalid x-api-key" - }, - "request_id": "req_011CXwgShB2Qa8WVkqeYfXig" - } - headers: - CF-RAY: - - 9cafd28f4a9a43cb-EWR - Connection: - - keep-alive - Content-Length: - - '130' - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Mon, 09 Feb 2026 02:09:03 GMT - Server: - - cloudflare - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXwgShB2Qa8WVkqeYfXig - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '8' - x-should-retry: - - 'false' - status: - code: 401 - message: Unauthorized -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01NPELKwEsJZ8JkGYmWb1dNZ","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cafd46b1f6bda48-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Mon, 09 Feb 2026 02:10:21 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-09T02:10:20Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-09T02:10:20Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-09T02:10:20Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-09T02:10:20Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXwgYJharaeaLQLFUgtAA - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1032' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01UM7FKi4sQ9AuD6jidmAKn9","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}} - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"}} - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cb07ef75f9041d2-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Mon, 09 Feb 2026 04:06:46 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-09T04:06:45Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-09T04:06:45Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-09T04:06:45Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-09T04:06:45Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXwqRFJ44wMGtnsUvEm3R - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '911' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_012oHhogVPBokZdYPVAew9X9","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cb889fc19275642-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Tue, 10 Feb 2026 03:32:24 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-10T03:32:23Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-10T03:32:23Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-10T03:32:23Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-10T03:32:23Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXygc7sLZXhoTvZSQiyNf - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1093' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01DEXdKjQxYs1URcxvKjQEwq","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cbfd2977ad0a10a-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Wed, 11 Feb 2026 00:45:18 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T00:45:17Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T00:45:17Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T00:45:17Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T00:45:17Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY1Mfzr54eUeix1eS7ZhW - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '780' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01HGay48sqJhc56SNCJjCoiz","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cc0d0d8983c1016-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Wed, 11 Feb 2026 03:38:52 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T03:38:51Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T03:38:51Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T03:38:51Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T03:38:51Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY1augFnKZsDhThMeaNLy - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1156' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_011weMCgsfAXGexR1Gq7hgjC","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cc0d5772b0ad123-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Wed, 11 Feb 2026 03:42:01 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T03:42:00Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T03:42:00Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T03:42:00Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T03:42:00Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY1b9dEMJJx7nop7Qrz56 - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1006' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01AKmfTCRXXJUUpkT6xknT7E","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello."} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cc8c34ebbbec439-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Thu, 12 Feb 2026 02:47:44 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-12T02:47:43Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-12T02:47:43Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-12T02:47:43Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-12T02:47:43Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY3QpQP1CyWbnSVQFwuUD - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '963' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01ECD5aYyRDZwE7pLF57iur3","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}}} + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01TWy739zrnMHqPHvW8oMvA4","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}}} event: content_block_start data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } @@ -1217,152 +66,20 @@ interactions: data: {"type": "ping"} event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cd82e434e02187f-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Fri, 13 Feb 2026 23:42:11 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-13T23:42:10Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-13T23:42:10Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-13T23:42:10Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-13T23:42:10Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY6xHbVMziDESSCKs8LPU - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '878' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_018kVwSv5McDqGb49NRcyCKB","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } event: content_block_stop - data: {"type":"content_block_stop","index":0 } + data: {"type":"content_block_stop","index":0 } event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } event: message_stop - data: {"type":"message_stop" } + data: {"type":"message_stop" } headers: CF-RAY: - - 9cf1c34e4cad43b5-EWR + - 9cfdb912ab2b8e3e-EWR Cache-Control: - no-cache Connection: @@ -1372,7 +89,7 @@ interactions: Content-Type: - text/event-stream; charset=utf-8 Date: - - Tue, 17 Feb 2026 02:13:00 GMT + - Wed, 18 Feb 2026 13:03:10 GMT Server: - cloudflare Transfer-Encoding: @@ -1384,33 +101,33 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-17T02:12:59Z' + - '2026-02-18T13:03:09Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-17T02:12:59Z' + - '2026-02-18T13:03:09Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-17T02:12:59Z' + - '2026-02-18T13:03:09Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-17T02:12:59Z' + - '2026-02-18T13:03:09Z' cf-cache-status: - DYNAMIC request-id: - - req_011CYCqDNLw9NwvMaLnrcft4 + - req_011CYFabssKz9uZDCAgktax9 strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '810' + - '1060' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml index 7ebf1b2228..cffe35684e 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml @@ -57,7 +57,7 @@ interactions: body: string: |+ event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01L4V8w9WcTqy9XqeSGMvtmU","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard"}}} + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01PTnvySwm1bNVqeGkMTGk8Q","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } event: content_block_start data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } @@ -66,1303 +66,20 @@ interactions: data: {"type": "ping"} event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"}} + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9c72cefdb96f5e71-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Sun, 01 Feb 2026 16:26:07 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '30000' - anthropic-ratelimit-input-tokens-remaining: - - '30000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-01T16:26:06Z' - anthropic-ratelimit-output-tokens-limit: - - '8000' - anthropic-ratelimit-output-tokens-remaining: - - '8000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-01T16:26:06Z' - anthropic-ratelimit-requests-limit: - - '50' - anthropic-ratelimit-requests-remaining: - - '49' - anthropic-ratelimit-requests-reset: - - '2026-02-01T16:26:07Z' - anthropic-ratelimit-tokens-limit: - - '38000' - anthropic-ratelimit-tokens-remaining: - - '38000' - anthropic-ratelimit-tokens-reset: - - '2026-02-01T16:26:06Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXhfKwTQ5cLbB8jmLW9Td - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1221' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "authentication_error", - "message": "invalid x-api-key" - }, - "request_id": "req_011CXwgShB2Qa8WVkqeYfXig" - } - headers: - CF-RAY: - - 9cafd28f4a9a43cb-EWR - Connection: - - keep-alive - Content-Length: - - '130' - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Mon, 09 Feb 2026 02:09:03 GMT - Server: - - cloudflare - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXwgShB2Qa8WVkqeYfXig - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '8' - x-should-retry: - - 'false' - status: - code: 401 - message: Unauthorized -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01NPELKwEsJZ8JkGYmWb1dNZ","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cafd46b1f6bda48-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Mon, 09 Feb 2026 02:10:21 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-09T02:10:20Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-09T02:10:20Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-09T02:10:20Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-09T02:10:20Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXwgYJharaeaLQLFUgtAA - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1032' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01UM7FKi4sQ9AuD6jidmAKn9","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}} - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"}} - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cb07ef75f9041d2-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Mon, 09 Feb 2026 04:06:46 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-09T04:06:45Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-09T04:06:45Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-09T04:06:45Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-09T04:06:45Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXwqRFJ44wMGtnsUvEm3R - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '911' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_012oHhogVPBokZdYPVAew9X9","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cb889fc19275642-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Tue, 10 Feb 2026 03:32:24 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-10T03:32:23Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-10T03:32:23Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-10T03:32:23Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-10T03:32:23Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXygc7sLZXhoTvZSQiyNf - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1093' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01UzxnH6yLX2hYsuaswms5M5","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cbfd29eec70659d-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Wed, 11 Feb 2026 00:45:19 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T00:45:18Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T00:45:18Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T00:45:18Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T00:45:18Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY1Mg5vfKFrFYmCmCEgn1 - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '815' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01JhhD5JShFDfmFGe5wKmgCg","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cc0d0e1e97edb40-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Wed, 11 Feb 2026 03:38:54 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T03:38:53Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T03:38:53Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T03:38:53Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T03:38:53Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY1aundm4FDfWaP7mx3Z3 - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1156' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_0188ofvsbrF4hnB1ctEazjQn","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"}} - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cc0d57fb8d40f93-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Wed, 11 Feb 2026 03:42:02 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T03:42:02Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T03:42:02Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T03:42:02Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T03:42:02Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY1b9j46Pwx2pYJKJ9MjW - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '785' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01DB4wa2XbVxgZXXW7UAGGCb","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cc8c357ffc043aa-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Thu, 12 Feb 2026 02:47:45 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-12T02:47:44Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-12T02:47:44Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-12T02:47:44Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-12T02:47:44Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY3QpWhWTag5PSoX3S4ws - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '932' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01VYEaknA5ZXjy22Sig9SWjN","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cd82e4b3c72432c-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Fri, 13 Feb 2026 23:42:12 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-13T23:42:11Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-13T23:42:11Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-13T23:42:11Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-13T23:42:11Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY6xHgwHTRxFXsS6rpDZD - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1131' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hello in one word." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '131' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_015yjvSJ5PzmJPZLM8BXMUFH","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } + data: {"type":"content_block_stop","index":0 } event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } event: message_stop - data: {"type":"message_stop" } + data: {"type":"message_stop" } headers: CF-RAY: - - 9cf1c355f9ab4385-EWR + - 9cfdb91afa64985c-EWR Cache-Control: - no-cache Connection: @@ -1372,7 +89,7 @@ interactions: Content-Type: - text/event-stream; charset=utf-8 Date: - - Tue, 17 Feb 2026 02:13:01 GMT + - Wed, 18 Feb 2026 13:03:12 GMT Server: - cloudflare Transfer-Encoding: @@ -1384,33 +101,33 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-17T02:13:00Z' + - '2026-02-18T13:03:11Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-17T02:13:00Z' + - '2026-02-18T13:03:11Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-17T02:13:00Z' + - '2026-02-18T13:03:11Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-17T02:13:00Z' + - '2026-02-18T13:03:11Z' cf-cache-status: - DYNAMIC request-id: - - req_011CYCqDTgeuTDxWBoPw1kQi + - req_011CYFabyc7Ne8XxYdhuD7yh strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '920' + - '2127' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml index aaac645bd0..da620f74fc 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml @@ -57,1368 +57,10 @@ interactions: body: string: |+ event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_0159m5BagLKEtHHfhvuJinV7","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard"}} } + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01V9EcqsWc8Bq8gjKW52VtG3","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"!"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" How"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are you doing today?"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } - - event: message_stop - data: {"type":"message_stop"} - - headers: - CF-RAY: - - 9c72cf073e4bacc5-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Sun, 01 Feb 2026 16:26:09 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '30000' - anthropic-ratelimit-input-tokens-remaining: - - '30000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-01T16:26:08Z' - anthropic-ratelimit-output-tokens-limit: - - '8000' - anthropic-ratelimit-output-tokens-remaining: - - '8000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-01T16:26:08Z' - anthropic-ratelimit-requests-limit: - - '50' - anthropic-ratelimit-requests-remaining: - - '49' - anthropic-ratelimit-requests-reset: - - '2026-02-01T16:26:09Z' - anthropic-ratelimit-tokens-limit: - - '38000' - anthropic-ratelimit-tokens-remaining: - - '38000' - anthropic-ratelimit-tokens-reset: - - '2026-02-01T16:26:08Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXhfL3wpdUeBmx5xUp4Fg - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1202' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '116' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "authentication_error", - "message": "invalid x-api-key" - }, - "request_id": "req_011CXwgSi5qjxtkPurKtrXr7" - } - headers: - CF-RAY: - - 9cafd29099c42223-EWR - Connection: - - keep-alive - Content-Length: - - '130' - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Mon, 09 Feb 2026 02:09:04 GMT - Server: - - cloudflare - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXwgSi5qjxtkPurKtrXr7 - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '13' - x-should-retry: - - 'false' - status: - code: 401 - message: Unauthorized -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '116' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_014NZvt7j1MKDNTWFjhWasU9","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"!"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" How"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"}} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" you doing today?"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cafd475585f0cc8-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Mon, 09 Feb 2026 02:10:22 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-09T02:10:21Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-09T02:10:21Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-09T02:10:21Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-09T02:10:21Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXwgYRjkokczYVciHiVSL - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '997' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '116' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01JQWybySyhRsevUAmynSLpW","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"!"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" How"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are you doing today?"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cb07eff1c978153-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Mon, 09 Feb 2026 04:06:47 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-09T04:06:47Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-09T04:06:47Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-09T04:06:47Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-09T04:06:47Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXwqRLbYFZHkPv1hGbWUK - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '955' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '116' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01ApLwwRkGe67Yjnarmgk4eu","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}} - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"! How"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" you doing today?"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cb88a04da4cf78d-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Tue, 10 Feb 2026 03:32:25 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-10T03:32:24Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-10T03:32:24Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-10T03:32:24Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-10T03:32:24Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXygcDsk8uukt8VNQHvUK - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '906' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '116' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01NZGnKhEzSZicN3pG2orWNg","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"! How"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are you doing today?"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cbfd2a5ff6b3ee0-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Wed, 11 Feb 2026 00:45:20 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T00:45:19Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T00:45:19Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T00:45:19Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T00:45:19Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY1MgAmsDhdF2P7xHz91Y - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1248' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '116' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01EUUGDrivPbs3wQZuCWKegE","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" there! How"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" you doing today?"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0} - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":12} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cc0d0eb99224276-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Wed, 11 Feb 2026 03:38:55 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T03:38:54Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T03:38:54Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T03:38:54Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T03:38:54Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY1auuH7E9b5k7Kmucga8 - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '927' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '116' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01Ddsijy47vScG6hRZMFrzTD","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"! How"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are you doing today?"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cc0d5872f8058c1-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Wed, 11 Feb 2026 03:42:04 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T03:42:03Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T03:42:03Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T03:42:03Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T03:42:03Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY1b9pAvKt35Cpcy14vgn - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1220' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '116' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01LYmwC7VS3vLuFPDVTi8Wvm","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"! How"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" you doing today?"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } - - event: message_stop - data: {"type":"message_stop" } - - headers: - CF-RAY: - - 9cc8c3606fe8e8c4-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Thu, 12 Feb 2026 02:47:46 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-12T02:47:46Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-12T02:47:46Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-12T02:47:46Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-12T02:47:46Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY3QpcUms4usvBtgfQVxQ - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '971' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '116' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_012e4YtASKobtskDRfzWPTD3","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } - - event: ping - data: {"type": "ping"} - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"! How"} } - - event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are you doing today?"} } - - event: content_block_stop - data: {"type":"content_block_stop","index":0 } - - event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } - - event: message_stop - data: {"type":"message_stop"} - - headers: - CF-RAY: - - 9cd82e54eb8a1768-EWR - Cache-Control: - - no-cache - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - text/event-stream; charset=utf-8 - Date: - - Fri, 13 Feb 2026 23:42:14 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-13T23:42:13Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-13T23:42:13Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-13T23:42:13Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-13T23:42:13Z' - cf-cache-status: - - DYNAMIC - request-id: - - req_011CY6xHoXQudgmTiYH5BPvv - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1141' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Say hi." - } - ], - "model": "claude-sonnet-4-20250514", - "stream": true - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '116' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - NOT_GIVEN - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |+ - event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01NFPZNyvNoXBVe7xMc18XNq","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } - - event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } event: ping data: {"type": "ping"} @@ -1427,23 +69,23 @@ interactions: data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"! How"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" there! How"} } event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are you doing today?"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are you doing today?"} } event: content_block_stop - data: {"type":"content_block_stop","index":0 } + data: {"type":"content_block_stop","index":0 } event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":12} } event: message_stop - data: {"type":"message_stop" } + data: {"type":"message_stop" } headers: CF-RAY: - - 9cf1c35e997bc54d-EWR + - 9cfdb92e0d7e99cb-EWR Cache-Control: - no-cache Connection: @@ -1453,7 +95,7 @@ interactions: Content-Type: - text/event-stream; charset=utf-8 Date: - - Tue, 17 Feb 2026 02:13:02 GMT + - Wed, 18 Feb 2026 13:03:14 GMT Server: - cloudflare Transfer-Encoding: @@ -1465,33 +107,33 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-17T02:13:01Z' + - '2026-02-18T13:03:13Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-17T02:13:01Z' + - '2026-02-18T13:03:13Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-17T02:13:02Z' + - '2026-02-18T13:03:13Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-17T02:13:01Z' + - '2026-02-18T13:03:13Z' cf-cache-status: - DYNAMIC request-id: - - req_011CYCqDZTvF6cNWtrStmFB3 + - req_011CYFacCeBsLuF97ndtCKfn strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1046' + - '1144' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml index ba572f40b0..fefcfc5cb1 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml @@ -1,1841 +1,4 @@ interactions: -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Count to 5." - } - ], - "model": "claude-3-5-sonnet-20241022" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '118' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python - x-api-key: - - test_anthropic_api_key - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "id": "msg_03ZGDUDYJgAACzvnptvVoYEL", - "type": "message", - "role": "assistant", - "model": "claude-3-5-sonnet-20241022", - "content": [ - { - "type": "text", - "text": "1, 2, 3, 4, 5" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 12, - "output_tokens": 14 - } - } - headers: - Connection: - - keep-alive - Content-Type: - - application/json - Date: - - Mon, 15 Dec 2024 10:00:02 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - content-length: - - '355' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Count to 5." - } - ], - "model": "claude-3-5-sonnet-20241022" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '108' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "authentication_error", - "message": "invalid x-api-key" - }, - "request_id": "req_011CX88X9HN93DBTEXsjo9DZ" - } - headers: - CF-RAY: - - 9be0e0346f01a0f4-EWR - Connection: - - keep-alive - Content-Length: - - '130' - Content-Type: - - application/json - Date: - - Wed, 14 Jan 2026 23:22:30 GMT - Server: - - cloudflare - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - request-id: - - req_011CX88X9HN93DBTEXsjo9DZ - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '11' - x-should-retry: - - 'false' - status: - code: 401 - message: Unauthorized -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Count to 5." - } - ], - "model": "claude-3-5-sonnet-20241022" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '108' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "invalid_request_error", - "message": "Your credit balance is too low to access the Anthropic API. Please go to Plans & Billing to upgrade or purchase credits." - }, - "request_id": "req_011CX88Zd4WpWvH6NbSKLd4T" - } - headers: - CF-RAY: - - 9be0e1068d28f9a9-EWR - Connection: - - keep-alive - Content-Length: - - '234' - Content-Type: - - application/json - Date: - - Wed, 14 Jan 2026 23:23:04 GMT - Server: - - cloudflare - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - request-id: - - req_011CX88Zd4WpWvH6NbSKLd4T - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '23' - x-should-retry: - - 'false' - status: - code: 400 - message: Bad Request -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Count to 5." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '106' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01ASpi9ptEqzyzyCGk3aB1tr", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "1\n2\n3\n4\n5" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 12, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 13, - "service_tier": "standard" - } - } - headers: - CF-RAY: - - 9be0f5e96d19cc98-EWR - Connection: - - keep-alive - Content-Type: - - application/json - Date: - - Wed, 14 Jan 2026 23:37:21 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '30000' - anthropic-ratelimit-input-tokens-remaining: - - '30000' - anthropic-ratelimit-input-tokens-reset: - - '2026-01-14T23:37:21Z' - anthropic-ratelimit-output-tokens-limit: - - '8000' - anthropic-ratelimit-output-tokens-remaining: - - '8000' - anthropic-ratelimit-output-tokens-reset: - - '2026-01-14T23:37:21Z' - anthropic-ratelimit-requests-limit: - - '50' - anthropic-ratelimit-requests-remaining: - - '49' - anthropic-ratelimit-requests-reset: - - '2026-01-14T23:37:20Z' - anthropic-ratelimit-tokens-limit: - - '38000' - anthropic-ratelimit-tokens-remaining: - - '38000' - anthropic-ratelimit-tokens-reset: - - '2026-01-14T23:37:21Z' - cf-cache-status: - - DYNAMIC - content-length: - - '417' - request-id: - - req_011CX89egfZS3S8npjMnb4jb - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '2246' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Count to 5." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '106' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01JFQS8RhcxvidJNQvmANwSp", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "1, 2, 3, 4, 5" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 12, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 17, - "service_tier": "standard" - } - } - headers: - CF-RAY: - - 9be0f7c51d21c62c-EWR - Connection: - - keep-alive - Content-Type: - - application/json - Date: - - Wed, 14 Jan 2026 23:38:37 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '30000' - anthropic-ratelimit-input-tokens-remaining: - - '30000' - anthropic-ratelimit-input-tokens-reset: - - '2026-01-14T23:38:36Z' - anthropic-ratelimit-output-tokens-limit: - - '8000' - anthropic-ratelimit-output-tokens-remaining: - - '8000' - anthropic-ratelimit-output-tokens-reset: - - '2026-01-14T23:38:38Z' - anthropic-ratelimit-requests-limit: - - '50' - anthropic-ratelimit-requests-remaining: - - '49' - anthropic-ratelimit-requests-reset: - - '2026-01-14T23:38:36Z' - anthropic-ratelimit-tokens-limit: - - '38000' - anthropic-ratelimit-tokens-remaining: - - '38000' - anthropic-ratelimit-tokens-reset: - - '2026-01-14T23:38:36Z' - cf-cache-status: - - DYNAMIC - content-length: - - '417' - request-id: - - req_011CX89kJ5gA2k39mva9DeiB - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '2244' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Count to 5." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '106' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_018pv7xuy9NfeeRkFsp9TaNB", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "1\n2\n3\n4\n5" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 12, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 13, - "service_tier": "standard" - } - } - headers: - CF-RAY: - - 9c72ced8a94daf79-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Sun, 01 Feb 2026 16:26:02 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '30000' - anthropic-ratelimit-input-tokens-remaining: - - '30000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-01T16:26:02Z' - anthropic-ratelimit-output-tokens-limit: - - '8000' - anthropic-ratelimit-output-tokens-remaining: - - '8000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-01T16:26:02Z' - anthropic-ratelimit-requests-limit: - - '50' - anthropic-ratelimit-requests-remaining: - - '49' - anthropic-ratelimit-requests-reset: - - '2026-02-01T16:26:02Z' - anthropic-ratelimit-tokens-limit: - - '38000' - anthropic-ratelimit-tokens-remaining: - - '38000' - anthropic-ratelimit-tokens-reset: - - '2026-02-01T16:26:02Z' - cf-cache-status: - - DYNAMIC - content-length: - - '417' - request-id: - - req_011CXhfKW89PXnDc5HQXH99X - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1884' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Count to 5." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '106' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "authentication_error", - "message": "invalid x-api-key" - }, - "request_id": "req_011CXwgSYmWMTGa8zyoZHp28" - } - headers: - CF-RAY: - - 9cafd282fe6680ce-EWR - Connection: - - keep-alive - Content-Length: - - '130' - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Mon, 09 Feb 2026 02:09:01 GMT - Server: - - cloudflare - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXwgSYmWMTGa8zyoZHp28 - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '7' - x-should-retry: - - 'false' - status: - code: 401 - message: Unauthorized -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Count to 5." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '106' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01C2Kwxu5ub3DBhyMpJ5Zkce", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "1\n2\n3\n4\n5" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 12, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 13, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cafd44f8d180c76-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Mon, 09 Feb 2026 02:10:16 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-09T02:10:16Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-09T02:10:16Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-09T02:10:15Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-09T02:10:16Z' - cf-cache-status: - - DYNAMIC - content-length: - - '449' - request-id: - - req_011CXwgXyq2Wq9g7egMSk4om - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1122' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Count to 5." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '106' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01HX4WVufKAzBqYmzF7mk8qy", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "1, 2, 3, 4, 5" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 12, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 17, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cb07ed81d621f03-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Mon, 09 Feb 2026 04:06:42 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-09T04:06:41Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-09T04:06:41Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-09T04:06:40Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-09T04:06:41Z' - cf-cache-status: - - DYNAMIC - content-length: - - '449' - request-id: - - req_011CXwqQsvfyqSDGqpibBfuU - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1327' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Count to 5." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '106' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01871ZBq5Y4CXmNXvUZJZSjB", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "1, 2, 3, 4, 5" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 12, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 17, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cb889dad8d81c6f-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Tue, 10 Feb 2026 03:32:19 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-10T03:32:18Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-10T03:32:19Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-10T03:32:17Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-10T03:32:18Z' - cf-cache-status: - - DYNAMIC - content-length: - - '449' - request-id: - - req_011CXygbj9MRg9YVhm8owbVG - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1471' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Count to 5." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '106' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_013MNsLPFCh6U1ktNYd1w1Kt", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "1, 2, 3, 4, 5" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 12, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 17, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cbfd2729fbfc3ab-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Wed, 11 Feb 2026 00:45:13 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T00:45:13Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T00:45:13Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T00:45:11Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T00:45:13Z' - cf-cache-status: - - DYNAMIC - content-length: - - '449' - request-id: - - req_011CY1MfZbXeLTM8bkcxvgvd - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '2317' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Count to 5." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '106' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01TZ2mzRLhFAZFMNDHjjgm3X", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "1\n2\n3\n4\n5" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 12, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 13, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cc0d0ba3fead826-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Wed, 11 Feb 2026 03:38:48 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T03:38:47Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T03:38:48Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T03:38:46Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T03:38:47Z' - cf-cache-status: - - DYNAMIC - content-length: - - '449' - request-id: - - req_011CY1auKVNGfuc2JAZMRHYC - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1399' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Count to 5." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '106' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01KtEQPkubeVibsiUEWJGuQb", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "1, 2, 3, 4, 5" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 12, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 17, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cc0d5594b29438c-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Wed, 11 Feb 2026 03:41:57 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T03:41:57Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T03:41:57Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T03:41:56Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T03:41:57Z' - cf-cache-status: - - DYNAMIC - content-length: - - '449' - request-id: - - req_011CY1b9GoXNd1TjZRyYLyFT - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1224' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Count to 5." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '106' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01L6VCoGpqErD9JSmy5p64Pp", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "1\n2\n3\n4\n5" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 12, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 13, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cc8c330aac12067-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Thu, 12 Feb 2026 02:47:39 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-12T02:47:39Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-12T02:47:39Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-12T02:47:38Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-12T02:47:39Z' - cf-cache-status: - - DYNAMIC - content-length: - - '449' - request-id: - - req_011CY3Qp3qjSQQbCT4NAu6JL - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1403' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 100, - "messages": [ - { - "role": "user", - "content": "Count to 5." - } - ], - "model": "claude-sonnet-4-20250514" - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '106' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_017ELW7Px1dL94WeMFzhuzqt", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "1\n2\n3\n4\n5" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 12, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 13, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cd82e23fef3ffd0-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Fri, 13 Feb 2026 23:42:06 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-13T23:42:06Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-13T23:42:06Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-13T23:42:05Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-13T23:42:06Z' - cf-cache-status: - - DYNAMIC - content-length: - - '449' - request-id: - - req_011CY6xHE5Fo2oiAKNJvbd1E - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1108' - status: - code: 200 - message: OK - request: body: |- { @@ -1894,7 +57,7 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_01KXKRGvCArYurAWdi9yTPZ4", + "id": "msg_01GApBhZsKAd9ydf4bAuJQtG", "type": "message", "role": "assistant", "content": [ @@ -1920,7 +83,7 @@ interactions: } headers: CF-RAY: - - 9cf1c330b8527c96-EWR + - 9cfdb8f5f8461768-EWR Connection: - keep-alive Content-Security-Policy: @@ -1928,7 +91,7 @@ interactions: Content-Type: - application/json Date: - - Tue, 17 Feb 2026 02:12:55 GMT + - Wed, 18 Feb 2026 13:03:06 GMT Server: - cloudflare Transfer-Encoding: @@ -1940,35 +103,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-17T02:12:55Z' + - '2026-02-18T13:03:05Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-17T02:12:55Z' + - '2026-02-18T13:03:06Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-17T02:12:54Z' + - '2026-02-18T13:03:04Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-17T02:12:55Z' + - '2026-02-18T13:03:05Z' cf-cache-status: - DYNAMIC content-length: - '449' request-id: - - req_011CYCqD281dvCxydEgB7wau + - req_011CYFabYE8rYYWg3TYBoDAo strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1364' + - '1466' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml index 7205734fac..3ca1e69cd7 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml @@ -1,1789 +1,4 @@ interactions: -- request: - body: |- - { - "max_tokens": 50, - "messages": [ - { - "role": "user", - "content": "Say hello." - } - ], - "model": "claude-3-5-sonnet-20241022", - "stop_sequences": [ - "STOP" - ], - "temperature": 0.7, - "top_k": 40, - "top_p": 0.9 - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '200' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python - x-api-key: - - test_anthropic_api_key - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "id": "msg_02YGDUDYJgAACzvnptvVoYEL", - "type": "message", - "role": "assistant", - "model": "claude-3-5-sonnet-20241022", - "content": [ - { - "type": "text", - "text": "Hello! How can I help you today?" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 10, - "output_tokens": 10 - } - } - headers: - Connection: - - keep-alive - Content-Type: - - application/json - Date: - - Mon, 15 Dec 2024 10:00:01 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - content-length: - - '380' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 50, - "messages": [ - { - "role": "user", - "content": "Say hello." - } - ], - "model": "claude-3-5-sonnet-20241022", - "stop_sequences": [ - "STOP" - ], - "temperature": 0.7, - "top_k": 40, - "top_p": 0.9 - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '173' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "authentication_error", - "message": "invalid x-api-key" - }, - "request_id": "req_011CX88X8R2SNXCvHpf8jdxa" - } - headers: - CF-RAY: - - 9be0e0331fe3effa-EWR - Connection: - - keep-alive - Content-Length: - - '130' - Content-Type: - - application/json - Date: - - Wed, 14 Jan 2026 23:22:30 GMT - Server: - - cloudflare - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - request-id: - - req_011CX88X8R2SNXCvHpf8jdxa - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '14' - x-should-retry: - - 'false' - status: - code: 401 - message: Unauthorized -- request: - body: |- - { - "max_tokens": 50, - "messages": [ - { - "role": "user", - "content": "Say hello." - } - ], - "model": "claude-3-5-sonnet-20241022", - "stop_sequences": [ - "STOP" - ], - "temperature": 0.7, - "top_k": 40, - "top_p": 0.9 - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '173' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "invalid_request_error", - "message": "Your credit balance is too low to access the Anthropic API. Please go to Plans & Billing to upgrade or purchase credits." - }, - "request_id": "req_011CX88Zc1kwbPkJkhghetKz" - } - headers: - CF-RAY: - - 9be0e10508204ba5-EWR - Connection: - - keep-alive - Content-Length: - - '234' - Content-Type: - - application/json - Date: - - Wed, 14 Jan 2026 23:23:03 GMT - Server: - - cloudflare - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - request-id: - - req_011CX88Zc1kwbPkJkhghetKz - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '31' - x-should-retry: - - 'false' - status: - code: 400 - message: Bad Request -- request: - body: |- - { - "max_tokens": 50, - "messages": [ - { - "role": "user", - "content": "Say hello." - } - ], - "model": "claude-sonnet-4-20250514", - "stop_sequences": [ - "STOP" - ], - "temperature": 0.7, - "top_k": 40, - "top_p": 0.9 - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '171' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01Nf6xgm48TeELiSicTA83cX", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello! How are you doing today?" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 10, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 11, - "service_tier": "standard" - } - } - headers: - CF-RAY: - - 9be0f5db9b8110f3-EWR - Connection: - - keep-alive - Content-Type: - - application/json - Date: - - Wed, 14 Jan 2026 23:37:19 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '30000' - anthropic-ratelimit-input-tokens-remaining: - - '30000' - anthropic-ratelimit-input-tokens-reset: - - '2026-01-14T23:37:18Z' - anthropic-ratelimit-output-tokens-limit: - - '8000' - anthropic-ratelimit-output-tokens-remaining: - - '8000' - anthropic-ratelimit-output-tokens-reset: - - '2026-01-14T23:37:19Z' - anthropic-ratelimit-requests-limit: - - '50' - anthropic-ratelimit-requests-remaining: - - '49' - anthropic-ratelimit-requests-reset: - - '2026-01-14T23:37:18Z' - anthropic-ratelimit-tokens-limit: - - '38000' - anthropic-ratelimit-tokens-remaining: - - '38000' - anthropic-ratelimit-tokens-reset: - - '2026-01-14T23:37:18Z' - cf-cache-status: - - DYNAMIC - content-length: - - '435' - request-id: - - req_011CX89eXCYZvbfUZDzWQK3e - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1953' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 50, - "messages": [ - { - "role": "user", - "content": "Say hello." - } - ], - "model": "claude-sonnet-4-20250514", - "stop_sequences": [ - "STOP" - ], - "temperature": 0.7, - "top_k": 40, - "top_p": 0.9 - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '171' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_015XXNApQAi4ZgazLmEDHne6", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello! How are you doing today?" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 10, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 11, - "service_tier": "standard" - } - } - headers: - CF-RAY: - - 9be0f7b73af7c269-EWR - Connection: - - keep-alive - Content-Type: - - application/json - Date: - - Wed, 14 Jan 2026 23:38:35 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '30000' - anthropic-ratelimit-input-tokens-remaining: - - '30000' - anthropic-ratelimit-input-tokens-reset: - - '2026-01-14T23:38:35Z' - anthropic-ratelimit-output-tokens-limit: - - '8000' - anthropic-ratelimit-output-tokens-remaining: - - '8000' - anthropic-ratelimit-output-tokens-reset: - - '2026-01-14T23:38:35Z' - anthropic-ratelimit-requests-limit: - - '50' - anthropic-ratelimit-requests-remaining: - - '49' - anthropic-ratelimit-requests-reset: - - '2026-01-14T23:38:34Z' - anthropic-ratelimit-tokens-limit: - - '38000' - anthropic-ratelimit-tokens-remaining: - - '38000' - anthropic-ratelimit-tokens-reset: - - '2026-01-14T23:38:35Z' - cf-cache-status: - - DYNAMIC - content-length: - - '435' - request-id: - - req_011CX89k8aBRkvFFLPZSBSrX - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1955' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 50, - "messages": [ - { - "role": "user", - "content": "Say hello." - } - ], - "model": "claude-sonnet-4-20250514", - "stop_sequences": [ - "STOP" - ], - "temperature": 0.7, - "top_k": 40, - "top_p": 0.9 - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '171' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_016EWkCizXupxVXJna4vtjhm", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello! It's nice to meet you. How are you doing today?" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 10, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 18, - "service_tier": "standard" - } - } - headers: - CF-RAY: - - 9c72cecc5ef2c407-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Sun, 01 Feb 2026 16:26:00 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '30000' - anthropic-ratelimit-input-tokens-remaining: - - '30000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-01T16:25:59Z' - anthropic-ratelimit-output-tokens-limit: - - '8000' - anthropic-ratelimit-output-tokens-remaining: - - '8000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-01T16:26:00Z' - anthropic-ratelimit-requests-limit: - - '50' - anthropic-ratelimit-requests-remaining: - - '49' - anthropic-ratelimit-requests-reset: - - '2026-02-01T16:26:00Z' - anthropic-ratelimit-tokens-limit: - - '38000' - anthropic-ratelimit-tokens-remaining: - - '38000' - anthropic-ratelimit-tokens-reset: - - '2026-02-01T16:25:59Z' - cf-cache-status: - - DYNAMIC - content-length: - - '458' - request-id: - - req_011CXhfKMg9YrSDWDAnNgcwE - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1801' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 50, - "messages": [ - { - "role": "user", - "content": "Say hello." - } - ], - "model": "claude-sonnet-4-20250514", - "stop_sequences": [ - "STOP" - ], - "temperature": 0.7, - "top_k": 40, - "top_p": 0.9 - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '171' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "type": "error", - "error": { - "type": "authentication_error", - "message": "invalid x-api-key" - }, - "request_id": "req_011CXwgSXkEnxQTGaBTxoZSF" - } - headers: - CF-RAY: - - 9cafd2817c630f9b-EWR - Connection: - - keep-alive - Content-Length: - - '130' - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Mon, 09 Feb 2026 02:09:01 GMT - Server: - - cloudflare - X-Robots-Tag: - - none - cf-cache-status: - - DYNAMIC - request-id: - - req_011CXwgSXkEnxQTGaBTxoZSF - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '6' - x-should-retry: - - 'false' - status: - code: 401 - message: Unauthorized -- request: - body: |- - { - "max_tokens": 50, - "messages": [ - { - "role": "user", - "content": "Say hello." - } - ], - "model": "claude-sonnet-4-20250514", - "stop_sequences": [ - "STOP" - ], - "temperature": 0.7, - "top_k": 40, - "top_p": 0.9 - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '171' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_014MYP78mTSiRjcz9ac37em3", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello! It's nice to meet you. How are you doing today?" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 10, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 18, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cafd4455ab8435b-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Mon, 09 Feb 2026 02:10:15 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-09T02:10:15Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-09T02:10:15Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-09T02:10:14Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-09T02:10:15Z' - cf-cache-status: - - DYNAMIC - content-length: - - '490' - request-id: - - req_011CXwgXrqash6KC6buH67mT - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1367' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 50, - "messages": [ - { - "role": "user", - "content": "Say hello." - } - ], - "model": "claude-sonnet-4-20250514", - "stop_sequences": [ - "STOP" - ], - "temperature": 0.7, - "top_k": 40, - "top_p": 0.9 - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '171' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01PtP8Jkm4iforEmomiHjp6n", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello! How are you doing today?" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 10, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 11, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cb07ecebf06acc5-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Mon, 09 Feb 2026 04:06:40 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-09T04:06:40Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-09T04:06:40Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-09T04:06:39Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-09T04:06:40Z' - cf-cache-status: - - DYNAMIC - content-length: - - '467' - request-id: - - req_011CXwqQmXDBUWKj1LHbm3p5 - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1210' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 50, - "messages": [ - { - "role": "user", - "content": "Say hello." - } - ], - "model": "claude-sonnet-4-20250514", - "stop_sequences": [ - "STOP" - ], - "temperature": 0.7, - "top_k": 40, - "top_p": 0.9 - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '171' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_015zydpZjnzzXbjbmDYcPJzE", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello! It's nice to meet you. How are you doing today?" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 10, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 18, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cb889d23c1942fb-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Tue, 10 Feb 2026 03:32:17 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-10T03:32:17Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-10T03:32:17Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-10T03:32:16Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-10T03:32:17Z' - cf-cache-status: - - DYNAMIC - content-length: - - '490' - request-id: - - req_011CXygbdHshaW4LSfGHCw5L - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1102' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 50, - "messages": [ - { - "role": "user", - "content": "Say hello." - } - ], - "model": "claude-sonnet-4-20250514", - "stop_sequences": [ - "STOP" - ], - "temperature": 0.7, - "top_k": 40, - "top_p": 0.9 - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '171' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01BzCQ8orpyan7Ystv5CgnyT", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello! It's nice to meet you. How are you doing today?" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 10, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 18, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cbfd269cf457cb1-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Wed, 11 Feb 2026 00:45:11 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T00:45:10Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T00:45:11Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T00:45:10Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T00:45:10Z' - cf-cache-status: - - DYNAMIC - content-length: - - '490' - request-id: - - req_011CY1MfTb88KBgprh7xpf5B - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1103' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 50, - "messages": [ - { - "role": "user", - "content": "Say hello." - } - ], - "model": "claude-sonnet-4-20250514", - "stop_sequences": [ - "STOP" - ], - "temperature": 0.7, - "top_k": 40, - "top_p": 0.9 - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '171' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_012DY733SL6BQu73vs85NbyT", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello! How are you doing today?" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 10, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 11, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cc0d0ab09cbf569-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Wed, 11 Feb 2026 03:38:46 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T03:38:46Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T03:38:46Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T03:38:44Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T03:38:46Z' - cf-cache-status: - - DYNAMIC - content-length: - - '467' - request-id: - - req_011CY1au95YQ9YSXvsuERw3a - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '2153' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 50, - "messages": [ - { - "role": "user", - "content": "Say hello." - } - ], - "model": "claude-sonnet-4-20250514", - "stop_sequences": [ - "STOP" - ], - "temperature": 0.7, - "top_k": 40, - "top_p": 0.9 - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '171' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01G1eYYnJGCf4h51N85Rm5Nh", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello! It's nice to meet you. How are you doing today?" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 10, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 18, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cc0d54c89c65017-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Wed, 11 Feb 2026 03:41:55 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-11T03:41:55Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-11T03:41:55Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-11T03:41:54Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-11T03:41:55Z' - cf-cache-status: - - DYNAMIC - content-length: - - '490' - request-id: - - req_011CY1b982gjPt4PyVaFsmtT - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1689' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 50, - "messages": [ - { - "role": "user", - "content": "Say hello." - } - ], - "model": "claude-sonnet-4-20250514", - "stop_sequences": [ - "STOP" - ], - "temperature": 0.7, - "top_k": 40, - "top_p": 0.9 - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '171' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01XjNmHT85KYJCsZxYQ2vshk", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello! How are you doing today?" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 10, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 11, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cc8c327d948381d-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Thu, 12 Feb 2026 02:47:38 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-12T02:47:37Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-12T02:47:38Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-12T02:47:37Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-12T02:47:37Z' - cf-cache-status: - - DYNAMIC - content-length: - - '467' - request-id: - - req_011CY3Qown73cxcgWpMdjvwD - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '1111' - status: - code: 200 - message: OK - request: body: |- { @@ -1848,7 +63,7 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_01Ly9k5DaT77qrCaFbJcvXCB", + "id": "msg_01Wx9Fy4Ret8awspBEvuQZsw", "type": "message", "role": "assistant", "content": [ @@ -1874,7 +89,7 @@ interactions: } headers: CF-RAY: - - 9cd82de9e935425d-EWR + - 9cfdb8e6be5142dc-EWR Connection: - keep-alive Content-Security-Policy: @@ -1882,7 +97,7 @@ interactions: Content-Type: - application/json Date: - - Fri, 13 Feb 2026 23:42:05 GMT + - Wed, 18 Feb 2026 13:03:04 GMT Server: - cloudflare Transfer-Encoding: @@ -1894,177 +109,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-13T23:42:04Z' + - '2026-02-18T13:03:03Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-13T23:42:05Z' + - '2026-02-18T13:03:04Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-13T23:41:56Z' + - '2026-02-18T13:03:02Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-13T23:42:04Z' + - '2026-02-18T13:03:03Z' cf-cache-status: - DYNAMIC content-length: - '467' request-id: - - req_011CY6xGYRY18pDRpFzqXtL9 - strict-transport-security: - - max-age=31536000; includeSubDomains; preload - x-envoy-upstream-service-time: - - '8990' - status: - code: 200 - message: OK -- request: - body: |- - { - "max_tokens": 50, - "messages": [ - { - "role": "user", - "content": "Say hello." - } - ], - "model": "claude-sonnet-4-20250514", - "stop_sequences": [ - "STOP" - ], - "temperature": 0.7, - "top_k": 40, - "top_p": 0.9 - } - headers: - accept: - - application/json - accept-encoding: - - gzip, deflate - anthropic-version: - - '2023-06-01' - connection: - - keep-alive - content-length: - - '171' - content-type: - - application/json - host: - - api.anthropic.com - user-agent: - - Anthropic/Python 0.75.0 - x-api-key: - - test_anthropic_api_key - x-stainless-arch: - - arm64 - x-stainless-async: - - 'false' - x-stainless-lang: - - python - x-stainless-os: - - MacOS - x-stainless-package-version: - - 0.75.0 - x-stainless-read-timeout: - - '600' - x-stainless-retry-count: - - '0' - x-stainless-runtime: - - CPython - x-stainless-runtime-version: - - 3.9.6 - x-stainless-timeout: - - '600' - method: POST - uri: https://api.anthropic.com/v1/messages - response: - body: - string: |- - { - "model": "claude-sonnet-4-20250514", - "id": "msg_01TCKet1V1E6SxQECvAymQf7", - "type": "message", - "role": "assistant", - "content": [ - { - "type": "text", - "text": "Hello! It's nice to meet you. How are you doing today?" - } - ], - "stop_reason": "end_turn", - "stop_sequence": null, - "usage": { - "input_tokens": 10, - "cache_creation_input_tokens": 0, - "cache_read_input_tokens": 0, - "cache_creation": { - "ephemeral_5m_input_tokens": 0, - "ephemeral_1h_input_tokens": 0 - }, - "output_tokens": 18, - "service_tier": "standard", - "inference_geo": "not_available" - } - } - headers: - CF-RAY: - - 9cf1c323dd48a0fb-EWR - Connection: - - keep-alive - Content-Security-Policy: - - default-src 'none'; frame-ancestors 'none' - Content-Type: - - application/json - Date: - - Tue, 17 Feb 2026 02:12:54 GMT - Server: - - cloudflare - Transfer-Encoding: - - chunked - X-Robots-Tag: - - none - anthropic-ratelimit-input-tokens-limit: - - '450000' - anthropic-ratelimit-input-tokens-remaining: - - '450000' - anthropic-ratelimit-input-tokens-reset: - - '2026-02-17T02:12:53Z' - anthropic-ratelimit-output-tokens-limit: - - '90000' - anthropic-ratelimit-output-tokens-remaining: - - '90000' - anthropic-ratelimit-output-tokens-reset: - - '2026-02-17T02:12:54Z' - anthropic-ratelimit-requests-limit: - - '1000' - anthropic-ratelimit-requests-remaining: - - '999' - anthropic-ratelimit-requests-reset: - - '2026-02-17T02:12:52Z' - anthropic-ratelimit-tokens-limit: - - '540000' - anthropic-ratelimit-tokens-remaining: - - '540000' - anthropic-ratelimit-tokens-reset: - - '2026-02-17T02:12:53Z' - cf-cache-status: - - DYNAMIC - content-length: - - '490' - request-id: - - req_011CYCqCsGx9mcjm1KGGQZTT + - req_011CYFabMwWPj9q7384nBa8k strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1777' + - '2255' status: code: 200 message: OK From da275d05e9fc0e6b1d4be5e2d0f82f923e7661d6 Mon Sep 17 00:00:00 2001 From: Teja Date: Wed, 18 Feb 2026 22:17:32 -0500 Subject: [PATCH 24/35] Enhance Anthropic instrumentation: update MessageWrapper and StreamWrapper to include content capture logic, improve type safety with explicit casting, and streamline test cases for better clarity. Added new test for streaming response attributes and refined existing tests to ensure consistency in message handling. --- .../instrumentation/anthropic/patch.py | 17 ++- .../instrumentation/anthropic/wrappers.py | 113 +------------- ...st_stream_wrapper_finalize_idempotent.yaml | 28 ++-- .../test_sync_messages_create_api_error.yaml | 10 +- .../test_sync_messages_create_basic.yaml | 18 +-- ...sync_messages_create_captures_content.yaml | 18 +-- ...ages_create_captures_thinking_content.yaml | 26 ++-- ...ages_create_captures_tool_use_content.yaml | 20 +-- ..._create_event_only_no_content_in_span.yaml | 18 +-- ...test_sync_messages_create_stop_reason.yaml | 18 +-- .../test_sync_messages_create_streaming.yaml | 28 ++-- ...ges_create_streaming_captures_content.yaml | 28 ++-- ...treaming_delegates_response_attribute.yaml | 143 ++++++++++++++++++ ...c_messages_create_streaming_iteration.yaml | 35 +++-- ...test_sync_messages_create_token_usage.yaml | 22 +-- ..._sync_messages_create_with_all_params.yaml | 24 +-- .../tests/conftest.py | 41 +++-- .../tests/test_sync_messages.py | 27 +++- 18 files changed, 364 insertions(+), 270 deletions(-) create mode 100644 instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_delegates_response_attribute.yaml diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py index 8e4a0825eb..a4046f2b19 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py @@ -14,7 +14,7 @@ """Patching functions for Anthropic instrumentation.""" -from typing import TYPE_CHECKING, Any, Callable, Union +from typing import TYPE_CHECKING, Any, Callable, Union, cast from opentelemetry.semconv._incubating.attributes import ( gen_ai_attributes as GenAIAttributes, @@ -47,6 +47,7 @@ def messages_create( handler: TelemetryHandler, ) -> Callable[..., Union["Message", "Stream[RawMessageStreamEvent]"]]: """Wrap the `create` method of the `Messages` class to trace it.""" + capture_content = should_capture_content() def traced_method( wrapped: Callable[ @@ -67,7 +68,6 @@ def traced_method( else params.model ) - capture_content = should_capture_content() invocation = LLMInvocation( request_model=request_model, provider=ANTHROPIC, @@ -87,8 +87,12 @@ def traced_method( try: result = wrapped(*args, **kwargs) if is_streaming: - return StreamWrapper(result, handler, invocation) # type: ignore[arg-type] - wrapper = MessageWrapper(result) # type: ignore[arg-type] + stream_result = cast("Stream[RawMessageStreamEvent]", result) + return StreamWrapper( + stream_result, handler, invocation, capture_content + ) + message_result = cast("Message", result) + wrapper = MessageWrapper(message_result, capture_content) wrapper.extract_into(invocation) handler.stop_llm(invocation) return wrapper.message @@ -98,4 +102,7 @@ def traced_method( ) raise - return traced_method # type: ignore[return-value] + return cast( + Callable[..., Union["Message", "Stream[RawMessageStreamEvent]"]], + traced_method, + ) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py index 09efa08ba8..53df438941 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py @@ -14,7 +14,6 @@ from __future__ import annotations -import logging from typing import TYPE_CHECKING, Any, Iterator, Optional from opentelemetry.util.genai.handler import TelemetryHandler @@ -24,7 +23,6 @@ MessagePart, OutputMessage, ) -from opentelemetry.util.genai.utils import should_capture_content from .messages_extractors import ( GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS, @@ -42,20 +40,15 @@ if TYPE_CHECKING: from anthropic._streaming import Stream - from anthropic.lib.streaming import ( - MessageStream, - MessageStreamManager, - ) from anthropic.types import Message, RawMessageStreamEvent -_logger = logging.getLogger(__name__) - class MessageWrapper: """Wrapper for non-streaming Message response that handles telemetry.""" - def __init__(self, message: "Message"): + def __init__(self, message: "Message", capture_content: bool): self._message = message + self._capture_content = capture_content def extract_into(self, invocation: LLMInvocation) -> None: """Extract response data into the invocation.""" @@ -87,7 +80,7 @@ def extract_into(self, invocation: LLMInvocation) -> None: cache_read_input_tokens ) - if should_capture_content(): + if self._capture_content: invocation.output_messages = get_output_messages_from_message( self._message ) @@ -106,6 +99,7 @@ def __init__( stream: "Stream[RawMessageStreamEvent]", handler: TelemetryHandler, invocation: LLMInvocation, + capture_content: bool, ): self._stream = stream self._handler = handler @@ -117,7 +111,7 @@ def __init__( self._output_tokens: Optional[int] = None self._cache_creation_input_tokens: Optional[int] = None self._cache_read_input_tokens: Optional[int] = None - self._capture_content = should_capture_content() + self._capture_content = capture_content self._content_blocks: dict[int, dict[str, Any]] = {} self._finalized = False @@ -211,6 +205,9 @@ def _finalize_invocation(self) -> None: def __iter__(self) -> "StreamWrapper": return self + def __getattr__(self, name: str) -> Any: + return getattr(self._stream, name) + def __next__(self) -> "RawMessageStreamEvent": try: chunk = next(self._stream) @@ -236,97 +233,3 @@ def close(self) -> None: if hasattr(self._stream, "close"): self._stream.close() self._finalize_invocation() - - -class MessageStreamManagerWrapper: - """Wrapper for MessageStreamManager that handles telemetry.""" - - def __init__( - self, - stream_manager: "MessageStreamManager", - handler: TelemetryHandler, - invocation: LLMInvocation, - ): - self._stream_manager = stream_manager - self._handler = handler - self._invocation = invocation - self._message_stream: Optional["MessageStream"] = None - self._finalized = False - - def _finalize_success(self) -> None: - if self._finalized: - return - self._finalized = True - self._handler.stop_llm(self._invocation) - - def _finalize_error(self, exc_type: Any, exc_val: Any) -> None: - if self._finalized: - return - self._finalized = True - self._handler.fail_llm( - self._invocation, - Error( - message=str(exc_val) if exc_val else str(exc_type), - type=exc_type, - ), - ) - - def __enter__(self) -> "MessageStream": - try: - self._message_stream = self._stream_manager.__enter__() - return self._message_stream - except Exception as exc: - self._finalize_error(type(exc), exc) - raise - - def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool: - if self._message_stream is not None and exc_type is None: - self._extract_telemetry_from_stream() - self._finalize_success() - elif exc_type is not None: - self._finalize_error(exc_type, exc_val) - return self._stream_manager.__exit__(exc_type, exc_val, exc_tb) # type: ignore[return-value] - - def _extract_telemetry_from_stream(self) -> None: - if self._message_stream is None: - return - - try: - final_message = self._message_stream.get_final_message() - - if final_message.model: - self._invocation.response_model_name = final_message.model - - if final_message.id: - self._invocation.response_id = final_message.id - - finish_reason = normalize_finish_reason(final_message.stop_reason) - if finish_reason: - self._invocation.finish_reasons = [finish_reason] - - if final_message.usage: - ( - input_tokens, - output_tokens, - cache_creation_input_tokens, - cache_read_input_tokens, - ) = extract_usage_tokens(final_message.usage) - self._invocation.input_tokens = input_tokens - self._invocation.output_tokens = output_tokens - if cache_creation_input_tokens is not None: - self._invocation.attributes[ - GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS - ] = cache_creation_input_tokens - if cache_read_input_tokens is not None: - self._invocation.attributes[ - GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS - ] = cache_read_input_tokens - if should_capture_content(): - self._invocation.output_messages = ( - get_output_messages_from_message(final_message) - ) - except Exception: # pylint: disable=broad-exception-caught - _logger.warning( - "Failed to extract telemetry from Anthropic MessageStream final message.", - exc_info=True, - ) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml index 77701a25ee..2d55fbb787 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml @@ -57,29 +57,29 @@ interactions: body: string: |+ event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01KXozW1kPToWN1CHMiuZ2p7","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01DQJcdDN1W6zgm4BRMykquB","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } event: ping data: {"type": "ping"} event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello."} } event: content_block_stop - data: {"type":"content_block_stop","index":0 } + data: {"type":"content_block_stop","index":0 } event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } event: message_stop - data: {"type":"message_stop" } + data: {"type":"message_stop" } headers: CF-RAY: - - 9cfdb96fcd97ae20-EWR + - 9d028b6bfcb722d7-EWR Cache-Control: - no-cache Connection: @@ -89,7 +89,7 @@ interactions: Content-Type: - text/event-stream; charset=utf-8 Date: - - Wed, 18 Feb 2026 13:03:25 GMT + - Thu, 19 Feb 2026 03:05:49 GMT Server: - cloudflare Transfer-Encoding: @@ -101,33 +101,33 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-18T13:03:24Z' + - '2026-02-19T03:05:48Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-18T13:03:24Z' + - '2026-02-19T03:05:48Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-18T13:03:24Z' + - '2026-02-19T03:05:48Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-18T13:03:24Z' + - '2026-02-19T03:05:48Z' cf-cache-status: - DYNAMIC request-id: - - req_011CYFacyYRKYZEYsdXjb9WU + - req_011CYGgrnyGR6b9uvhZrry1J strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1043' + - '1733' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml index 878f9f07b1..e9fde21c94 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml @@ -61,11 +61,11 @@ interactions: "type": "not_found_error", "message": "model: invalid-model-name" }, - "request_id": "req_011CYFabrqa2YA8WSpkzwYiU" + "request_id": "req_011CYGgqd2T6RpN1QH8eu44p" } headers: CF-RAY: - - 9cfdb9112935e640-EWR + - 9d028b089e27a4c6-EWR Connection: - keep-alive Content-Security-Policy: @@ -73,7 +73,7 @@ interactions: Content-Type: - application/json Date: - - Wed, 18 Feb 2026 13:03:09 GMT + - Thu, 19 Feb 2026 03:05:32 GMT Server: - cloudflare Transfer-Encoding: @@ -85,11 +85,11 @@ interactions: content-length: - '133' request-id: - - req_011CYFabrqa2YA8WSpkzwYiU + - req_011CYGgqd2T6RpN1QH8eu44p strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '53' + - '62' x-should-retry: - 'false' status: diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml index 6b262d29ed..78f4b3ec20 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml @@ -57,7 +57,7 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_01VdhCzYwXoK615zbBaimYhX", + "id": "msg_01DUmi3tbd6g3b2ySCyDftGL", "type": "message", "role": "assistant", "content": [ @@ -83,7 +83,7 @@ interactions: } headers: CF-RAY: - - 9cfdb8d73a447564-EWR + - 9d028ad08ba28456-EWR Connection: - keep-alive Content-Security-Policy: @@ -91,7 +91,7 @@ interactions: Content-Type: - application/json Date: - - Wed, 18 Feb 2026 13:03:00 GMT + - Thu, 19 Feb 2026 03:05:24 GMT Server: - cloudflare Transfer-Encoding: @@ -103,35 +103,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-18T13:03:00Z' + - '2026-02-19T03:05:24Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-18T13:03:00Z' + - '2026-02-19T03:05:24Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-18T13:02:59Z' + - '2026-02-19T03:05:23Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-18T13:03:00Z' + - '2026-02-19T03:05:24Z' cf-cache-status: - DYNAMIC content-length: - '441' request-id: - - req_011CYFabBBrKEaMTgAcq7Kcx + - req_011CYGgpxe8e6VvWmUwKDv8H strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1027' + - '1455' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml index 23aa755c56..e1d62bf913 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml @@ -57,7 +57,7 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_01CnATbLCi3YseMs7jDaaVeG", + "id": "msg_01HGN5SyxyviUtZCzahx9yCm", "type": "message", "role": "assistant", "content": [ @@ -83,7 +83,7 @@ interactions: } headers: CF-RAY: - - 9cfdb8deffb7423d-EWR + - 9d028adac9054322-EWR Connection: - keep-alive Content-Security-Policy: @@ -91,7 +91,7 @@ interactions: Content-Type: - application/json Date: - - Wed, 18 Feb 2026 13:03:02 GMT + - Thu, 19 Feb 2026 03:05:26 GMT Server: - cloudflare Transfer-Encoding: @@ -103,35 +103,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-18T13:03:01Z' + - '2026-02-19T03:05:26Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-18T13:03:01Z' + - '2026-02-19T03:05:26Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-18T13:03:01Z' + - '2026-02-19T03:05:25Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-18T13:03:01Z' + - '2026-02-19T03:05:26Z' cf-cache-status: - DYNAMIC content-length: - '441' request-id: - - req_011CYFabGWKybEHmHfoTW69x + - req_011CYGgq5hHjT7VaBfe9Q1sN strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1111' + - '1208' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml index fe482fbfd5..f04fe133a6 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml @@ -61,18 +61,18 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_01YYhGREUae6du1iWeqioVVG", + "id": "msg_019NDXwtBySEFeG2ZqQSaEo4", "type": "message", "role": "assistant", "content": [ { "type": "thinking", - "thinking": "I need to calculate 17 \u00d7 19.\n\nLet me think about this step by step. I can use the standard multiplication method or look for patterns.\n\nOne way is to use the distributive property:\n17 \u00d7 19 = 17 \u00d7 (20 - 1) = 17 \u00d7 20 - 17 \u00d7 1 = 340 - 17 = 323\n\nOr I could do it the other way:\n17 \u00d7 19 = (20 - 3) \u00d7 19 = 20 \u00d7 19 - 3 \u00d7 19 = 380 - 57 = 323\n\nLet me double-check this with standard multiplication:\n 17\n\u00d7 19\n----\n 153 (17 \u00d7 9)\n170 (17 \u00d7 10)\n----\n323\n\nSo 17 \u00d7 9 = 153\nAnd 17 \u00d7 10 = 170\n153 + 170 = 323\n\nYes, that's correct.", - "signature": "ErwFCkYICxgCKkAIyFnVyRLtMaBCLiVKWlkhL8SYinMf/zEwhjv4st3JDPdO0jm+Ld8SZZA8bnRj4vrqMhms4/iO/HYrfUFHsCa/Egxaf/VZi9E7zirZDZIaDDzYRgMY7t+cvg7EdSIwmvdX+u8Gv+uxcu7oKtHQE9dfrZL66SfsDOSWr8aRrt4CdpvfJEcS5Epb4iKJ8ix6KqMEoWAEhCQpZk7AMB4ITt5fCU96O5XrCEsAydYMdeZMdt+OhCWE6O7CYuidCtEPyd0UmOxiG6ZcSv9mDj2dXe77C4FBTqU8zrtlp8Fvu5RcWdLrjJTujKW8Sqv+lBt5HOPgTmouflucoS884UbR5fknJeOiAyljXYc2OcifNZd/tCgsSd7WaSwWhiKx95VFt3Gwz+cNI5IGB29v7uUo4EGUxmbHHzE3Mk7dOh97vk50ejiW5/2XMlkZ6TBqYaEpCwCtrFpymSTcfYYyWeXGaIXImZCQOUmpcev6gJ1WFI8/8/bP4OYtXXnCyJyfBAgXasOcHUIiGF9ipe6OaPKvYS6A3fqavvZnblqxVf4Y10lurRUieCU5jsnmu+SML0VFrexfqe9i5IdMuCHFRJuhzP++b5Tc+tMK9ndmtwT1SVEULWL27HL7Skg3qn1QphZKn0ZQ/JRMR/Rmkau4LL6PC7Ql7YDBmh1mRRTO0b5sTA1x3LhSQUWjX9Ne1zvuCySOLNiatqeA2aERsob02eyqFNuy6dtzD66EaZq7LzmRjlt5jbycmn1axYCQ1EB4I4l2xEA30kNHUzO04YYvnc17W+Ew8MI2l1lNgVH3NaYq2fiSE+FshKz4nM9Omha6pX72vTT3tbeC9tcbpfEbu1B8T+To0uFzjLsIuzjrhaZC1jkamGBp1fsD6TGS6S9eU6zY3xI7+Dju0JXRhS9U4sq4hWh4oV4/khgB" + "thinking": "I need to calculate 17 * 19.\n\nLet me think about this step by step.\n\n17 * 19\n\nI can use the distributive property or just multiply directly.\n\nMethod 1: Direct multiplication\n17 * 19\n= 17 * (20 - 1)\n= 17 * 20 - 17 * 1\n= 340 - 17\n= 323\n\nMethod 2: Let me double-check with standard multiplication\n 17\n\u00d7 19\n----\n 153 (17 \u00d7 9)\n170 (17 \u00d7 10, shifted one place)\n----\n323\n\nLet me verify the first line: 17 \u00d7 9\n17 \u00d7 9 = 17 \u00d7 (10 - 1) = 170 - 17 = 153 \u2713\n\nAnd the second line: 17 \u00d7 10 = 170 \u2713\n\n153 + 170 = 323 \u2713\n\nSo 17 \u00d7 19 = 323", + "signature": "EsEFCkYICxgCKkAIGZPDOqD0gDVK//TgvXwCDj3ZW3uQ+ktoo+p/HDigcgFke4byRd8xvvl2RakjQcPFkRqyox1bc7+pi5wUjW0FEgw71QuDm1IP1jAIZm4aDO+/Kx+ob0xHevusAiIw28eEOxLg6AZiDjmcHUf9jfwknL0nq3BEJ6A/GKXvGsVSCGlxf3cQih4fSI7izDonKqgEb4GYu6l9uI5Sn3O+LnbOIby3T8iMlsZaOxFIkL6JG4YGXsePNhZqfsUJ8KpWdDrzz86lDW0k5ixQUHtKaTI4E5VzIg8nFsjLXjmXorFbM9LwsEenAns6/Acd1LfOO3hojaa/cLub/zxXmd/ANIj7hTHfl+gOJrXtVglgE1FDjkLFwEsx0brQgJJuGMSimKL+CWrMcGkDrVo0ZycZVGRqztcPBYrmNmsQjZWo/BxoM9WD+8xGTvO1WNq1c5hguwmZhO9v0W7nnNtoyS+62ZCvbsde5bMd237VyRKpDQcqy/3BK5Xo5TTe2NQhF8y15SujYrH2DXz/T+ljPQwetGcpaCxlC/8Mb8ixZh0mWDrx5eG638g/Yj/jBBjjtx/673MDDvYXCsH6FxVp4K2L40WLGdmRpIqc2jfjvIi3mJSpO/x2pYkmkEAd9SG/vVOERDFRwO1455eye8C5f9Zc0X6bhY9Obf/ZELkRSHT6ggzR+gYINGokfLxMWf5hyrVC3TbqPBa6SwIWpLiFGAboCizN3SozuVHRwBWW6bGV2W22IFnFL7OBWA9qr1FPFtIUWfrmm3VcUl9gmVQs9GelsiY3XrgC/hxa3SwKHUOVR0RYrM3zxEMTXNwfwqvI9+7gB6fLmBU80xZGgKoN8tuGMIhLzRb6j2kREK7AIcPprl29qDbX+h6WIr4BU1zlUTgFn4nDdYQhJEW19ky2pcDhi+4ax7SLN680TAC8GAE=" }, { "type": "text", - "text": "I need to calculate 17 \u00d7 19.\n\nLet me use the distributive property to make this easier:\n17 \u00d7 19 = 17 \u00d7 (20 - 1) = 17 \u00d7 20 - 17 \u00d7 1 = 340 - 17 = 323\n\nTo verify: I can also think of it as (20 - 3) \u00d7 19 = 20 \u00d7 19 - 3 \u00d7 19 = 380 - 57 = 323\n\nTherefore, 17 \u00d7 19 = 323." + "text": "I need to calculate 17 \u00d7 19.\n\nLet me break this down:\n17 \u00d7 19 = 17 \u00d7 (20 - 1) = 17 \u00d7 20 - 17 \u00d7 1 = 340 - 17 = 323\n\nOr using standard multiplication:\n```\n 17\n\u00d7 19\n----\n 153 (17 \u00d7 9)\n170 (17 \u00d7 1, in tens place)\n----\n323\n```\n\nTherefore, 17 \u00d7 19 = 323." } ], "stop_reason": "end_turn", @@ -92,7 +92,7 @@ interactions: } headers: CF-RAY: - - 9cfdb94b5cc20cbe-EWR + - 9d028b439be25f83-EWR Connection: - keep-alive Content-Security-Policy: @@ -100,7 +100,7 @@ interactions: Content-Type: - application/json Date: - - Wed, 18 Feb 2026 13:03:23 GMT + - Thu, 19 Feb 2026 03:05:47 GMT Server: - cloudflare Transfer-Encoding: @@ -112,35 +112,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-18T13:03:19Z' + - '2026-02-19T03:05:42Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-18T13:03:24Z' + - '2026-02-19T03:05:48Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-18T13:03:18Z' + - '2026-02-19T03:05:41Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-18T13:03:19Z' + - '2026-02-19T03:05:42Z' cf-cache-status: - DYNAMIC content-length: - - '2258' + - '2278' request-id: - - req_011CYFacYeTZZTq1MwZRjGzo + - req_011CYGgrKNqV8tVpUzrRJ1B8 strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '5637' + - '6263' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml index 0791d96447..fadc99c375 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml @@ -78,13 +78,13 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_01BTv19CzPqf44Mv3vfQtxEW", + "id": "msg_012FAaF3YhTsW9qvrxrF67zh", "type": "message", "role": "assistant", "content": [ { "type": "tool_use", - "id": "toolu_01EUaABXVkdmAGsMCwv76XKm", + "id": "toolu_01DeHniJtv1akvrok8vEy2AP", "name": "get_weather", "input": { "city": "San Francisco" @@ -111,7 +111,7 @@ interactions: } headers: CF-RAY: - - 9cfdb9416a164345-EWR + - 9d028b39aabd5e6b-EWR Connection: - keep-alive Content-Security-Policy: @@ -119,7 +119,7 @@ interactions: Content-Type: - application/json Date: - - Wed, 18 Feb 2026 13:03:18 GMT + - Thu, 19 Feb 2026 03:05:41 GMT Server: - cloudflare Transfer-Encoding: @@ -131,35 +131,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-18T13:03:18Z' + - '2026-02-19T03:05:41Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-18T13:03:18Z' + - '2026-02-19T03:05:41Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-18T13:03:16Z' + - '2026-02-19T03:05:40Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-18T13:03:18Z' + - '2026-02-19T03:05:41Z' cf-cache-status: - DYNAMIC content-length: - '550' request-id: - - req_011CYFacRqga3Xmm6ToDthnG + - req_011CYGgrCbJN2SFVjiNdcR2L strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1444' + - '1386' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml index 3df9807ef4..87b261a944 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml @@ -57,7 +57,7 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_01FgtC8QCmPVu51wiSK2JBx5", + "id": "msg_018Wpmp7P3Hn65X9qJsD2DFr", "type": "message", "role": "assistant", "content": [ @@ -83,7 +83,7 @@ interactions: } headers: CF-RAY: - - 9cfdb978acb072b1-EWR + - 9d028b78d8a6c62c-EWR Connection: - keep-alive Content-Security-Policy: @@ -91,7 +91,7 @@ interactions: Content-Type: - application/json Date: - - Wed, 18 Feb 2026 13:03:26 GMT + - Thu, 19 Feb 2026 03:05:51 GMT Server: - cloudflare Transfer-Encoding: @@ -103,35 +103,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-18T13:03:26Z' + - '2026-02-19T03:05:51Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-18T13:03:26Z' + - '2026-02-19T03:05:51Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-18T13:03:25Z' + - '2026-02-19T03:05:50Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-18T13:03:26Z' + - '2026-02-19T03:05:51Z' cf-cache-status: - DYNAMIC content-length: - '441' request-id: - - req_011CYFad5co5Bv4yah8Qv7i9 + - req_011CYGgrwqpKtnsyaydatP2f strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1222' + - '1057' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml index 4a6bf95b3a..cc69688423 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml @@ -57,7 +57,7 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_01KVUfQS8uK6f1tRbPsQ4ktb", + "id": "msg_01HHi7SZjEcqmPwaVL6iqhgS", "type": "message", "role": "assistant", "content": [ @@ -83,7 +83,7 @@ interactions: } headers: CF-RAY: - - 9cfdb9003a8299cb-EWR + - 9d028af71bccccf1-EWR Connection: - keep-alive Content-Security-Policy: @@ -91,7 +91,7 @@ interactions: Content-Type: - application/json Date: - - Wed, 18 Feb 2026 13:03:07 GMT + - Thu, 19 Feb 2026 03:05:30 GMT Server: - cloudflare Transfer-Encoding: @@ -103,35 +103,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-18T13:03:07Z' + - '2026-02-19T03:05:30Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-18T13:03:07Z' + - '2026-02-19T03:05:30Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-18T13:03:06Z' + - '2026-02-19T03:05:29Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-18T13:03:07Z' + - '2026-02-19T03:05:30Z' cf-cache-status: - DYNAMIC content-length: - '464' request-id: - - req_011CYFabfFJk35kvqvHeTs4L + - req_011CYGgqR6MLvjMPvFrrtq24 strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1323' + - '1374' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml index c79275391a..3a886a957e 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml @@ -57,29 +57,29 @@ interactions: body: string: |+ event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01TWy739zrnMHqPHvW8oMvA4","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}}} + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01X6ELJ64F76umdSX1DVcBVD","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":5,"service_tier":"standard","inference_geo":"not_available"}} } event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } event: ping data: {"type": "ping"} event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } event: content_block_stop - data: {"type":"content_block_stop","index":0 } + data: {"type":"content_block_stop","index":0 } event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } event: message_stop - data: {"type":"message_stop" } + data: {"type":"message_stop" } headers: CF-RAY: - - 9cfdb912ab2b8e3e-EWR + - 9d028b09eb3a729c-EWR Cache-Control: - no-cache Connection: @@ -89,7 +89,7 @@ interactions: Content-Type: - text/event-stream; charset=utf-8 Date: - - Wed, 18 Feb 2026 13:03:10 GMT + - Thu, 19 Feb 2026 03:05:33 GMT Server: - cloudflare Transfer-Encoding: @@ -101,33 +101,33 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-18T13:03:09Z' + - '2026-02-19T03:05:32Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-18T13:03:09Z' + - '2026-02-19T03:05:32Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-18T13:03:09Z' + - '2026-02-19T03:05:32Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-18T13:03:09Z' + - '2026-02-19T03:05:32Z' cf-cache-status: - DYNAMIC request-id: - - req_011CYFabssKz9uZDCAgktax9 + - req_011CYGgqdvXWP1xPyJZqEoWt strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1060' + - '1103' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml index cffe35684e..f2311cc01e 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml @@ -57,29 +57,29 @@ interactions: body: string: |+ event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01PTnvySwm1bNVqeGkMTGk8Q","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01VfhzAPn1QG4ioXQ1z1mgk2","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } event: ping data: {"type": "ping"} event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello."} } event: content_block_stop - data: {"type":"content_block_stop","index":0 } + data: {"type":"content_block_stop","index":0} event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } event: message_stop - data: {"type":"message_stop" } + data: {"type":"message_stop"} headers: CF-RAY: - - 9cfdb91afa64985c-EWR + - 9d028b127e3be563-EWR Cache-Control: - no-cache Connection: @@ -89,7 +89,7 @@ interactions: Content-Type: - text/event-stream; charset=utf-8 Date: - - Wed, 18 Feb 2026 13:03:12 GMT + - Thu, 19 Feb 2026 03:05:35 GMT Server: - cloudflare Transfer-Encoding: @@ -101,33 +101,33 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-18T13:03:11Z' + - '2026-02-19T03:05:33Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-18T13:03:11Z' + - '2026-02-19T03:05:33Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-18T13:03:11Z' + - '2026-02-19T03:05:34Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-18T13:03:11Z' + - '2026-02-19T03:05:33Z' cf-cache-status: - DYNAMIC request-id: - - req_011CYFabyc7Ne8XxYdhuD7yh + - req_011CYGgqjkmHf8Jym2C64R1C strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '2127' + - '1578' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_delegates_response_attribute.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_delegates_response_attribute.yaml new file mode 100644 index 0000000000..c38a3e1b7f --- /dev/null +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_delegates_response_attribute.yaml @@ -0,0 +1,143 @@ +interactions: +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hi." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '116' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01K8QbSPahDZjJJ7Jssa138s","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"! How"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" you doing today?"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11}} + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9d028b278cfa0d33-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Thu, 19 Feb 2026 03:05:38 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-19T03:05:37Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-19T03:05:37Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-19T03:05:37Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-19T03:05:37Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CYGgqzCvG9T57j3mhgid9 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1193' + status: + code: 200 + message: OK +version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml index da620f74fc..2d0e637020 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml @@ -57,35 +57,38 @@ interactions: body: string: |+ event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01V9EcqsWc8Bq8gjKW52VtG3","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01BpCo1wgx38EMetyqUHbKU4","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } event: ping data: {"type": "ping"} event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" there! How"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"! How"}} event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are you doing today?"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" you doing today?"} } event: content_block_stop - data: {"type":"content_block_stop","index":0 } + data: {"type":"content_block_stop","index":0 } event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":12} } + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } event: message_stop - data: {"type":"message_stop" } + data: {"type":"message_stop" } headers: CF-RAY: - - 9cfdb92e0d7e99cb-EWR + - 9d028b1dedaa8c5d-EWR Cache-Control: - no-cache Connection: @@ -95,7 +98,7 @@ interactions: Content-Type: - text/event-stream; charset=utf-8 Date: - - Wed, 18 Feb 2026 13:03:14 GMT + - Thu, 19 Feb 2026 03:05:36 GMT Server: - cloudflare Transfer-Encoding: @@ -107,33 +110,33 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-18T13:03:13Z' + - '2026-02-19T03:05:35Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-18T13:03:13Z' + - '2026-02-19T03:05:35Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-18T13:03:13Z' + - '2026-02-19T03:05:35Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-18T13:03:13Z' + - '2026-02-19T03:05:35Z' cf-cache-status: - DYNAMIC request-id: - - req_011CYFacCeBsLuF97ndtCKfn + - req_011CYGgqsb4LTyo7gqt7x1BX strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1144' + - '1115' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml index fefcfc5cb1..31d7708f2c 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml @@ -57,13 +57,13 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_01GApBhZsKAd9ydf4bAuJQtG", + "id": "msg_01K2eUCtTz3m34b16Fj2PRLL", "type": "message", "role": "assistant", "content": [ { "type": "text", - "text": "1\n2\n3\n4\n5" + "text": "1, 2, 3, 4, 5" } ], "stop_reason": "end_turn", @@ -76,14 +76,14 @@ interactions: "ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0 }, - "output_tokens": 13, + "output_tokens": 17, "service_tier": "standard", "inference_geo": "not_available" } } headers: CF-RAY: - - 9cfdb8f5f8461768-EWR + - 9d028aed89256e53-EWR Connection: - keep-alive Content-Security-Policy: @@ -91,7 +91,7 @@ interactions: Content-Type: - application/json Date: - - Wed, 18 Feb 2026 13:03:06 GMT + - Thu, 19 Feb 2026 03:05:29 GMT Server: - cloudflare Transfer-Encoding: @@ -103,35 +103,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-18T13:03:05Z' + - '2026-02-19T03:05:29Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-18T13:03:06Z' + - '2026-02-19T03:05:29Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-18T13:03:04Z' + - '2026-02-19T03:05:28Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-18T13:03:05Z' + - '2026-02-19T03:05:29Z' cf-cache-status: - DYNAMIC content-length: - '449' request-id: - - req_011CYFabYE8rYYWg3TYBoDAo + - req_011CYGgqJXDj6uzUxcHZccee strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1466' + - '1370' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml index 3ca1e69cd7..a5f8a1f1bf 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml @@ -63,13 +63,13 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_01Wx9Fy4Ret8awspBEvuQZsw", + "id": "msg_01FiTVJCpPge2YniT4JqyGyh", "type": "message", "role": "assistant", "content": [ { "type": "text", - "text": "Hello! How are you doing today?" + "text": "Hello! It's nice to meet you. How are you doing today?" } ], "stop_reason": "end_turn", @@ -82,14 +82,14 @@ interactions: "ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0 }, - "output_tokens": 11, + "output_tokens": 18, "service_tier": "standard", "inference_geo": "not_available" } } headers: CF-RAY: - - 9cfdb8e6be5142dc-EWR + - 9d028ae39c1f422b-EWR Connection: - keep-alive Content-Security-Policy: @@ -97,7 +97,7 @@ interactions: Content-Type: - application/json Date: - - Wed, 18 Feb 2026 13:03:04 GMT + - Thu, 19 Feb 2026 03:05:27 GMT Server: - cloudflare Transfer-Encoding: @@ -109,35 +109,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-18T13:03:03Z' + - '2026-02-19T03:05:27Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-18T13:03:04Z' + - '2026-02-19T03:05:27Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-18T13:03:02Z' + - '2026-02-19T03:05:26Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-18T13:03:03Z' + - '2026-02-19T03:05:27Z' cf-cache-status: - DYNAMIC content-length: - - '467' + - '490' request-id: - - req_011CYFabMwWPj9q7384nBa8k + - req_011CYGgqBhCi2fdTMjzUaVCr strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '2255' + - '1446' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/conftest.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/conftest.py index 3e7a087d0b..c9573d8251 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/conftest.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/conftest.py @@ -135,10 +135,15 @@ def instrument_no_content(tracer_provider, logger_provider, meter_provider): meter_provider=meter_provider, ) - yield instrumentor - os.environ.pop(OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT, None) - os.environ.pop(OTEL_SEMCONV_STABILITY_OPT_IN, None) - instrumentor.uninstrument() + try: + yield instrumentor + finally: + os.environ.pop( + OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT, None + ) + os.environ.pop(OTEL_SEMCONV_STABILITY_OPT_IN, None) + instrumentor.uninstrument() + _OpenTelemetrySemanticConventionStability._initialized = False @pytest.fixture(scope="function") @@ -158,10 +163,15 @@ def instrument_with_content(tracer_provider, logger_provider, meter_provider): meter_provider=meter_provider, ) - yield instrumentor - os.environ.pop(OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT, None) - os.environ.pop(OTEL_SEMCONV_STABILITY_OPT_IN, None) - instrumentor.uninstrument() + try: + yield instrumentor + finally: + os.environ.pop( + OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT, None + ) + os.environ.pop(OTEL_SEMCONV_STABILITY_OPT_IN, None) + instrumentor.uninstrument() + _OpenTelemetrySemanticConventionStability._initialized = False @pytest.fixture(scope="function") @@ -182,11 +192,16 @@ def instrument_event_only(tracer_provider, logger_provider, meter_provider): meter_provider=meter_provider, ) - yield instrumentor - os.environ.pop(OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT, None) - os.environ.pop(OTEL_SEMCONV_STABILITY_OPT_IN, None) - os.environ.pop(OTEL_INSTRUMENTATION_GENAI_EMIT_EVENT, None) - instrumentor.uninstrument() + try: + yield instrumentor + finally: + os.environ.pop( + OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT, None + ) + os.environ.pop(OTEL_SEMCONV_STABILITY_OPT_IN, None) + os.environ.pop(OTEL_INSTRUMENTATION_GENAI_EMIT_EVENT, None) + instrumentor.uninstrument() + _OpenTelemetrySemanticConventionStability._initialized = False @pytest.fixture diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py index eda6956b19..ea61f30073 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py @@ -510,6 +510,27 @@ def test_sync_messages_create_streaming_iteration( assert GenAIAttributes.GEN_AI_RESPONSE_MODEL in span.attributes +@pytest.mark.vcr() +def test_sync_messages_create_streaming_delegates_response_attribute( + request, anthropic_client, instrument_no_content +): + """Stream wrapper should expose attributes from the wrapped stream.""" + _skip_if_cassette_missing_and_no_real_key(request) + + stream = anthropic_client.messages.create( + model="claude-sonnet-4-20250514", + max_tokens=100, + messages=[{"role": "user", "content": "Say hi."}], + stream=True, + ) + + # `response` exists on Anthropic Stream and should be reachable on wrapper. + assert stream.response is not None + assert stream.response.status_code == 200 + assert stream.response.headers.get("request-id") is not None + stream.close() + + def test_sync_messages_create_streaming_connection_error( span_exporter, instrument_no_content ): @@ -696,7 +717,7 @@ def test_message_wrapper_aggregates_cache_tokens(): provider="anthropic", ) - MessageWrapper(message).extract_into(invocation) # type: ignore[arg-type] + MessageWrapper(message, capture_content=False).extract_into(invocation) # type: ignore[arg-type] assert invocation.input_tokens == 20 assert invocation.output_tokens == 5 @@ -762,7 +783,9 @@ def close(self): # pylint: disable=no-self-use request_model="claude-sonnet-4-20250514", provider="anthropic", ) - wrapper = StreamWrapper(FakeStream(), FakeHandler(), invocation) # type: ignore[arg-type] + wrapper = StreamWrapper( # type: ignore[arg-type] + FakeStream(), FakeHandler(), invocation, capture_content=False + ) list(wrapper) assert invocation.input_tokens == 17 From 2c2a7809c05ad4d7ecec2271850da77c109bbc09 Mon Sep 17 00:00:00 2001 From: Teja Date: Wed, 18 Feb 2026 22:19:13 -0500 Subject: [PATCH 25/35] Update test cassettes for Anthropic instrumentation: modify message IDs, timestamps, and token usage across various test cases. Refine content capture logic and ensure consistency in message formats, including adjustments to event data and headers for improved clarity and accuracy. --- ...st_stream_wrapper_finalize_idempotent.yaml | 26 +++++++------- .../test_sync_messages_create_api_error.yaml | 10 +++--- .../test_sync_messages_create_basic.yaml | 20 +++++------ ...sync_messages_create_captures_content.yaml | 18 +++++----- ...ages_create_captures_thinking_content.yaml | 28 +++++++-------- ...ages_create_captures_tool_use_content.yaml | 20 +++++------ ..._create_event_only_no_content_in_span.yaml | 18 +++++----- ...test_sync_messages_create_stop_reason.yaml | 18 +++++----- .../test_sync_messages_create_streaming.yaml | 26 +++++++------- ...ges_create_streaming_captures_content.yaml | 26 +++++++------- ...treaming_delegates_response_attribute.yaml | 32 ++++++++--------- ...c_messages_create_streaming_iteration.yaml | 34 +++++++++---------- ...test_sync_messages_create_token_usage.yaml | 18 +++++----- ..._sync_messages_create_with_all_params.yaml | 24 ++++++------- 14 files changed, 159 insertions(+), 159 deletions(-) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml index 2d55fbb787..c1e0c24c69 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml @@ -57,29 +57,29 @@ interactions: body: string: |+ event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01DQJcdDN1W6zgm4BRMykquB","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01LviXx3SM9CFsB8qWtzz5eA","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}}} event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } event: ping data: {"type": "ping"} event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello."} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } event: content_block_stop data: {"type":"content_block_stop","index":0 } event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } event: message_stop - data: {"type":"message_stop" } + data: {"type":"message_stop" } headers: CF-RAY: - - 9d028b6bfcb722d7-EWR + - 9d029e4f4aa45e72-EWR Cache-Control: - no-cache Connection: @@ -89,7 +89,7 @@ interactions: Content-Type: - text/event-stream; charset=utf-8 Date: - - Thu, 19 Feb 2026 03:05:49 GMT + - Thu, 19 Feb 2026 03:18:42 GMT Server: - cloudflare Transfer-Encoding: @@ -101,33 +101,33 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-19T03:05:48Z' + - '2026-02-19T03:18:41Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-19T03:05:48Z' + - '2026-02-19T03:18:41Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-19T03:05:48Z' + - '2026-02-19T03:18:41Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-19T03:05:48Z' + - '2026-02-19T03:18:41Z' cf-cache-status: - DYNAMIC request-id: - - req_011CYGgrnyGR6b9uvhZrry1J + - req_011CYGhqpgJFAfFHU4h8WWSE strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1733' + - '902' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml index e9fde21c94..7d65b589c7 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml @@ -61,11 +61,11 @@ interactions: "type": "not_found_error", "message": "model: invalid-model-name" }, - "request_id": "req_011CYGgqd2T6RpN1QH8eu44p" + "request_id": "req_011CYGhpks5P7XxEveVNKVG1" } headers: CF-RAY: - - 9d028b089e27a4c6-EWR + - 9d029df4edc1dcf2-EWR Connection: - keep-alive Content-Security-Policy: @@ -73,7 +73,7 @@ interactions: Content-Type: - application/json Date: - - Thu, 19 Feb 2026 03:05:32 GMT + - Thu, 19 Feb 2026 03:18:27 GMT Server: - cloudflare Transfer-Encoding: @@ -85,11 +85,11 @@ interactions: content-length: - '133' request-id: - - req_011CYGgqd2T6RpN1QH8eu44p + - req_011CYGhpks5P7XxEveVNKVG1 strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '62' + - '55' x-should-retry: - 'false' status: diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml index 78f4b3ec20..0dbfd2bbc2 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml @@ -57,13 +57,13 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_01DUmi3tbd6g3b2ySCyDftGL", + "id": "msg_011kM6moFzh9EE6Ka7oczinb", "type": "message", "role": "assistant", "content": [ { "type": "text", - "text": "Hello!" + "text": "Hello." } ], "stop_reason": "end_turn", @@ -83,7 +83,7 @@ interactions: } headers: CF-RAY: - - 9d028ad08ba28456-EWR + - 9d029dbefaa9566e-EWR Connection: - keep-alive Content-Security-Policy: @@ -91,7 +91,7 @@ interactions: Content-Type: - application/json Date: - - Thu, 19 Feb 2026 03:05:24 GMT + - Thu, 19 Feb 2026 03:18:19 GMT Server: - cloudflare Transfer-Encoding: @@ -103,35 +103,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-19T03:05:24Z' + - '2026-02-19T03:18:19Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-19T03:05:24Z' + - '2026-02-19T03:18:19Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-19T03:05:23Z' + - '2026-02-19T03:18:18Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-19T03:05:24Z' + - '2026-02-19T03:18:19Z' cf-cache-status: - DYNAMIC content-length: - '441' request-id: - - req_011CYGgpxe8e6VvWmUwKDv8H + - req_011CYGhp7xZSRVffb9XH2iUi strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1455' + - '1124' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml index e1d62bf913..b2da7f57b8 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml @@ -57,7 +57,7 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_01HGN5SyxyviUtZCzahx9yCm", + "id": "msg_01EVg89cSWpjbbXZS6r1xNVD", "type": "message", "role": "assistant", "content": [ @@ -83,7 +83,7 @@ interactions: } headers: CF-RAY: - - 9d028adac9054322-EWR + - 9d029dc7188d7ce8-EWR Connection: - keep-alive Content-Security-Policy: @@ -91,7 +91,7 @@ interactions: Content-Type: - application/json Date: - - Thu, 19 Feb 2026 03:05:26 GMT + - Thu, 19 Feb 2026 03:18:21 GMT Server: - cloudflare Transfer-Encoding: @@ -103,35 +103,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-19T03:05:26Z' + - '2026-02-19T03:18:21Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-19T03:05:26Z' + - '2026-02-19T03:18:21Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-19T03:05:25Z' + - '2026-02-19T03:18:20Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-19T03:05:26Z' + - '2026-02-19T03:18:21Z' cf-cache-status: - DYNAMIC content-length: - '441' request-id: - - req_011CYGgq5hHjT7VaBfe9Q1sN + - req_011CYGhpDXfu53sCJs3Jj8uH strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1208' + - '1514' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml index f04fe133a6..81071ebe65 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml @@ -61,18 +61,18 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_019NDXwtBySEFeG2ZqQSaEo4", + "id": "msg_019M6D1Hc9WSFVbi5UhXvxm5", "type": "message", "role": "assistant", "content": [ { "type": "thinking", - "thinking": "I need to calculate 17 * 19.\n\nLet me think about this step by step.\n\n17 * 19\n\nI can use the distributive property or just multiply directly.\n\nMethod 1: Direct multiplication\n17 * 19\n= 17 * (20 - 1)\n= 17 * 20 - 17 * 1\n= 340 - 17\n= 323\n\nMethod 2: Let me double-check with standard multiplication\n 17\n\u00d7 19\n----\n 153 (17 \u00d7 9)\n170 (17 \u00d7 10, shifted one place)\n----\n323\n\nLet me verify the first line: 17 \u00d7 9\n17 \u00d7 9 = 17 \u00d7 (10 - 1) = 170 - 17 = 153 \u2713\n\nAnd the second line: 17 \u00d7 10 = 170 \u2713\n\n153 + 170 = 323 \u2713\n\nSo 17 \u00d7 19 = 323", - "signature": "EsEFCkYICxgCKkAIGZPDOqD0gDVK//TgvXwCDj3ZW3uQ+ktoo+p/HDigcgFke4byRd8xvvl2RakjQcPFkRqyox1bc7+pi5wUjW0FEgw71QuDm1IP1jAIZm4aDO+/Kx+ob0xHevusAiIw28eEOxLg6AZiDjmcHUf9jfwknL0nq3BEJ6A/GKXvGsVSCGlxf3cQih4fSI7izDonKqgEb4GYu6l9uI5Sn3O+LnbOIby3T8iMlsZaOxFIkL6JG4YGXsePNhZqfsUJ8KpWdDrzz86lDW0k5ixQUHtKaTI4E5VzIg8nFsjLXjmXorFbM9LwsEenAns6/Acd1LfOO3hojaa/cLub/zxXmd/ANIj7hTHfl+gOJrXtVglgE1FDjkLFwEsx0brQgJJuGMSimKL+CWrMcGkDrVo0ZycZVGRqztcPBYrmNmsQjZWo/BxoM9WD+8xGTvO1WNq1c5hguwmZhO9v0W7nnNtoyS+62ZCvbsde5bMd237VyRKpDQcqy/3BK5Xo5TTe2NQhF8y15SujYrH2DXz/T+ljPQwetGcpaCxlC/8Mb8ixZh0mWDrx5eG638g/Yj/jBBjjtx/673MDDvYXCsH6FxVp4K2L40WLGdmRpIqc2jfjvIi3mJSpO/x2pYkmkEAd9SG/vVOERDFRwO1455eye8C5f9Zc0X6bhY9Obf/ZELkRSHT6ggzR+gYINGokfLxMWf5hyrVC3TbqPBa6SwIWpLiFGAboCizN3SozuVHRwBWW6bGV2W22IFnFL7OBWA9qr1FPFtIUWfrmm3VcUl9gmVQs9GelsiY3XrgC/hxa3SwKHUOVR0RYrM3zxEMTXNwfwqvI9+7gB6fLmBU80xZGgKoN8tuGMIhLzRb6j2kREK7AIcPprl29qDbX+h6WIr4BU1zlUTgFn4nDdYQhJEW19ky2pcDhi+4ax7SLN680TAC8GAE=" + "thinking": "I need to calculate 17 * 19.\n\nLet me think about this step by step.\n\nOne way is to use the standard multiplication:\n17 * 19\n\nI can break this down:\n17 * 19 = 17 * (20 - 1) = 17 * 20 - 17 * 1 = 340 - 17 = 323\n\nLet me double-check this:\n17 * 20 = 340\n17 * 1 = 17\n340 - 17 = 323\n\nAlternatively, I could do:\n19 * 17 = 19 * (10 + 7) = 19 * 10 + 19 * 7 = 190 + 133\n\nLet me calculate 19 * 7:\n19 * 7 = (20 - 1) * 7 = 20 * 7 - 1 * 7 = 140 - 7 = 133\n\nSo: 190 + 133 = 323\n\nBoth methods give me 323, so that should be correct.", + "signature": "EqsFCkYICxgCKkBj3TzwlCMb5oc6IOfRK12T1/x6oRw0jcUAh73ytRZYa+FS2kbF2ww9xPCMT6UA6mo3mNluiotjDwd7ox2CQaYpEgzfGNJ622dnd9Zao78aDEvJnPgVLG3DbVZAZiIwHtc5Bi2WdxoOJlbdbxACS6DJC/wETtNVKh6+YelaZbyB5yAbq0DOX0OWLr1QL1lRKpIEb7XRfskfTALZimvJMVmxn5zFcVdGM42FoiBAUvDdugak6qgRw2l7Ur4v+6y/PHt65MrlSGz72eHCbaPJI5gXoArNOdEOBKbHkIVYrqUF+KuGtNXSS9N0+LuntqiLXO985/aA4lRpo48DAYxUIDMpjun2VPVs0U5opP4hpyhPKy+jVx0ua0bihuAQtESjacRVSXuUPa839Y7qx+uvzyCW5dXym5HiEvX5edcWSxGukLJNXpxWv1KP89PCCXvlQkSRLlGblBLVhvlW2lbKftPEN1pnlQ7ZI+kh+F9t41SUm6MQ2vyb0v9Blbs5bujDs1ivNqUldx/TNLFwQbCMVZ9fBxXO2YbmOKOkRvdaw1W5p32tRfFHSldg8Toj5wi4MWtCcSBCFq5SploMAPLS5tUyQXMCVmEye77ltNi86d0ezBTm8Xebuo1VPdJVWMMHKI0iYch6SgBbR31HA2/hO8A/BWnHryDUYb34zu8A31Zp6igaxtoCKniLTFyBIJbeJD4qf+yVrFRfdUblQu8p1dpdlY/MOnR1EVOqWj8jyiYwTtqQBqaA1bjgNCWR+dTBrolFh5n5ZGDVaZrAJo/dmhYqVBlZ3STsvm+pBf3MCw761Z0BCy5h6YkEA87PbA3yi0QxEQCoOtjgyX/cBw0K2Aillhtbq1SSEOV0CCtrwUSw6ENf/eCSqkNcWR4Q9zT7kZ1YGxUYAQ==" }, { "type": "text", - "text": "I need to calculate 17 \u00d7 19.\n\nLet me break this down:\n17 \u00d7 19 = 17 \u00d7 (20 - 1) = 17 \u00d7 20 - 17 \u00d7 1 = 340 - 17 = 323\n\nOr using standard multiplication:\n```\n 17\n\u00d7 19\n----\n 153 (17 \u00d7 9)\n170 (17 \u00d7 1, in tens place)\n----\n323\n```\n\nTherefore, 17 \u00d7 19 = 323." + "text": "I need to calculate 17 \u00d7 19.\n\nLet me use the distributive property to make this easier:\n17 \u00d7 19 = 17 \u00d7 (20 - 1) = 17 \u00d7 20 - 17 \u00d7 1\n\n17 \u00d7 20 = 340\n17 \u00d7 1 = 17\n\nSo: 340 - 17 = 323\n\nTherefore, 17 \u00d7 19 = 323." } ], "stop_reason": "end_turn", @@ -85,14 +85,14 @@ interactions: "ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0 }, - "output_tokens": 376, + "output_tokens": 378, "service_tier": "standard", "inference_geo": "not_available" } } headers: CF-RAY: - - 9d028b439be25f83-EWR + - 9d029e2d5f104337-EWR Connection: - keep-alive Content-Security-Policy: @@ -100,7 +100,7 @@ interactions: Content-Type: - application/json Date: - - Thu, 19 Feb 2026 03:05:47 GMT + - Thu, 19 Feb 2026 03:18:41 GMT Server: - cloudflare Transfer-Encoding: @@ -112,35 +112,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-19T03:05:42Z' + - '2026-02-19T03:18:37Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-19T03:05:48Z' + - '2026-02-19T03:18:41Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-19T03:05:41Z' + - '2026-02-19T03:18:36Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-19T03:05:42Z' + - '2026-02-19T03:18:37Z' cf-cache-status: - DYNAMIC content-length: - - '2278' + - '2165' request-id: - - req_011CYGgrKNqV8tVpUzrRJ1B8 + - req_011CYGhqRT49PCBrV4e9s65s strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '6263' + - '5185' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml index fadc99c375..04ee4860f6 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml @@ -78,13 +78,13 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_012FAaF3YhTsW9qvrxrF67zh", + "id": "msg_01BbgL8QuxD4kEF5UNmv3tQQ", "type": "message", "role": "assistant", "content": [ { "type": "tool_use", - "id": "toolu_01DeHniJtv1akvrok8vEy2AP", + "id": "toolu_012aj769msPHQ9EULAXN6d4z", "name": "get_weather", "input": { "city": "San Francisco" @@ -111,7 +111,7 @@ interactions: } headers: CF-RAY: - - 9d028b39aabd5e6b-EWR + - 9d029e22de730cb2-EWR Connection: - keep-alive Content-Security-Policy: @@ -119,7 +119,7 @@ interactions: Content-Type: - application/json Date: - - Thu, 19 Feb 2026 03:05:41 GMT + - Thu, 19 Feb 2026 03:18:36 GMT Server: - cloudflare Transfer-Encoding: @@ -131,35 +131,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-19T03:05:41Z' + - '2026-02-19T03:18:36Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-19T03:05:41Z' + - '2026-02-19T03:18:36Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-19T03:05:40Z' + - '2026-02-19T03:18:34Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-19T03:05:41Z' + - '2026-02-19T03:18:36Z' cf-cache-status: - DYNAMIC content-length: - '550' request-id: - - req_011CYGgrCbJN2SFVjiNdcR2L + - req_011CYGhqJJSMHstMWe9qB2hE strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1386' + - '1511' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml index 87b261a944..6e4b730c7e 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml @@ -57,7 +57,7 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_018Wpmp7P3Hn65X9qJsD2DFr", + "id": "msg_01VRcbGg6sG2yDjYRqx3a9qb", "type": "message", "role": "assistant", "content": [ @@ -83,7 +83,7 @@ interactions: } headers: CF-RAY: - - 9d028b78d8a6c62c-EWR + - 9d029e56d8310e82-EWR Connection: - keep-alive Content-Security-Policy: @@ -91,7 +91,7 @@ interactions: Content-Type: - application/json Date: - - Thu, 19 Feb 2026 03:05:51 GMT + - Thu, 19 Feb 2026 03:18:44 GMT Server: - cloudflare Transfer-Encoding: @@ -103,35 +103,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-19T03:05:51Z' + - '2026-02-19T03:18:44Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-19T03:05:51Z' + - '2026-02-19T03:18:44Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-19T03:05:50Z' + - '2026-02-19T03:18:43Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-19T03:05:51Z' + - '2026-02-19T03:18:44Z' cf-cache-status: - DYNAMIC content-length: - '441' request-id: - - req_011CYGgrwqpKtnsyaydatP2f + - req_011CYGhqurMQzX7ZdQY5zit6 strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1057' + - '1456' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml index cc69688423..e1854639df 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml @@ -57,7 +57,7 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_01HHi7SZjEcqmPwaVL6iqhgS", + "id": "msg_012NCVGZiy8NSkEv21ZvbeqM", "type": "message", "role": "assistant", "content": [ @@ -83,7 +83,7 @@ interactions: } headers: CF-RAY: - - 9d028af71bccccf1-EWR + - 9d029de2fb8041e9-EWR Connection: - keep-alive Content-Security-Policy: @@ -91,7 +91,7 @@ interactions: Content-Type: - application/json Date: - - Thu, 19 Feb 2026 03:05:30 GMT + - Thu, 19 Feb 2026 03:18:25 GMT Server: - cloudflare Transfer-Encoding: @@ -103,35 +103,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-19T03:05:30Z' + - '2026-02-19T03:18:25Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-19T03:05:30Z' + - '2026-02-19T03:18:25Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-19T03:05:29Z' + - '2026-02-19T03:18:24Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-19T03:05:30Z' + - '2026-02-19T03:18:25Z' cf-cache-status: - DYNAMIC content-length: - '464' request-id: - - req_011CYGgqR6MLvjMPvFrrtq24 + - req_011CYGhpYaPsv6SGrGNRBWpP strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1374' + - '1245' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml index 3a886a957e..59d7614a83 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml @@ -57,29 +57,29 @@ interactions: body: string: |+ event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01X6ELJ64F76umdSX1DVcBVD","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":5,"service_tier":"standard","inference_geo":"not_available"}} } + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_013BkEEt2ex79CpGTK17p2nv","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } event: ping data: {"type": "ping"} event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } event: content_block_stop data: {"type":"content_block_stop","index":0 } event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } event: message_stop - data: {"type":"message_stop" } + data: {"type":"message_stop" } headers: CF-RAY: - - 9d028b09eb3a729c-EWR + - 9d029df659ec269c-EWR Cache-Control: - no-cache Connection: @@ -89,7 +89,7 @@ interactions: Content-Type: - text/event-stream; charset=utf-8 Date: - - Thu, 19 Feb 2026 03:05:33 GMT + - Thu, 19 Feb 2026 03:18:28 GMT Server: - cloudflare Transfer-Encoding: @@ -101,33 +101,33 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-19T03:05:32Z' + - '2026-02-19T03:18:27Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-19T03:05:32Z' + - '2026-02-19T03:18:27Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-19T03:05:32Z' + - '2026-02-19T03:18:27Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-19T03:05:32Z' + - '2026-02-19T03:18:27Z' cf-cache-status: - DYNAMIC request-id: - - req_011CYGgqdvXWP1xPyJZqEoWt + - req_011CYGhpmqNWeuQCcAER3zK6 strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1103' + - '1239' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml index f2311cc01e..5ae71005fd 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml @@ -57,29 +57,29 @@ interactions: body: string: |+ event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01VfhzAPn1QG4ioXQ1z1mgk2","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01JM82ym7YEkpf9EYa75JDSg","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } event: ping data: {"type": "ping"} event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello."} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello."} } event: content_block_stop data: {"type":"content_block_stop","index":0} event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } event: message_stop - data: {"type":"message_stop"} + data: {"type":"message_stop" } headers: CF-RAY: - - 9d028b127e3be563-EWR + - 9d029e000af99f3b-EWR Cache-Control: - no-cache Connection: @@ -89,7 +89,7 @@ interactions: Content-Type: - text/event-stream; charset=utf-8 Date: - - Thu, 19 Feb 2026 03:05:35 GMT + - Thu, 19 Feb 2026 03:18:30 GMT Server: - cloudflare Transfer-Encoding: @@ -101,33 +101,33 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-19T03:05:33Z' + - '2026-02-19T03:18:29Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-19T03:05:33Z' + - '2026-02-19T03:18:29Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-19T03:05:34Z' + - '2026-02-19T03:18:29Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-19T03:05:33Z' + - '2026-02-19T03:18:29Z' cf-cache-status: - DYNAMIC request-id: - - req_011CYGgqjkmHf8Jym2C64R1C + - req_011CYGhptTUiKkLJS5jVsinx strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1578' + - '1132' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_delegates_response_attribute.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_delegates_response_attribute.yaml index c38a3e1b7f..3519554bec 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_delegates_response_attribute.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_delegates_response_attribute.yaml @@ -57,10 +57,10 @@ interactions: body: string: |+ event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01K8QbSPahDZjJJ7Jssa138s","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01Y7yWx31UWCjCNW9M1pNzgX","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } event: ping data: {"type": "ping"} @@ -69,26 +69,26 @@ interactions: data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"! How"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" there! How"} } event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"} } event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" you doing today?"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" you doing today?"} } event: content_block_stop - data: {"type":"content_block_stop","index":0 } + data: {"type":"content_block_stop","index":0 } event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11}} + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":12} } event: message_stop - data: {"type":"message_stop" } + data: {"type":"message_stop" } headers: CF-RAY: - - 9d028b278cfa0d33-EWR + - 9d029e11ec7ab3aa-EWR Cache-Control: - no-cache Connection: @@ -98,7 +98,7 @@ interactions: Content-Type: - text/event-stream; charset=utf-8 Date: - - Thu, 19 Feb 2026 03:05:38 GMT + - Thu, 19 Feb 2026 03:18:32 GMT Server: - cloudflare Transfer-Encoding: @@ -110,33 +110,33 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-19T03:05:37Z' + - '2026-02-19T03:18:32Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-19T03:05:37Z' + - '2026-02-19T03:18:32Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-19T03:05:37Z' + - '2026-02-19T03:18:32Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-19T03:05:37Z' + - '2026-02-19T03:18:32Z' cf-cache-status: - DYNAMIC request-id: - - req_011CYGgqzCvG9T57j3mhgid9 + - req_011CYGhq6hBg2rHwtnkZ3CTA strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1193' + - '920' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml index 2d0e637020..903aa5d301 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml @@ -57,38 +57,38 @@ interactions: body: string: |+ event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01BpCo1wgx38EMetyqUHbKU4","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_015ue1pF9o95kVXNnKmwQnx4","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } event: ping data: {"type": "ping"} event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"! How"}} + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"! How"} } event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"} } event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" you doing today?"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" you doing today?"} } event: content_block_stop - data: {"type":"content_block_stop","index":0 } + data: {"type":"content_block_stop","index":0 } event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } event: message_stop - data: {"type":"message_stop" } + data: {"type":"message_stop" } headers: CF-RAY: - - 9d028b1dedaa8c5d-EWR + - 9d029e09ac68adca-EWR Cache-Control: - no-cache Connection: @@ -98,7 +98,7 @@ interactions: Content-Type: - text/event-stream; charset=utf-8 Date: - - Thu, 19 Feb 2026 03:05:36 GMT + - Thu, 19 Feb 2026 03:18:31 GMT Server: - cloudflare Transfer-Encoding: @@ -110,33 +110,33 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-19T03:05:35Z' + - '2026-02-19T03:18:30Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-19T03:05:35Z' + - '2026-02-19T03:18:30Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-19T03:05:35Z' + - '2026-02-19T03:18:30Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-19T03:05:35Z' + - '2026-02-19T03:18:30Z' cf-cache-status: - DYNAMIC request-id: - - req_011CYGgqsb4LTyo7gqt7x1BX + - req_011CYGhq14bvWmjvRbWXvVJu strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1115' + - '968' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml index 31d7708f2c..63ac23ae0f 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml @@ -57,7 +57,7 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_01K2eUCtTz3m34b16Fj2PRLL", + "id": "msg_01QCqNmmLxxd8VpRtmMJykSg", "type": "message", "role": "assistant", "content": [ @@ -83,7 +83,7 @@ interactions: } headers: CF-RAY: - - 9d028aed89256e53-EWR + - 9d029dd9daad5e73-EWR Connection: - keep-alive Content-Security-Policy: @@ -91,7 +91,7 @@ interactions: Content-Type: - application/json Date: - - Thu, 19 Feb 2026 03:05:29 GMT + - Thu, 19 Feb 2026 03:18:24 GMT Server: - cloudflare Transfer-Encoding: @@ -103,35 +103,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-19T03:05:29Z' + - '2026-02-19T03:18:24Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-19T03:05:29Z' + - '2026-02-19T03:18:24Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-19T03:05:28Z' + - '2026-02-19T03:18:23Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-19T03:05:29Z' + - '2026-02-19T03:18:24Z' cf-cache-status: - DYNAMIC content-length: - '449' request-id: - - req_011CYGgqJXDj6uzUxcHZccee + - req_011CYGhpSN6LooGwaddQzbTg strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1370' + - '1294' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml index a5f8a1f1bf..15353d701b 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml @@ -63,13 +63,13 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_01FiTVJCpPge2YniT4JqyGyh", + "id": "msg_01EEc9oeAcYNQNRBEvJjssPz", "type": "message", "role": "assistant", "content": [ { "type": "text", - "text": "Hello! It's nice to meet you. How are you doing today?" + "text": "Hello! How are you doing today?" } ], "stop_reason": "end_turn", @@ -82,14 +82,14 @@ interactions: "ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0 }, - "output_tokens": 18, + "output_tokens": 11, "service_tier": "standard", "inference_geo": "not_available" } } headers: CF-RAY: - - 9d028ae39c1f422b-EWR + - 9d029dd1bff5488c-EWR Connection: - keep-alive Content-Security-Policy: @@ -97,7 +97,7 @@ interactions: Content-Type: - application/json Date: - - Thu, 19 Feb 2026 03:05:27 GMT + - Thu, 19 Feb 2026 03:18:22 GMT Server: - cloudflare Transfer-Encoding: @@ -109,35 +109,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-19T03:05:27Z' + - '2026-02-19T03:18:22Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-19T03:05:27Z' + - '2026-02-19T03:18:22Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-19T03:05:26Z' + - '2026-02-19T03:18:21Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-19T03:05:27Z' + - '2026-02-19T03:18:22Z' cf-cache-status: - DYNAMIC content-length: - - '490' + - '467' request-id: - - req_011CYGgqBhCi2fdTMjzUaVCr + - req_011CYGhpLoUa14drYiMctTHg strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1446' + - '1151' status: code: 200 message: OK From 1d1b7f5f905022cd1d9c0c7f0b76ee1345529930 Mon Sep 17 00:00:00 2001 From: Teja Date: Mon, 23 Feb 2026 20:23:31 -0500 Subject: [PATCH 26/35] Rename StreamWrapper to MessagesStreamWrapper and update references in code and tests --- .../instrumentation/anthropic/patch.py | 6 +-- .../instrumentation/anthropic/wrappers.py | 54 +++++++++++++------ .../tests/test_sync_messages.py | 6 +-- 3 files changed, 44 insertions(+), 22 deletions(-) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py index a4046f2b19..6b1ce0b137 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py @@ -31,7 +31,7 @@ ) from .wrappers import ( MessageWrapper, - StreamWrapper, + MessagesStreamWrapper, ) if TYPE_CHECKING: @@ -56,7 +56,7 @@ def traced_method( instance: "Messages", args: tuple[Any, ...], kwargs: dict[str, Any], - ) -> Union["Message", StreamWrapper]: + ) -> Union["Message", MessagesStreamWrapper]: params = extract_params(*args, **kwargs) attributes = get_llm_request_attributes(params, instance) request_model_attribute = attributes.get( @@ -88,7 +88,7 @@ def traced_method( result = wrapped(*args, **kwargs) if is_streaming: stream_result = cast("Stream[RawMessageStreamEvent]", result) - return StreamWrapper( + return MessagesStreamWrapper( stream_result, handler, invocation, capture_content ) message_result = cast("Message", result) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py index 53df438941..271e31801b 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py @@ -91,7 +91,7 @@ def message(self) -> "Message": return self._message -class StreamWrapper(Iterator["RawMessageStreamEvent"]): +class MessagesStreamWrapper(Iterator["RawMessageStreamEvent"]): """Wrapper for Anthropic Stream that handles telemetry.""" def __init__( @@ -162,11 +162,8 @@ def _process_chunk(self, chunk: "RawMessageStreamEvent") -> None: block = self._content_blocks.setdefault(index, {}) update_stream_block_state(block, delta) - def _finalize_invocation(self) -> None: - if self._finalized: - return - self._finalized = True - + def _set_invocation_response_attributes(self) -> None: + """Extract accumulated stream state into the invocation.""" if self._response_model: self._invocation.response_model_name = self._response_model if self._response_id: @@ -200,9 +197,24 @@ def _finalize_invocation(self) -> None: ) ] + def _stop(self) -> None: + if self._finalized: + return + self._set_invocation_response_attributes() self._handler.stop_llm(self._invocation) + self._finalized = True - def __iter__(self) -> "StreamWrapper": + def _fail( + self, message: str, error_type: type[BaseException] + ) -> None: + if self._finalized: + return + self._handler.fail_llm( + self._invocation, Error(message=message, type=error_type) + ) + self._finalized = True + + def __iter__(self) -> "MessagesStreamWrapper": return self def __getattr__(self, name: str) -> Any: @@ -214,22 +226,32 @@ def __next__(self) -> "RawMessageStreamEvent": self._process_chunk(chunk) return chunk except StopIteration: - self._finalize_invocation() + self._stop() raise except Exception as exc: - self._handler.fail_llm( - self._invocation, Error(message=str(exc), type=type(exc)) - ) + self._fail(str(exc), type(exc)) raise - def __enter__(self) -> "StreamWrapper": + def __enter__(self) -> "MessagesStreamWrapper": return self def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool: - self.close() + try: + if exc_type is not None: + self._fail( + str(exc_val), type(exc_val) if exc_val else Exception + ) + finally: + self.close() return False def close(self) -> None: - if hasattr(self._stream, "close"): - self._stream.close() - self._finalize_invocation() + try: + if hasattr(self._stream, "close"): + self._stream.close() + finally: + self._stop() + + +# Backward-compatible alias for older imports. +StreamWrapper = MessagesStreamWrapper diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py index ea61f30073..bd70ec6c50 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py @@ -27,7 +27,7 @@ from opentelemetry.instrumentation.anthropic import AnthropicInstrumentor from opentelemetry.instrumentation.anthropic.wrappers import ( MessageWrapper, - StreamWrapper, + MessagesStreamWrapper, ) from opentelemetry.semconv._incubating.attributes import ( error_attributes as ErrorAttributes, @@ -729,7 +729,7 @@ def test_message_wrapper_aggregates_cache_tokens(): def test_stream_wrapper_aggregates_cache_tokens(): - """StreamWrapper should aggregate cache token fields from stream chunks.""" + """MessagesStreamWrapper should aggregate cache token fields.""" class FakeHandler: def stop_llm(self, invocation): # pylint: disable=no-self-use @@ -783,7 +783,7 @@ def close(self): # pylint: disable=no-self-use request_model="claude-sonnet-4-20250514", provider="anthropic", ) - wrapper = StreamWrapper( # type: ignore[arg-type] + wrapper = MessagesStreamWrapper( # type: ignore[arg-type] FakeStream(), FakeHandler(), invocation, capture_content=False ) list(wrapper) From 5effa69e695fcdcee198cb555e32a12315f94506 Mon Sep 17 00:00:00 2001 From: Teja Date: Tue, 24 Feb 2026 21:11:17 -0500 Subject: [PATCH 27/35] Refactor type annotations in message extractors and wrappers for improved type safety. Replace 'Any' with 'object' in several function signatures and class attributes. Introduce logging for error handling in MessagesStreamWrapper to enhance instrumentation reliability. --- .../anthropic/messages_extractors.py | 44 +++++------ .../instrumentation/anthropic/wrappers.py | 74 +++++++++++++------ 2 files changed, 74 insertions(+), 44 deletions(-) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/messages_extractors.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/messages_extractors.py index 43d01feeff..9b2dfee310 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/messages_extractors.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/messages_extractors.py @@ -17,7 +17,7 @@ from __future__ import annotations from dataclasses import dataclass -from typing import TYPE_CHECKING, Any, Optional, Sequence, cast +from typing import TYPE_CHECKING, Optional, Sequence from urllib.parse import urlparse from opentelemetry.semconv._incubating.attributes import ( @@ -53,8 +53,8 @@ class MessageRequestParams: top_k: int | None = None top_p: float | None = None stop_sequences: Sequence[str] | None = None - messages: Any | None = None - system: Any | None = None + messages: object | None = None + system: object | None = None GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS = ( @@ -64,7 +64,7 @@ class MessageRequestParams: def extract_usage_tokens( - usage: Any | None, + usage: object | None, ) -> tuple[int | None, int | None, int | None, int | None]: if usage is None: return None, None, None, None @@ -99,23 +99,23 @@ def extract_usage_tokens( ) -def get_input_messages(messages: Any) -> list[InputMessage]: +def get_input_messages(messages: object) -> list[InputMessage]: if not isinstance(messages, list): return [] result: list[InputMessage] = [] - for message in cast(list[Any], messages): + for message in messages: role = _as_str(_get_field(message, "role")) or "user" parts = convert_content_to_parts(_get_field(message, "content")) result.append(InputMessage(role=role, parts=parts)) return result -def get_system_instruction(system: Any) -> list[MessagePart]: +def get_system_instruction(system: object) -> list[MessagePart]: return convert_content_to_parts(system) -def get_output_messages_from_message(message: Any) -> list[OutputMessage]: +def get_output_messages_from_message(message: object) -> list[OutputMessage]: if message is None: return [] @@ -133,24 +133,24 @@ def get_output_messages_from_message(message: Any) -> list[OutputMessage]: def extract_params( # pylint: disable=too-many-locals *, max_tokens: int | None = None, - messages: Any | None = None, + messages: object | None = None, model: str | None = None, - metadata: Any | None = None, - service_tier: Any | None = None, + metadata: object | None = None, + service_tier: object | None = None, stop_sequences: Sequence[str] | None = None, - stream: Any | None = None, - system: Any | None = None, + stream: object | None = None, + system: object | None = None, temperature: float | None = None, - thinking: Any | None = None, - tool_choice: Any | None = None, - tools: Any | None = None, + thinking: object | None = None, + tool_choice: object | None = None, + tools: object | None = None, top_k: int | None = None, top_p: float | None = None, - extra_headers: Any | None = None, - extra_query: Any | None = None, - extra_body: Any | None = None, - timeout: Any | None = None, - **_kwargs: Any, + extra_headers: object | None = None, + extra_query: object | None = None, + extra_body: object | None = None, + timeout: object | None = None, + **_kwargs: object, ) -> MessageRequestParams: return MessageRequestParams( model=model, @@ -165,7 +165,7 @@ def extract_params( # pylint: disable=too-many-locals def _set_server_address_and_port( - client_instance: "Messages", attributes: dict[str, Any] + client_instance: "Messages", attributes: dict[str, AttributeValue] ) -> None: base_client = getattr(client_instance, "_client", None) base_url = getattr(base_client, "base_url", None) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py index 271e31801b..91a68f989e 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py @@ -14,7 +14,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Iterator, Optional +import logging +from types import TracebackType +from typing import TYPE_CHECKING, Callable, Iterator, Optional from opentelemetry.util.genai.handler import TelemetryHandler from opentelemetry.util.genai.types import ( @@ -43,10 +45,13 @@ from anthropic.types import Message, RawMessageStreamEvent +_logger = logging.getLogger(__name__) + + class MessageWrapper: """Wrapper for non-streaming Message response that handles telemetry.""" - def __init__(self, message: "Message", capture_content: bool): + def __init__(self, message: Message, capture_content: bool): self._message = message self._capture_content = capture_content @@ -86,7 +91,7 @@ def extract_into(self, invocation: LLMInvocation) -> None: ) @property - def message(self) -> "Message": + def message(self) -> Message: """Return the wrapped Message object.""" return self._message @@ -96,7 +101,7 @@ class MessagesStreamWrapper(Iterator["RawMessageStreamEvent"]): def __init__( self, - stream: "Stream[RawMessageStreamEvent]", + stream: Stream[RawMessageStreamEvent], handler: TelemetryHandler, invocation: LLMInvocation, capture_content: bool, @@ -112,10 +117,10 @@ def __init__( self._cache_creation_input_tokens: Optional[int] = None self._cache_read_input_tokens: Optional[int] = None self._capture_content = capture_content - self._content_blocks: dict[int, dict[str, Any]] = {} + self._content_blocks: dict[int, dict[str, object]] = {} self._finalized = False - def _update_usage(self, usage: Any | None) -> None: + def _update_usage(self, usage: object | None) -> None: ( input_tokens, output_tokens, @@ -131,7 +136,7 @@ def _update_usage(self, usage: Any | None) -> None: if cache_read_input_tokens is not None: self._cache_read_input_tokens = cache_read_input_tokens - def _process_chunk(self, chunk: "RawMessageStreamEvent") -> None: + def _process_chunk(self, chunk: RawMessageStreamEvent) -> None: """Extract telemetry data from a streaming chunk.""" if chunk.type == "message_start": message = getattr(chunk, "message", None) @@ -162,6 +167,18 @@ def _process_chunk(self, chunk: "RawMessageStreamEvent") -> None: block = self._content_blocks.setdefault(index, {}) update_stream_block_state(block, delta) + def _safe_instrumentation( + self, callback: Callable[[], None], context: str + ) -> None: + try: + callback() + except Exception: # pylint: disable=broad-exception-caught + _logger.debug( + "Anthropic MessagesStreamWrapper instrumentation error in %s", + context, + exc_info=True, + ) + def _set_invocation_response_attributes(self) -> None: """Extract accumulated stream state into the invocation.""" if self._response_model: @@ -200,8 +217,14 @@ def _set_invocation_response_attributes(self) -> None: def _stop(self) -> None: if self._finalized: return - self._set_invocation_response_attributes() - self._handler.stop_llm(self._invocation) + self._safe_instrumentation( + self._set_invocation_response_attributes, + "response attribute extraction", + ) + self._safe_instrumentation( + lambda: self._handler.stop_llm(self._invocation), + "stop_llm", + ) self._finalized = True def _fail( @@ -209,33 +232,44 @@ def _fail( ) -> None: if self._finalized: return - self._handler.fail_llm( - self._invocation, Error(message=message, type=error_type) + self._safe_instrumentation( + lambda: self._handler.fail_llm( + self._invocation, Error(message=message, type=error_type) + ), + "fail_llm", ) self._finalized = True - def __iter__(self) -> "MessagesStreamWrapper": + def __iter__(self) -> MessagesStreamWrapper: return self - def __getattr__(self, name: str) -> Any: + def __getattr__(self, name: str) -> object: return getattr(self._stream, name) - def __next__(self) -> "RawMessageStreamEvent": + def __next__(self) -> RawMessageStreamEvent: try: chunk = next(self._stream) - self._process_chunk(chunk) - return chunk except StopIteration: self._stop() raise except Exception as exc: self._fail(str(exc), type(exc)) raise + self._safe_instrumentation( + lambda: self._process_chunk(chunk), + "stream chunk processing", + ) + return chunk - def __enter__(self) -> "MessagesStreamWrapper": + def __enter__(self) -> MessagesStreamWrapper: return self - def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool: + def __exit__( + self, + exc_type: type[BaseException] | None, + exc_val: BaseException | None, + exc_tb: TracebackType | None, + ) -> bool: try: if exc_type is not None: self._fail( @@ -251,7 +285,3 @@ def close(self) -> None: self._stream.close() finally: self._stop() - - -# Backward-compatible alias for older imports. -StreamWrapper = MessagesStreamWrapper From a835a751fe7bb2c97a724dcd135a1ccad2edc17d Mon Sep 17 00:00:00 2001 From: Teja Date: Tue, 24 Feb 2026 22:32:36 -0500 Subject: [PATCH 28/35] Enhance type annotations in message extractors and patch for improved clarity and safety. Update function signatures to use specific types instead of 'object', including changes to parameters in extract_params, get_input_messages, and get_system_instruction. Refactor messages_create to ensure correct type handling for streaming and non-streaming responses. Additionally, streamline message handling in MessagesStreamWrapper for better performance and reliability. --- .../anthropic/messages_extractors.py | 58 ++++++++++++------- .../instrumentation/anthropic/patch.py | 45 ++++++++++---- .../instrumentation/anthropic/wrappers.py | 13 ++--- .../tests/test_sync_messages.py | 2 +- 4 files changed, 78 insertions(+), 40 deletions(-) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/messages_extractors.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/messages_extractors.py index 9b2dfee310..72978385fa 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/messages_extractors.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/messages_extractors.py @@ -20,6 +20,8 @@ from typing import TYPE_CHECKING, Optional, Sequence from urllib.parse import urlparse +from anthropic.types import MessageDeltaUsage + from opentelemetry.semconv._incubating.attributes import ( gen_ai_attributes as GenAIAttributes, ) @@ -42,7 +44,20 @@ ) if TYPE_CHECKING: + from collections.abc import Iterable, Mapping + + import httpx from anthropic.resources.messages import Messages + from anthropic.types import ( + Message, + MessageParam, + MetadataParam, + TextBlockParam, + ThinkingConfigParam, + ToolChoiceParam, + ToolUnionParam, + Usage, + ) @dataclass @@ -53,8 +68,9 @@ class MessageRequestParams: top_k: int | None = None top_p: float | None = None stop_sequences: Sequence[str] | None = None - messages: object | None = None - system: object | None = None + stream: bool | None = None + messages: Iterable[MessageParam] | None = None + system: str | Iterable[TextBlockParam] | None = None GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS = ( @@ -64,7 +80,7 @@ class MessageRequestParams: def extract_usage_tokens( - usage: object | None, + usage: Usage | MessageDeltaUsage | None, ) -> tuple[int | None, int | None, int | None, int | None]: if usage is None: return None, None, None, None @@ -99,10 +115,7 @@ def extract_usage_tokens( ) -def get_input_messages(messages: object) -> list[InputMessage]: - if not isinstance(messages, list): - return [] - +def get_input_messages(messages: Iterable[MessageParam]) -> list[InputMessage]: result: list[InputMessage] = [] for message in messages: role = _as_str(_get_field(message, "role")) or "user" @@ -111,11 +124,15 @@ def get_input_messages(messages: object) -> list[InputMessage]: return result -def get_system_instruction(system: object) -> list[MessagePart]: +def get_system_instruction( + system: str | Iterable[TextBlockParam], +) -> list[MessagePart]: return convert_content_to_parts(system) -def get_output_messages_from_message(message: object) -> list[OutputMessage]: +def get_output_messages_from_message( + message: Message | None, +) -> list[OutputMessage]: if message is None: return [] @@ -133,23 +150,23 @@ def get_output_messages_from_message(message: object) -> list[OutputMessage]: def extract_params( # pylint: disable=too-many-locals *, max_tokens: int | None = None, - messages: object | None = None, + messages: Iterable[MessageParam] | None = None, model: str | None = None, - metadata: object | None = None, - service_tier: object | None = None, + metadata: MetadataParam | None = None, + service_tier: str | None = None, stop_sequences: Sequence[str] | None = None, - stream: object | None = None, - system: object | None = None, + stream: bool | None = None, + system: str | Iterable[TextBlockParam] | None = None, temperature: float | None = None, - thinking: object | None = None, - tool_choice: object | None = None, - tools: object | None = None, + thinking: ThinkingConfigParam | None = None, + tool_choice: ToolChoiceParam | None = None, + tools: Iterable[ToolUnionParam] | None = None, top_k: int | None = None, top_p: float | None = None, - extra_headers: object | None = None, - extra_query: object | None = None, + extra_headers: Mapping[str, str] | None = None, + extra_query: Mapping[str, object] | None = None, extra_body: object | None = None, - timeout: object | None = None, + timeout: float | httpx.Timeout | None = None, **_kwargs: object, ) -> MessageRequestParams: return MessageRequestParams( @@ -159,6 +176,7 @@ def extract_params( # pylint: disable=too-many-locals top_p=top_p, top_k=top_k, stop_sequences=stop_sequences, + stream=stream, messages=messages, system=system, ) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py index 6b1ce0b137..1fadb78a38 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/patch.py @@ -16,6 +16,9 @@ from typing import TYPE_CHECKING, Any, Callable, Union, cast +from anthropic._streaming import Stream as AnthropicStream +from anthropic.types import Message as AnthropicMessage + from opentelemetry.semconv._incubating.attributes import ( gen_ai_attributes as GenAIAttributes, ) @@ -30,14 +33,13 @@ get_system_instruction, ) from .wrappers import ( - MessageWrapper, MessagesStreamWrapper, + MessageWrapper, ) if TYPE_CHECKING: - from anthropic._streaming import Stream from anthropic.resources.messages import Messages - from anthropic.types import Message, RawMessageStreamEvent + from anthropic.types import RawMessageStreamEvent ANTHROPIC = "anthropic" @@ -45,18 +47,24 @@ def messages_create( handler: TelemetryHandler, -) -> Callable[..., Union["Message", "Stream[RawMessageStreamEvent]"]]: +) -> Callable[ + ..., Union["AnthropicMessage", "AnthropicStream[RawMessageStreamEvent]"] +]: """Wrap the `create` method of the `Messages` class to trace it.""" capture_content = should_capture_content() def traced_method( wrapped: Callable[ - ..., Union["Message", "Stream[RawMessageStreamEvent]"] + ..., + Union[ + "AnthropicMessage", + "AnthropicStream[RawMessageStreamEvent]", + ], ], instance: "Messages", args: tuple[Any, ...], kwargs: dict[str, Any], - ) -> Union["Message", MessagesStreamWrapper]: + ) -> Union["AnthropicMessage", MessagesStreamWrapper]: params = extract_params(*args, **kwargs) attributes = get_llm_request_attributes(params, instance) request_model_attribute = attributes.get( @@ -80,19 +88,26 @@ def traced_method( attributes=attributes, ) - is_streaming = kwargs.get("stream", False) + is_streaming = params.stream is True # Use manual lifecycle management for both streaming and non-streaming handler.start_llm(invocation) try: result = wrapped(*args, **kwargs) if is_streaming: - stream_result = cast("Stream[RawMessageStreamEvent]", result) + if not isinstance(result, AnthropicStream): + raise TypeError( + "Expected anthropic Stream when stream=True" + ) return MessagesStreamWrapper( - stream_result, handler, invocation, capture_content + result, handler, invocation, capture_content ) - message_result = cast("Message", result) - wrapper = MessageWrapper(message_result, capture_content) + if not isinstance(result, AnthropicMessage): + raise TypeError( + "Expected anthropic Message when stream is disabled" + ) + + wrapper = MessageWrapper(result, capture_content) wrapper.extract_into(invocation) handler.stop_llm(invocation) return wrapper.message @@ -103,6 +118,12 @@ def traced_method( raise return cast( - Callable[..., Union["Message", "Stream[RawMessageStreamEvent]"]], + Callable[ + ..., + Union[ + "AnthropicMessage", + "AnthropicStream[RawMessageStreamEvent]", + ], + ], traced_method, ) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py index 91a68f989e..3334eff546 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py @@ -139,7 +139,7 @@ def _update_usage(self, usage: object | None) -> None: def _process_chunk(self, chunk: RawMessageStreamEvent) -> None: """Extract telemetry data from a streaming chunk.""" if chunk.type == "message_start": - message = getattr(chunk, "message", None) + message = chunk.message if message: if hasattr(message, "id") and message.id: self._response_id = message.id @@ -148,10 +148,10 @@ def _process_chunk(self, chunk: RawMessageStreamEvent) -> None: if hasattr(message, "usage") and message.usage: self._update_usage(message.usage) elif chunk.type == "message_delta": - delta = getattr(chunk, "delta", None) + delta = chunk.delta if delta and hasattr(delta, "stop_reason") and delta.stop_reason: self._stop_reason = normalize_finish_reason(delta.stop_reason) - usage = getattr(chunk, "usage", None) + usage = chunk.usage self._update_usage(usage) elif self._capture_content and chunk.type == "content_block_start": index = _get_field(chunk, "index") @@ -167,8 +167,9 @@ def _process_chunk(self, chunk: RawMessageStreamEvent) -> None: block = self._content_blocks.setdefault(index, {}) update_stream_block_state(block, delta) + @staticmethod def _safe_instrumentation( - self, callback: Callable[[], None], context: str + callback: Callable[[], None], context: str ) -> None: try: callback() @@ -227,9 +228,7 @@ def _stop(self) -> None: ) self._finalized = True - def _fail( - self, message: str, error_type: type[BaseException] - ) -> None: + def _fail(self, message: str, error_type: type[BaseException]) -> None: if self._finalized: return self._safe_instrumentation( diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py index bd70ec6c50..4797cffd5e 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py @@ -26,8 +26,8 @@ from opentelemetry.instrumentation.anthropic import AnthropicInstrumentor from opentelemetry.instrumentation.anthropic.wrappers import ( - MessageWrapper, MessagesStreamWrapper, + MessageWrapper, ) from opentelemetry.semconv._incubating.attributes import ( error_attributes as ErrorAttributes, From 471204c61287cf3e6a4cf8245841149fb55827e4 Mon Sep 17 00:00:00 2001 From: Teja Date: Wed, 25 Feb 2026 19:11:57 -0500 Subject: [PATCH 29/35] Enhance type safety and error handling in message processing. Update function signatures in `messages_extractors.py` and `wrappers.py` to include specific types, improving clarity and reliability. Introduce handling for `None` values in `get_input_messages` and `get_system_instruction`. Refactor `MessagesStreamWrapper` to better manage usage updates and ensure correct type handling for streaming responses. Add new test cases for aggregating cache tokens and handling streaming errors. --- .../anthropic/messages_extractors.py | 18 +- .../instrumentation/anthropic/wrappers.py | 11 +- ...st_stream_wrapper_finalize_idempotent.yaml | 24 +- ...ssages_create_aggregates_cache_tokens.yaml | 138 +++++++++ .../test_sync_messages_create_api_error.yaml | 10 +- .../test_sync_messages_create_basic.yaml | 20 +- ...sync_messages_create_captures_content.yaml | 18 +- ...ages_create_captures_thinking_content.yaml | 28 +- ...ages_create_captures_tool_use_content.yaml | 20 +- ..._create_event_only_no_content_in_span.yaml | 18 +- ...reate_instrumentation_error_swallowed.yaml | 134 +++++++++ ...test_sync_messages_create_stop_reason.yaml | 18 +- ...sages_create_stream_propagation_error.yaml | 134 +++++++++ .../test_sync_messages_create_streaming.yaml | 28 +- ...ate_streaming_aggregates_cache_tokens.yaml | 134 +++++++++ ...ges_create_streaming_captures_content.yaml | 26 +- ...treaming_delegates_response_attribute.yaml | 32 +-- ...c_messages_create_streaming_iteration.yaml | 30 +- ...sages_create_streaming_user_exception.yaml | 134 +++++++++ ...test_sync_messages_create_token_usage.yaml | 18 +- ..._sync_messages_create_with_all_params.yaml | 18 +- .../tests/test_sync_messages.py | 263 +++++++++++++----- 22 files changed, 1035 insertions(+), 239 deletions(-) create mode 100644 instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_aggregates_cache_tokens.yaml create mode 100644 instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_instrumentation_error_swallowed.yaml create mode 100644 instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stream_propagation_error.yaml create mode 100644 instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_aggregates_cache_tokens.yaml create mode 100644 instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_user_exception.yaml diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/messages_extractors.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/messages_extractors.py index 72978385fa..acfdffb093 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/messages_extractors.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/messages_extractors.py @@ -115,7 +115,11 @@ def extract_usage_tokens( ) -def get_input_messages(messages: Iterable[MessageParam]) -> list[InputMessage]: +def get_input_messages( + messages: Iterable[MessageParam] | None, +) -> list[InputMessage]: + if messages is None: + return [] result: list[InputMessage] = [] for message in messages: role = _as_str(_get_field(message, "role")) or "user" @@ -125,8 +129,10 @@ def get_input_messages(messages: Iterable[MessageParam]) -> list[InputMessage]: def get_system_instruction( - system: str | Iterable[TextBlockParam], + system: str | Iterable[TextBlockParam] | None, ) -> list[MessagePart]: + if system is None: + return [] return convert_content_to_parts(system) @@ -183,7 +189,8 @@ def extract_params( # pylint: disable=too-many-locals def _set_server_address_and_port( - client_instance: "Messages", attributes: dict[str, AttributeValue] + client_instance: "Messages", + attributes: dict[str, AttributeValue | None], ) -> None: base_client = getattr(client_instance, "_client", None) base_url = getattr(base_client, "base_url", None) @@ -196,7 +203,8 @@ def _set_server_address_and_port( port = getattr(base_url, "port", None) elif isinstance(base_url, str): url = urlparse(base_url) - attributes[ServerAttributes.SERVER_ADDRESS] = url.hostname + if url.hostname is not None: + attributes[ServerAttributes.SERVER_ADDRESS] = url.hostname port = url.port if port and port != 443 and port > 0: @@ -206,7 +214,7 @@ def _set_server_address_and_port( def get_llm_request_attributes( params: MessageRequestParams, client_instance: "Messages" ) -> dict[str, AttributeValue]: - attributes = { + attributes: dict[str, AttributeValue | None] = { GenAIAttributes.GEN_AI_OPERATION_NAME: GenAIAttributes.GenAiOperationNameValues.CHAT.value, GenAIAttributes.GEN_AI_SYSTEM: GenAIAttributes.GenAiSystemValues.ANTHROPIC.value, # pyright: ignore[reportDeprecated] GenAIAttributes.GEN_AI_REQUEST_MODEL: params.model, diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py index 3334eff546..9d069c96f7 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py @@ -42,7 +42,12 @@ if TYPE_CHECKING: from anthropic._streaming import Stream - from anthropic.types import Message, RawMessageStreamEvent + from anthropic.types import ( + Message, + MessageDeltaUsage, + RawMessageStreamEvent, + Usage, + ) _logger = logging.getLogger(__name__) @@ -120,7 +125,7 @@ def __init__( self._content_blocks: dict[int, dict[str, object]] = {} self._finalized = False - def _update_usage(self, usage: object | None) -> None: + def _update_usage(self, usage: Usage | MessageDeltaUsage | None) -> None: ( input_tokens, output_tokens, @@ -169,7 +174,7 @@ def _process_chunk(self, chunk: RawMessageStreamEvent) -> None: @staticmethod def _safe_instrumentation( - callback: Callable[[], None], context: str + callback: Callable[[], object], context: str ) -> None: try: callback() diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml index c1e0c24c69..b4df860b7f 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml @@ -57,7 +57,7 @@ interactions: body: string: |+ event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01LviXx3SM9CFsB8qWtzz5eA","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}}} + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01H6rLTyoXw2bmGDRrqebTks","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } event: content_block_start data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } @@ -66,20 +66,20 @@ interactions: data: {"type": "ping"} event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello."} } event: content_block_stop - data: {"type":"content_block_stop","index":0 } + data: {"type":"content_block_stop","index":0 } event: message_delta data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } event: message_stop - data: {"type":"message_stop" } + data: {"type":"message_stop" } headers: CF-RAY: - - 9d029e4f4aa45e72-EWR + - 9d3b38fa8f2d31cb-EWR Cache-Control: - no-cache Connection: @@ -89,7 +89,7 @@ interactions: Content-Type: - text/event-stream; charset=utf-8 Date: - - Thu, 19 Feb 2026 03:18:42 GMT + - Thu, 26 Feb 2026 00:11:00 GMT Server: - cloudflare Transfer-Encoding: @@ -101,33 +101,33 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-19T03:18:41Z' + - '2026-02-26T00:10:59Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-19T03:18:41Z' + - '2026-02-26T00:10:59Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-19T03:18:41Z' + - '2026-02-26T00:10:59Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-19T03:18:41Z' + - '2026-02-26T00:10:59Z' cf-cache-status: - DYNAMIC request-id: - - req_011CYGhqpgJFAfFHU4h8WWSE + - req_011CYViC3gVvbQccjvnUK4qs strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '902' + - '923' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_aggregates_cache_tokens.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_aggregates_cache_tokens.yaml new file mode 100644 index 0000000000..a5c55501e2 --- /dev/null +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_aggregates_cache_tokens.yaml @@ -0,0 +1,138 @@ +interactions: +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514" + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '117' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - '600' + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |- + { + "model": "claude-sonnet-4-20250514", + "id": "msg_01YM2FALrDv6M4wXGzYmL1NK", + "type": "message", + "role": "assistant", + "content": [ + { + "type": "text", + "text": "Hello!" + } + ], + "stop_reason": "end_turn", + "stop_sequence": null, + "usage": { + "input_tokens": 13, + "cache_creation_input_tokens": 0, + "cache_read_input_tokens": 0, + "cache_creation": { + "ephemeral_5m_input_tokens": 0, + "ephemeral_1h_input_tokens": 0 + }, + "output_tokens": 5, + "service_tier": "standard", + "inference_geo": "not_available" + } + } + headers: + CF-RAY: + - 9d3b3901ea5a8abe-EWR + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - application/json + Date: + - Thu, 26 Feb 2026 00:11:02 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-26T00:11:02Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-26T00:11:02Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-26T00:11:01Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-26T00:11:02Z' + cf-cache-status: + - DYNAMIC + content-length: + - '441' + request-id: + - req_011CYViC8mb2JZhazchQ29qj + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1865' + status: + code: 200 + message: OK +version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml index 7d65b589c7..89db81a0f3 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml @@ -61,11 +61,11 @@ interactions: "type": "not_found_error", "message": "model: invalid-model-name" }, - "request_id": "req_011CYGhpks5P7XxEveVNKVG1" + "request_id": "req_011CYViAuU7DmHrwTiP5n98M" } headers: CF-RAY: - - 9d029df4edc1dcf2-EWR + - 9d3b3899bfea151b-EWR Connection: - keep-alive Content-Security-Policy: @@ -73,7 +73,7 @@ interactions: Content-Type: - application/json Date: - - Thu, 19 Feb 2026 03:18:27 GMT + - Thu, 26 Feb 2026 00:10:44 GMT Server: - cloudflare Transfer-Encoding: @@ -85,11 +85,11 @@ interactions: content-length: - '133' request-id: - - req_011CYGhpks5P7XxEveVNKVG1 + - req_011CYViAuU7DmHrwTiP5n98M strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '55' + - '50' x-should-retry: - 'false' status: diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml index 0dbfd2bbc2..72b04ea175 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml @@ -57,13 +57,13 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_011kM6moFzh9EE6Ka7oczinb", + "id": "msg_01EyT4W1amM9qQRUGKXEQtKE", "type": "message", "role": "assistant", "content": [ { "type": "text", - "text": "Hello." + "text": "Hello!" } ], "stop_reason": "end_turn", @@ -83,7 +83,7 @@ interactions: } headers: CF-RAY: - - 9d029dbefaa9566e-EWR + - 9d3b3863dc6058af-EWR Connection: - keep-alive Content-Security-Policy: @@ -91,7 +91,7 @@ interactions: Content-Type: - application/json Date: - - Thu, 19 Feb 2026 03:18:19 GMT + - Thu, 26 Feb 2026 00:10:36 GMT Server: - cloudflare Transfer-Encoding: @@ -103,35 +103,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-19T03:18:19Z' + - '2026-02-26T00:10:36Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-19T03:18:19Z' + - '2026-02-26T00:10:36Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-19T03:18:18Z' + - '2026-02-26T00:10:35Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-19T03:18:19Z' + - '2026-02-26T00:10:36Z' cf-cache-status: - DYNAMIC content-length: - '441' request-id: - - req_011CYGhp7xZSRVffb9XH2iUi + - req_011CYViAGeo3XGFByeCrP8XD strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1124' + - '1191' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml index b2da7f57b8..50f6d3ab5a 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml @@ -57,7 +57,7 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_01EVg89cSWpjbbXZS6r1xNVD", + "id": "msg_018pm1e8M2sq6wFbuWi66Mzi", "type": "message", "role": "assistant", "content": [ @@ -83,7 +83,7 @@ interactions: } headers: CF-RAY: - - 9d029dc7188d7ce8-EWR + - 9d3b386c6b5920f8-EWR Connection: - keep-alive Content-Security-Policy: @@ -91,7 +91,7 @@ interactions: Content-Type: - application/json Date: - - Thu, 19 Feb 2026 03:18:21 GMT + - Thu, 26 Feb 2026 00:10:38 GMT Server: - cloudflare Transfer-Encoding: @@ -103,35 +103,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-19T03:18:21Z' + - '2026-02-26T00:10:37Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-19T03:18:21Z' + - '2026-02-26T00:10:38Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-19T03:18:20Z' + - '2026-02-26T00:10:37Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-19T03:18:21Z' + - '2026-02-26T00:10:37Z' cf-cache-status: - DYNAMIC content-length: - '441' request-id: - - req_011CYGhpDXfu53sCJs3Jj8uH + - req_011CYViANVXrHMDpqf67PSep strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1514' + - '1449' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml index 81071ebe65..70568f92c9 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml @@ -61,18 +61,18 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_019M6D1Hc9WSFVbi5UhXvxm5", + "id": "msg_01SAeJ8UJd4oULnubnoGU5td", "type": "message", "role": "assistant", "content": [ { "type": "thinking", - "thinking": "I need to calculate 17 * 19.\n\nLet me think about this step by step.\n\nOne way is to use the standard multiplication:\n17 * 19\n\nI can break this down:\n17 * 19 = 17 * (20 - 1) = 17 * 20 - 17 * 1 = 340 - 17 = 323\n\nLet me double-check this:\n17 * 20 = 340\n17 * 1 = 17\n340 - 17 = 323\n\nAlternatively, I could do:\n19 * 17 = 19 * (10 + 7) = 19 * 10 + 19 * 7 = 190 + 133\n\nLet me calculate 19 * 7:\n19 * 7 = (20 - 1) * 7 = 20 * 7 - 1 * 7 = 140 - 7 = 133\n\nSo: 190 + 133 = 323\n\nBoth methods give me 323, so that should be correct.", - "signature": "EqsFCkYICxgCKkBj3TzwlCMb5oc6IOfRK12T1/x6oRw0jcUAh73ytRZYa+FS2kbF2ww9xPCMT6UA6mo3mNluiotjDwd7ox2CQaYpEgzfGNJ622dnd9Zao78aDEvJnPgVLG3DbVZAZiIwHtc5Bi2WdxoOJlbdbxACS6DJC/wETtNVKh6+YelaZbyB5yAbq0DOX0OWLr1QL1lRKpIEb7XRfskfTALZimvJMVmxn5zFcVdGM42FoiBAUvDdugak6qgRw2l7Ur4v+6y/PHt65MrlSGz72eHCbaPJI5gXoArNOdEOBKbHkIVYrqUF+KuGtNXSS9N0+LuntqiLXO985/aA4lRpo48DAYxUIDMpjun2VPVs0U5opP4hpyhPKy+jVx0ua0bihuAQtESjacRVSXuUPa839Y7qx+uvzyCW5dXym5HiEvX5edcWSxGukLJNXpxWv1KP89PCCXvlQkSRLlGblBLVhvlW2lbKftPEN1pnlQ7ZI+kh+F9t41SUm6MQ2vyb0v9Blbs5bujDs1ivNqUldx/TNLFwQbCMVZ9fBxXO2YbmOKOkRvdaw1W5p32tRfFHSldg8Toj5wi4MWtCcSBCFq5SploMAPLS5tUyQXMCVmEye77ltNi86d0ezBTm8Xebuo1VPdJVWMMHKI0iYch6SgBbR31HA2/hO8A/BWnHryDUYb34zu8A31Zp6igaxtoCKniLTFyBIJbeJD4qf+yVrFRfdUblQu8p1dpdlY/MOnR1EVOqWj8jyiYwTtqQBqaA1bjgNCWR+dTBrolFh5n5ZGDVaZrAJo/dmhYqVBlZ3STsvm+pBf3MCw761Z0BCy5h6YkEA87PbA3yi0QxEQCoOtjgyX/cBw0K2Aillhtbq1SSEOV0CCtrwUSw6ENf/eCSqkNcWR4Q9zT7kZ1YGxUYAQ==" + "thinking": "I need to calculate 17 * 19.\n\nLet me think about this step by step.\n\nI can use the standard multiplication method:\n17 * 19\n\nOne way is to break this down:\n17 * 19 = 17 * (20 - 1) = 17 * 20 - 17 * 1 = 340 - 17 = 323\n\nLet me double-check this:\n17 * 20 = 340\n17 * 1 = 17\n340 - 17 = 323\n\nOr I can do it the traditional way:\n 17\n \u00d7 19\n ----\n 153 (17 \u00d7 9)\n 170 (17 \u00d7 10)\n ----\n 323\n\nLet me verify the first line: 17 \u00d7 9\n17 \u00d7 9 = 17 \u00d7 (10 - 1) = 170 - 17 = 153 \u2713\n\nAnd 17 \u00d7 10 = 170 \u2713\n\n153 + 170 = 323 \u2713\n\nSo 17 \u00d7 19 = 323", + "signature": "EsUFCkYICxgCKkAnODd4PdhUxMLqu22G9c3tMkOjFSSENuRRZ2ByZwrTTnOPVzlgFlSb07WVM4fkNQWRL+HQW6Sa92QmizG9a4w+Egxp8ECwLs0DYAAfoGwaDHSL7ulnOrb+ToEFTSIweI7AyqUtDgqaXgMcB7LXIx0rtAb4m8/CEzcO5QoalHVTuowRTxaWjSeScouRN1Z5KqwEuYzsnig6MJER60OSnZz+TaJL+/VCgqgsfCYrbBhshsFrYFwLgce2s/eLMPRtC+5gTz3JFDgQmoMYSw4O7FUP3jrHu73RMFXEqo5sWtLK2Rr9UF9ovU3HFIawAK1jC0TJ3zyupJ616mNRILu0xeEc35u5RcYIr9UITAhlrpknJCKlGnll2OGUWe7Bs0ygixflZ4CiF6oHH+AIdrnAnU1TxVbF3r2IpufWpA0B20f3/P6Z6eHgGdBVnlfIhFXMjEvDO+nUw48mXt9v8SwffMWVM02yOsdKGNiPr7EQ4cgMKXEswpzX1O4rjTUejhjZqQmu4hWBf8p/hiOeyda7wJ355kX1a5V0uYyZ+fPNO1ZbRUz4SDtw/f81lC6DiedD6WebSflRHFmryf1TpCmzS0I/s8TVwLRrCY4jnHWXA2be41oan48vp/7mhy2aNnZYDp8dNLmmgIWYddU8899AINccZDi5Yj1Th9A/GFtCJXWUkIKkOJopritOmydTWRAqnopTHZ/gpjIxXDM9u8fSiIRUKbWVz0lobVNobrOjsqkG0x8Eg7UMbaduLyOAqRwaTJZY2jNpcmrArH+8LI+HGCxYXPbvrXsPJxHjkY+vrehTrAtJGA8KdNhxisn7cwf1UOUiPtXQI6+iW157UhTWwrhXKIDEwKui5hXEUym+2HfB/peEqY1Nwt/vquU2Wtn6ki3kHtc5vcK1WVic/lven6v+mucecLa145Hm/OpZVhgB" }, { "type": "text", - "text": "I need to calculate 17 \u00d7 19.\n\nLet me use the distributive property to make this easier:\n17 \u00d7 19 = 17 \u00d7 (20 - 1) = 17 \u00d7 20 - 17 \u00d7 1\n\n17 \u00d7 20 = 340\n17 \u00d7 1 = 17\n\nSo: 340 - 17 = 323\n\nTherefore, 17 \u00d7 19 = 323." + "text": "I need to calculate 17 \u00d7 19.\n\nLet me break this down using the distributive property:\n17 \u00d7 19 = 17 \u00d7 (20 - 1)\n= 17 \u00d7 20 - 17 \u00d7 1\n= 340 - 17\n= 323\n\nLet me verify with standard multiplication:\n```\n 17\n\u00d7 19\n-----\n 153 (17 \u00d7 9)\n 170 (17 \u00d7 1, shifted one place)\n-----\n 323\n```\n\nTherefore, 17 \u00d7 19 = 323." } ], "stop_reason": "end_turn", @@ -85,14 +85,14 @@ interactions: "ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0 }, - "output_tokens": 378, + "output_tokens": 417, "service_tier": "standard", "inference_geo": "not_available" } } headers: CF-RAY: - - 9d029e2d5f104337-EWR + - 9d3b38d21818f3bb-EWR Connection: - keep-alive Content-Security-Policy: @@ -100,7 +100,7 @@ interactions: Content-Type: - application/json Date: - - Thu, 19 Feb 2026 03:18:41 GMT + - Thu, 26 Feb 2026 00:10:59 GMT Server: - cloudflare Transfer-Encoding: @@ -112,35 +112,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-19T03:18:37Z' + - '2026-02-26T00:10:54Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-19T03:18:41Z' + - '2026-02-26T00:10:59Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-19T03:18:36Z' + - '2026-02-26T00:10:53Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-19T03:18:37Z' + - '2026-02-26T00:10:54Z' cf-cache-status: - DYNAMIC content-length: - - '2165' + - '2342' request-id: - - req_011CYGhqRT49PCBrV4e9s65s + - req_011CYViBa3b8ctAu7Xkm6zNL strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '5185' + - '6252' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml index 04ee4860f6..7c3de9606b 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml @@ -78,13 +78,13 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_01BbgL8QuxD4kEF5UNmv3tQQ", + "id": "msg_019yWjxTF7xZwvSo32EGeLRe", "type": "message", "role": "assistant", "content": [ { "type": "tool_use", - "id": "toolu_012aj769msPHQ9EULAXN6d4z", + "id": "toolu_01Hqe6XnkTWQkryxNHtk8kTw", "name": "get_weather", "input": { "city": "San Francisco" @@ -111,7 +111,7 @@ interactions: } headers: CF-RAY: - - 9d029e22de730cb2-EWR + - 9d3b38c7fae6a0fb-EWR Connection: - keep-alive Content-Security-Policy: @@ -119,7 +119,7 @@ interactions: Content-Type: - application/json Date: - - Thu, 19 Feb 2026 03:18:36 GMT + - Thu, 26 Feb 2026 00:10:52 GMT Server: - cloudflare Transfer-Encoding: @@ -131,35 +131,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-19T03:18:36Z' + - '2026-02-26T00:10:52Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-19T03:18:36Z' + - '2026-02-26T00:10:52Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-19T03:18:34Z' + - '2026-02-26T00:10:51Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-19T03:18:36Z' + - '2026-02-26T00:10:52Z' cf-cache-status: - DYNAMIC content-length: - '550' request-id: - - req_011CYGhqJJSMHstMWe9qB2hE + - req_011CYViBT9c3zdmSZzK2BRk4 strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1511' + - '1422' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml index 6e4b730c7e..e3f7868551 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml @@ -57,7 +57,7 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_01VRcbGg6sG2yDjYRqx3a9qb", + "id": "msg_01GGtjbGqbadf1kdUv24ce2F", "type": "message", "role": "assistant", "content": [ @@ -83,7 +83,7 @@ interactions: } headers: CF-RAY: - - 9d029e56d8310e82-EWR + - 9d3b392fbbfe583f-EWR Connection: - keep-alive Content-Security-Policy: @@ -91,7 +91,7 @@ interactions: Content-Type: - application/json Date: - - Thu, 19 Feb 2026 03:18:44 GMT + - Thu, 26 Feb 2026 00:11:09 GMT Server: - cloudflare Transfer-Encoding: @@ -103,35 +103,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-19T03:18:44Z' + - '2026-02-26T00:11:09Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-19T03:18:44Z' + - '2026-02-26T00:11:09Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-19T03:18:43Z' + - '2026-02-26T00:11:08Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-19T03:18:44Z' + - '2026-02-26T00:11:09Z' cf-cache-status: - DYNAMIC content-length: - '441' request-id: - - req_011CYGhqurMQzX7ZdQY5zit6 + - req_011CYViCg7zFhWkmNGucF9FG strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1456' + - '1114' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_instrumentation_error_swallowed.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_instrumentation_error_swallowed.yaml new file mode 100644 index 0000000000..9fdad5a8b0 --- /dev/null +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_instrumentation_error_swallowed.yaml @@ -0,0 +1,134 @@ +interactions: +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01DJ9j2gWyEJVviKj7Q6pgjv","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9d3b3927ecd24396-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Thu, 26 Feb 2026 00:11:07 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-26T00:11:06Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-26T00:11:06Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-26T00:11:06Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-26T00:11:06Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CYViCak2u4rCZvC1rFVaF + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '925' + status: + code: 200 + message: OK +version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml index e1854639df..2e0d6e8055 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml @@ -57,7 +57,7 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_012NCVGZiy8NSkEv21ZvbeqM", + "id": "msg_018voDg2j9DfJRDo9cqg7Lzs", "type": "message", "role": "assistant", "content": [ @@ -83,7 +83,7 @@ interactions: } headers: CF-RAY: - - 9d029de2fb8041e9-EWR + - 9d3b3887cee5ccb6-EWR Connection: - keep-alive Content-Security-Policy: @@ -91,7 +91,7 @@ interactions: Content-Type: - application/json Date: - - Thu, 19 Feb 2026 03:18:25 GMT + - Thu, 26 Feb 2026 00:10:42 GMT Server: - cloudflare Transfer-Encoding: @@ -103,35 +103,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-19T03:18:25Z' + - '2026-02-26T00:10:42Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-19T03:18:25Z' + - '2026-02-26T00:10:42Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-19T03:18:24Z' + - '2026-02-26T00:10:41Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-19T03:18:25Z' + - '2026-02-26T00:10:42Z' cf-cache-status: - DYNAMIC content-length: - '464' request-id: - - req_011CYGhpYaPsv6SGrGNRBWpP + - req_011CYViAhDAfDMmNJMVgE6iV strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1245' + - '1292' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stream_propagation_error.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stream_propagation_error.yaml new file mode 100644 index 0000000000..2c1dc0200a --- /dev/null +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stream_propagation_error.yaml @@ -0,0 +1,134 @@ +interactions: +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01PimXT91pHrfmpMZo4yfBUK","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop"} + + headers: + CF-RAY: + - 9d3b39167de86d50-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Thu, 26 Feb 2026 00:11:05 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-26T00:11:04Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-26T00:11:04Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-26T00:11:04Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-26T00:11:04Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CYViCNoCLnN2DGG7MPDTD + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '964' + status: + code: 200 + message: OK +version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml index 59d7614a83..cb85df54b0 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml @@ -57,29 +57,29 @@ interactions: body: string: |+ event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_013BkEEt2ex79CpGTK17p2nv","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01Ljp7MtYoLaeYxJ4JktUEhe","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } event: ping data: {"type": "ping"} event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } event: content_block_stop - data: {"type":"content_block_stop","index":0 } + data: {"type":"content_block_stop","index":0 } event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } event: message_stop - data: {"type":"message_stop" } + data: {"type":"message_stop" } headers: CF-RAY: - - 9d029df659ec269c-EWR + - 9d3b389b1f235541-EWR Cache-Control: - no-cache Connection: @@ -89,7 +89,7 @@ interactions: Content-Type: - text/event-stream; charset=utf-8 Date: - - Thu, 19 Feb 2026 03:18:28 GMT + - Thu, 26 Feb 2026 00:10:45 GMT Server: - cloudflare Transfer-Encoding: @@ -101,33 +101,33 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-19T03:18:27Z' + - '2026-02-26T00:10:44Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-19T03:18:27Z' + - '2026-02-26T00:10:44Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-19T03:18:27Z' + - '2026-02-26T00:10:44Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-19T03:18:27Z' + - '2026-02-26T00:10:44Z' cf-cache-status: - DYNAMIC request-id: - - req_011CYGhpmqNWeuQCcAER3zK6 + - req_011CYViAvPfy215EsADmjHTw strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1239' + - '1002' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_aggregates_cache_tokens.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_aggregates_cache_tokens.yaml new file mode 100644 index 0000000000..4cf649ba38 --- /dev/null +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_aggregates_cache_tokens.yaml @@ -0,0 +1,134 @@ +interactions: +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_015SPzdGP6SSWMmVsXzkxPoe","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0 } + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9d3b390e8b8823dd-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Thu, 26 Feb 2026 00:11:03 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-26T00:11:02Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-26T00:11:02Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-26T00:11:02Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-26T00:11:02Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CYViCHMmnHDrnQPoTjub7 + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '967' + status: + code: 200 + message: OK +version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml index 5ae71005fd..57d2f51c5e 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml @@ -57,7 +57,7 @@ interactions: body: string: |+ event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01JM82ym7YEkpf9EYa75JDSg","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_015xcfsHjWyzeJNhLUN2XY1A","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } event: content_block_start data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } @@ -66,20 +66,20 @@ interactions: data: {"type": "ping"} event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello."} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } event: content_block_stop - data: {"type":"content_block_stop","index":0} + data: {"type":"content_block_stop","index":0 } event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } event: message_stop - data: {"type":"message_stop" } + data: {"type":"message_stop" } headers: CF-RAY: - - 9d029e000af99f3b-EWR + - 9d3b38a33bc293b9-EWR Cache-Control: - no-cache Connection: @@ -89,7 +89,7 @@ interactions: Content-Type: - text/event-stream; charset=utf-8 Date: - - Thu, 19 Feb 2026 03:18:30 GMT + - Thu, 26 Feb 2026 00:10:46 GMT Server: - cloudflare Transfer-Encoding: @@ -101,33 +101,33 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-19T03:18:29Z' + - '2026-02-26T00:10:45Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-19T03:18:29Z' + - '2026-02-26T00:10:45Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-19T03:18:29Z' + - '2026-02-26T00:10:45Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-19T03:18:29Z' + - '2026-02-26T00:10:45Z' cf-cache-status: - DYNAMIC request-id: - - req_011CYGhptTUiKkLJS5jVsinx + - req_011CYViB1zWtZDrhgf4gQowM strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1132' + - '1102' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_delegates_response_attribute.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_delegates_response_attribute.yaml index 3519554bec..83ff88ea00 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_delegates_response_attribute.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_delegates_response_attribute.yaml @@ -57,38 +57,38 @@ interactions: body: string: |+ event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01Y7yWx31UWCjCNW9M1pNzgX","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01AfpfPhdXq6t3UGyaDvXBik","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } event: ping data: {"type": "ping"} event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"}} event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" there! How"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"! How"} } event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"} } event: content_block_delta data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" you doing today?"} } event: content_block_stop - data: {"type":"content_block_stop","index":0 } + data: {"type":"content_block_stop","index":0 } event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":12} } + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } event: message_stop - data: {"type":"message_stop" } + data: {"type":"message_stop" } headers: CF-RAY: - - 9d029e11ec7ab3aa-EWR + - 9d3b38b38dc0a10a-EWR Cache-Control: - no-cache Connection: @@ -98,7 +98,7 @@ interactions: Content-Type: - text/event-stream; charset=utf-8 Date: - - Thu, 19 Feb 2026 03:18:32 GMT + - Thu, 26 Feb 2026 00:10:49 GMT Server: - cloudflare Transfer-Encoding: @@ -110,33 +110,33 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-19T03:18:32Z' + - '2026-02-26T00:10:48Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-19T03:18:32Z' + - '2026-02-26T00:10:48Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-19T03:18:32Z' + - '2026-02-26T00:10:48Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-19T03:18:32Z' + - '2026-02-26T00:10:48Z' cf-cache-status: - DYNAMIC request-id: - - req_011CYGhq6hBg2rHwtnkZ3CTA + - req_011CYViBD9EnGW4myALEXtBD strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '920' + - '1029' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml index 903aa5d301..fc34cb691b 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml @@ -57,38 +57,38 @@ interactions: body: string: |+ event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_015ue1pF9o95kVXNnKmwQnx4","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_0121nnwh1G3cPTAEX74JsHTk","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } event: ping data: {"type": "ping"} event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } event: content_block_delta data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"! How"} } event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"} } event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" you doing today?"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" you doing today?"} } event: content_block_stop data: {"type":"content_block_stop","index":0 } event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } event: message_stop - data: {"type":"message_stop" } + data: {"type":"message_stop" } headers: CF-RAY: - - 9d029e09ac68adca-EWR + - 9d3b38ab9a1fed71-EWR Cache-Control: - no-cache Connection: @@ -98,7 +98,7 @@ interactions: Content-Type: - text/event-stream; charset=utf-8 Date: - - Thu, 19 Feb 2026 03:18:31 GMT + - Thu, 26 Feb 2026 00:10:47 GMT Server: - cloudflare Transfer-Encoding: @@ -110,33 +110,33 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-19T03:18:30Z' + - '2026-02-26T00:10:47Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-19T03:18:30Z' + - '2026-02-26T00:10:47Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-19T03:18:30Z' + - '2026-02-26T00:10:47Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-19T03:18:30Z' + - '2026-02-26T00:10:47Z' cf-cache-status: - DYNAMIC request-id: - - req_011CYGhq14bvWmjvRbWXvVJu + - req_011CYViB7iojRRL4v9f2JaEX strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '968' + - '857' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_user_exception.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_user_exception.yaml new file mode 100644 index 0000000000..b911864f70 --- /dev/null +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_user_exception.yaml @@ -0,0 +1,134 @@ +interactions: +- request: + body: |- + { + "max_tokens": 100, + "messages": [ + { + "role": "user", + "content": "Say hello in one word." + } + ], + "model": "claude-sonnet-4-20250514", + "stream": true + } + headers: + accept: + - application/json + accept-encoding: + - gzip, deflate + anthropic-version: + - '2023-06-01' + connection: + - keep-alive + content-length: + - '131' + content-type: + - application/json + host: + - api.anthropic.com + user-agent: + - Anthropic/Python 0.75.0 + x-api-key: + - test_anthropic_api_key + x-stainless-arch: + - arm64 + x-stainless-async: + - 'false' + x-stainless-lang: + - python + x-stainless-os: + - MacOS + x-stainless-package-version: + - 0.75.0 + x-stainless-read-timeout: + - '600' + x-stainless-retry-count: + - '0' + x-stainless-runtime: + - CPython + x-stainless-runtime-version: + - 3.9.6 + x-stainless-timeout: + - NOT_GIVEN + method: POST + uri: https://api.anthropic.com/v1/messages + response: + body: + string: |+ + event: message_start + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_014oR3DpZKsLw65binJNTdxe","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":5,"service_tier":"standard","inference_geo":"not_available"}} } + + event: content_block_start + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + + event: ping + data: {"type": "ping"} + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + + event: content_block_stop + data: {"type":"content_block_stop","index":0} + + event: message_delta + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + + event: message_stop + data: {"type":"message_stop" } + + headers: + CF-RAY: + - 9d3b391e6c42b734-EWR + Cache-Control: + - no-cache + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none'; frame-ancestors 'none' + Content-Type: + - text/event-stream; charset=utf-8 + Date: + - Thu, 26 Feb 2026 00:11:06 GMT + Server: + - cloudflare + Transfer-Encoding: + - chunked + X-Robots-Tag: + - none + anthropic-ratelimit-input-tokens-limit: + - '450000' + anthropic-ratelimit-input-tokens-remaining: + - '450000' + anthropic-ratelimit-input-tokens-reset: + - '2026-02-26T00:11:05Z' + anthropic-ratelimit-output-tokens-limit: + - '90000' + anthropic-ratelimit-output-tokens-remaining: + - '90000' + anthropic-ratelimit-output-tokens-reset: + - '2026-02-26T00:11:05Z' + anthropic-ratelimit-requests-limit: + - '1000' + anthropic-ratelimit-requests-remaining: + - '999' + anthropic-ratelimit-requests-reset: + - '2026-02-26T00:11:05Z' + anthropic-ratelimit-tokens-limit: + - '540000' + anthropic-ratelimit-tokens-remaining: + - '540000' + anthropic-ratelimit-tokens-reset: + - '2026-02-26T00:11:05Z' + cf-cache-status: + - DYNAMIC + request-id: + - req_011CYViCUG7E3FEZv5dbGhze + strict-transport-security: + - max-age=31536000; includeSubDomains; preload + x-envoy-upstream-service-time: + - '1282' + status: + code: 200 + message: OK +version: 1 diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml index 63ac23ae0f..37fd939ef1 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml @@ -57,7 +57,7 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_01QCqNmmLxxd8VpRtmMJykSg", + "id": "msg_01QwHjvtC6ugf49hNKNXotxJ", "type": "message", "role": "assistant", "content": [ @@ -83,7 +83,7 @@ interactions: } headers: CF-RAY: - - 9d029dd9daad5e73-EWR + - 9d3b387fea1f3ea9-EWR Connection: - keep-alive Content-Security-Policy: @@ -91,7 +91,7 @@ interactions: Content-Type: - application/json Date: - - Thu, 19 Feb 2026 03:18:24 GMT + - Thu, 26 Feb 2026 00:10:41 GMT Server: - cloudflare Transfer-Encoding: @@ -103,35 +103,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-19T03:18:24Z' + - '2026-02-26T00:10:40Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-19T03:18:24Z' + - '2026-02-26T00:10:41Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-19T03:18:23Z' + - '2026-02-26T00:10:40Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-19T03:18:24Z' + - '2026-02-26T00:10:40Z' cf-cache-status: - DYNAMIC content-length: - '449' request-id: - - req_011CYGhpSN6LooGwaddQzbTg + - req_011CYViAbqTfhdQbBTBUpcA6 strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1294' + - '1075' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml index 15353d701b..03ae29b305 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml @@ -63,7 +63,7 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_01EEc9oeAcYNQNRBEvJjssPz", + "id": "msg_01YLYw2WP65AdfrhVYQHxknf", "type": "message", "role": "assistant", "content": [ @@ -89,7 +89,7 @@ interactions: } headers: CF-RAY: - - 9d029dd1bff5488c-EWR + - 9d3b387668c69175-EWR Connection: - keep-alive Content-Security-Policy: @@ -97,7 +97,7 @@ interactions: Content-Type: - application/json Date: - - Thu, 19 Feb 2026 03:18:22 GMT + - Thu, 26 Feb 2026 00:10:39 GMT Server: - cloudflare Transfer-Encoding: @@ -109,35 +109,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-19T03:18:22Z' + - '2026-02-26T00:10:39Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-19T03:18:22Z' + - '2026-02-26T00:10:39Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-19T03:18:21Z' + - '2026-02-26T00:10:38Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-19T03:18:22Z' + - '2026-02-26T00:10:39Z' cf-cache-status: - DYNAMIC content-length: - '467' request-id: - - req_011CYGhpLoUa14drYiMctTHg + - req_011CYViAVL3Y2XRNdwzAJwav strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1151' + - '1346' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py index 4797cffd5e..96ae23fd17 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py @@ -18,16 +18,18 @@ import json import os from pathlib import Path -from types import SimpleNamespace import pytest from anthropic import Anthropic, APIConnectionError, NotFoundError from anthropic.resources.messages import Messages as _Messages from opentelemetry.instrumentation.anthropic import AnthropicInstrumentor +from opentelemetry.instrumentation.anthropic.messages_extractors import ( + GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS, + GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS, +) from opentelemetry.instrumentation.anthropic.wrappers import ( MessagesStreamWrapper, - MessageWrapper, ) from opentelemetry.semconv._incubating.attributes import ( error_attributes as ErrorAttributes, @@ -38,7 +40,6 @@ from opentelemetry.semconv._incubating.attributes import ( server_attributes as ServerAttributes, ) -from opentelemetry.util.genai.types import LLMInvocation # Detect whether the installed anthropic SDK supports tools / thinking params. # Older SDK versions (e.g. 0.16.0) do not accept these keyword arguments. @@ -697,104 +698,212 @@ def test_stream_wrapper_finalize_idempotent( # pylint: disable=too-many-locals ) -def test_message_wrapper_aggregates_cache_tokens(): - """MessageWrapper should aggregate cache token fields into input tokens.""" +@pytest.mark.vcr() +def test_sync_messages_create_aggregates_cache_tokens( + span_exporter, anthropic_client, instrument_no_content +): + """Non-streaming response with non-zero cache tokens aggregates correctly.""" + model = "claude-sonnet-4-20250514" + messages = [{"role": "user", "content": "Say hello in one word."}] - usage = SimpleNamespace( - input_tokens=10, - cache_creation_input_tokens=3, - cache_read_input_tokens=7, - output_tokens=5, - ) - message = SimpleNamespace( - model="claude-sonnet-4-20250514", - id="msg_123", - stop_reason="end_turn", - usage=usage, - ) - invocation = LLMInvocation( - request_model="claude-sonnet-4-20250514", - provider="anthropic", + response = anthropic_client.messages.create( + model=model, + max_tokens=100, + messages=messages, ) - MessageWrapper(message, capture_content=False).extract_into(invocation) # type: ignore[arg-type] + spans = span_exporter.get_finished_spans() + assert len(spans) == 1 + span = spans[0] - assert invocation.input_tokens == 20 - assert invocation.output_tokens == 5 - assert invocation.finish_reasons == ["stop"] assert ( - invocation.attributes["gen_ai.usage.cache_creation.input_tokens"] == 3 + GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS in span.attributes + ) + assert GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS in span.attributes + assert span.attributes[ + GenAIAttributes.GEN_AI_USAGE_INPUT_TOKENS + ] == expected_input_tokens(response.usage) + assert ( + span.attributes[GenAIAttributes.GEN_AI_USAGE_OUTPUT_TOKENS] + == response.usage.output_tokens + ) + cache_creation = getattr(response.usage, "cache_creation_input_tokens", 0) + cache_read = getattr(response.usage, "cache_read_input_tokens", 0) + assert ( + span.attributes[GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS] + == cache_creation ) - assert invocation.attributes["gen_ai.usage.cache_read.input_tokens"] == 7 + assert span.attributes[GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS] == cache_read + +@pytest.mark.vcr() +def test_sync_messages_create_streaming_aggregates_cache_tokens( + span_exporter, anthropic_client, instrument_no_content +): + """Streaming response with non-zero cache tokens aggregates correctly.""" + model = "claude-sonnet-4-20250514" + messages = [{"role": "user", "content": "Say hello in one word."}] -def test_stream_wrapper_aggregates_cache_tokens(): - """MessagesStreamWrapper should aggregate cache token fields.""" + input_tokens = None + output_tokens = None + cache_creation = None + cache_read = None - class FakeHandler: - def stop_llm(self, invocation): # pylint: disable=no-self-use - return invocation + with anthropic_client.messages.create( + model=model, + max_tokens=100, + messages=messages, + stream=True, + ) as stream: + for chunk in stream: + if chunk.type == "message_delta": + usage = getattr(chunk, "usage", None) + if usage: + input_tokens = expected_input_tokens(usage) + output_tokens = getattr(usage, "output_tokens", None) + cache_creation = getattr( + usage, "cache_creation_input_tokens", None + ) + cache_read = getattr( + usage, "cache_read_input_tokens", None + ) - def fail_llm(self, invocation, error): # pylint: disable=no-self-use - return invocation + spans = span_exporter.get_finished_spans() + assert len(spans) == 1 + span = spans[0] - message_start = SimpleNamespace( - type="message_start", - message=SimpleNamespace( - id="msg_1", - model="claude-sonnet-4-20250514", - usage=SimpleNamespace( - input_tokens=9, - cache_creation_input_tokens=1, - cache_read_input_tokens=2, - ), - ), + assert ( + GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS in span.attributes + ) + assert GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS in span.attributes + assert ( + span.attributes[GenAIAttributes.GEN_AI_USAGE_INPUT_TOKENS] + == input_tokens + ) + assert ( + span.attributes[GenAIAttributes.GEN_AI_USAGE_OUTPUT_TOKENS] + == output_tokens + ) + assert ( + span.attributes[GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS] + == cache_creation ) - message_delta = SimpleNamespace( - type="message_delta", - delta=SimpleNamespace(stop_reason="end_turn"), - usage=SimpleNamespace( - input_tokens=10, - cache_creation_input_tokens=3, - cache_read_input_tokens=4, - output_tokens=8, - ), + assert ( + span.attributes[GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS] == cache_read + ) + + +@pytest.mark.vcr() +def test_sync_messages_create_stream_propagation_error( + span_exporter, anthropic_client, instrument_no_content, monkeypatch +): + """Mid-stream errors from the underlying iterator must propagate and record error on span.""" + model = "claude-sonnet-4-20250514" + messages = [{"role": "user", "content": "Say hello in one word."}] + + stream = anthropic_client.messages.create( + model=model, + max_tokens=100, + messages=messages, + stream=True, ) - class FakeStream: - def __init__(self): - self._chunks = [message_start, message_delta] - self._index = 0 + # Wrap the underlying stream so we inject an iteration error but still + # delegate close()/other behavior to the real stream. + class ErrorInjectingStreamDelegate: + def __init__(self, inner): + self._inner = inner + self._count = 0 def __iter__(self): return self def __next__(self): - if self._index >= len(self._chunks): - raise StopIteration - value = self._chunks[self._index] - self._index += 1 - return value + # Fail after yielding one chunk so this exercises a mid-stream error. + if self._count == 1: + raise ConnectionError("connection reset during stream") + self._count += 1 + return next(self._inner) - def close(self): # pylint: disable=no-self-use - return None + def close(self): + return self._inner.close() - invocation = LLMInvocation( - request_model="claude-sonnet-4-20250514", - provider="anthropic", - ) - wrapper = MessagesStreamWrapper( # type: ignore[arg-type] - FakeStream(), FakeHandler(), invocation, capture_content=False + def __getattr__(self, name): + return getattr(self._inner, name) + + monkeypatch.setattr( + stream, "_stream", ErrorInjectingStreamDelegate(stream._stream) ) - list(wrapper) - assert invocation.input_tokens == 17 - assert invocation.output_tokens == 8 - assert invocation.finish_reasons == ["stop"] - assert ( - invocation.attributes["gen_ai.usage.cache_creation.input_tokens"] == 3 + with pytest.raises( + ConnectionError, match="connection reset during stream" + ): + with stream: + for _ in stream: + pass + + spans = span_exporter.get_finished_spans() + assert len(spans) == 1 + span = spans[0] + assert span.attributes[GenAIAttributes.GEN_AI_REQUEST_MODEL] == model + assert span.attributes[ErrorAttributes.ERROR_TYPE] == "ConnectionError" + + +@pytest.mark.vcr() +def test_sync_messages_create_streaming_user_exception( + span_exporter, anthropic_client, instrument_no_content +): + """Test that user raised exceptions are propagated.""" + model = "claude-sonnet-4-20250514" + messages = [{"role": "user", "content": "Say hello in one word."}] + + with pytest.raises(ValueError, match="User raised exception"): + with anthropic_client.messages.create( + model=model, + max_tokens=100, + messages=messages, + stream=True, + ) as stream: + for _ in stream: + raise ValueError("User raised exception") + + spans = span_exporter.get_finished_spans() + assert len(spans) == 1 + span = spans[0] + assert span.attributes[GenAIAttributes.GEN_AI_REQUEST_MODEL] == model + assert span.attributes[ErrorAttributes.ERROR_TYPE] == "ValueError" + + +@pytest.mark.vcr() +def test_sync_messages_create_instrumentation_error_swallowed( + span_exporter, anthropic_client, instrument_no_content, monkeypatch +): + """Instrumentation errors in _process_chunk must not propagate to user code.""" + model = "claude-sonnet-4-20250514" + messages = [{"role": "user", "content": "Say hello in one word."}] + + def exploding_process_chunk(self, chunk): + raise RuntimeError("instrumentation bug") + + monkeypatch.setattr( + MessagesStreamWrapper, "_process_chunk", exploding_process_chunk ) - assert invocation.attributes["gen_ai.usage.cache_read.input_tokens"] == 4 + + with anthropic_client.messages.create( + model=model, + max_tokens=100, + messages=messages, + stream=True, + ) as stream: + chunks = list(stream) + + assert len(chunks) > 0 + + spans = span_exporter.get_finished_spans() + assert len(spans) == 1 + span = spans[0] + assert span.attributes[GenAIAttributes.GEN_AI_REQUEST_MODEL] == model + assert ErrorAttributes.ERROR_TYPE not in span.attributes # ============================================================================= From d1bf3fe1c9d3396646bffd57a7c970c232a12d71 Mon Sep 17 00:00:00 2001 From: Teja Date: Wed, 25 Feb 2026 19:14:35 -0500 Subject: [PATCH 30/35] Refactor assertions in test_sync_messages.py for improved readability. Simplify assertion statements by removing unnecessary parentheses, enhancing code clarity in cache token tests. --- .../tests/test_sync_messages.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py index 96ae23fd17..6bce6f2e16 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/test_sync_messages.py @@ -716,9 +716,7 @@ def test_sync_messages_create_aggregates_cache_tokens( assert len(spans) == 1 span = spans[0] - assert ( - GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS in span.attributes - ) + assert GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS in span.attributes assert GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS in span.attributes assert span.attributes[ GenAIAttributes.GEN_AI_USAGE_INPUT_TOKENS @@ -772,9 +770,7 @@ def test_sync_messages_create_streaming_aggregates_cache_tokens( assert len(spans) == 1 span = spans[0] - assert ( - GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS in span.attributes - ) + assert GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS in span.attributes assert GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS in span.attributes assert ( span.attributes[GenAIAttributes.GEN_AI_USAGE_INPUT_TOKENS] @@ -788,9 +784,7 @@ def test_sync_messages_create_streaming_aggregates_cache_tokens( span.attributes[GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS] == cache_creation ) - assert ( - span.attributes[GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS] == cache_read - ) + assert span.attributes[GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS] == cache_read @pytest.mark.vcr() From 0dc8a9fa0ecc339c34a20786e6087dd2546e4bbe Mon Sep 17 00:00:00 2001 From: Teja Date: Thu, 26 Feb 2026 18:35:36 -0500 Subject: [PATCH 31/35] enforce strong typing system. --- .../anthropic/messages_extractors.py | 47 +-- .../instrumentation/anthropic/utils.py | 305 ++++++++++-------- .../instrumentation/anthropic/wrappers.py | 46 ++- ...st_stream_wrapper_finalize_idempotent.yaml | 32 +- ...ssages_create_aggregates_cache_tokens.yaml | 18 +- .../test_sync_messages_create_api_error.yaml | 10 +- .../test_sync_messages_create_basic.yaml | 18 +- ...sync_messages_create_captures_content.yaml | 18 +- ...ages_create_captures_thinking_content.yaml | 28 +- ...ages_create_captures_tool_use_content.yaml | 20 +- ..._create_event_only_no_content_in_span.yaml | 18 +- ...reate_instrumentation_error_swallowed.yaml | 32 +- ...test_sync_messages_create_stop_reason.yaml | 18 +- ...sages_create_stream_propagation_error.yaml | 32 +- .../test_sync_messages_create_streaming.yaml | 30 +- ...ate_streaming_aggregates_cache_tokens.yaml | 32 +- ...ges_create_streaming_captures_content.yaml | 30 +- ...treaming_delegates_response_attribute.yaml | 41 ++- ...c_messages_create_streaming_iteration.yaml | 36 ++- ...sages_create_streaming_user_exception.yaml | 32 +- ...test_sync_messages_create_token_usage.yaml | 18 +- ..._sync_messages_create_with_all_params.yaml | 24 +- 22 files changed, 466 insertions(+), 419 deletions(-) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/messages_extractors.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/messages_extractors.py index acfdffb093..319ed183cb 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/messages_extractors.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/messages_extractors.py @@ -17,8 +17,7 @@ from __future__ import annotations from dataclasses import dataclass -from typing import TYPE_CHECKING, Optional, Sequence -from urllib.parse import urlparse +from typing import TYPE_CHECKING, Sequence from anthropic.types import MessageDeltaUsage @@ -36,9 +35,6 @@ from opentelemetry.util.types import AttributeValue from .utils import ( - _as_str, - _get_field, - as_int, convert_content_to_parts, normalize_finish_reason, ) @@ -85,14 +81,10 @@ def extract_usage_tokens( if usage is None: return None, None, None, None - input_tokens = as_int(getattr(usage, "input_tokens", None)) - cache_creation_input_tokens = as_int( - getattr(usage, "cache_creation_input_tokens", None) - ) - cache_read_input_tokens = as_int( - getattr(usage, "cache_read_input_tokens", None) - ) - output_tokens = as_int(getattr(usage, "output_tokens", None)) + input_tokens = usage.input_tokens + output_tokens = usage.output_tokens + cache_creation_input_tokens = usage.cache_creation_input_tokens + cache_read_input_tokens = usage.cache_read_input_tokens if ( input_tokens is None @@ -122,8 +114,8 @@ def get_input_messages( return [] result: list[InputMessage] = [] for message in messages: - role = _as_str(_get_field(message, "role")) or "user" - parts = convert_content_to_parts(_get_field(message, "content")) + role = message["role"] + parts = convert_content_to_parts(message["content"]) result.append(InputMessage(role=role, parts=parts)) return result @@ -142,11 +134,11 @@ def get_output_messages_from_message( if message is None: return [] - parts = convert_content_to_parts(_get_field(message, "content")) - finish_reason = normalize_finish_reason(_get_field(message, "stop_reason")) + parts = convert_content_to_parts(message.content) + finish_reason = normalize_finish_reason(message.stop_reason) return [ OutputMessage( - role=_as_str(_get_field(message, "role")) or "assistant", + role=message.role, parts=parts, finish_reason=finish_reason or "", ) @@ -192,21 +184,12 @@ def _set_server_address_and_port( client_instance: "Messages", attributes: dict[str, AttributeValue | None], ) -> None: - base_client = getattr(client_instance, "_client", None) - base_url = getattr(base_client, "base_url", None) - if not base_url: - return - - port: Optional[int] = None - if hasattr(base_url, "host"): - attributes[ServerAttributes.SERVER_ADDRESS] = base_url.host - port = getattr(base_url, "port", None) - elif isinstance(base_url, str): - url = urlparse(base_url) - if url.hostname is not None: - attributes[ServerAttributes.SERVER_ADDRESS] = url.hostname - port = url.port + base_url = client_instance._client.base_url + host = base_url.host + if host: + attributes[ServerAttributes.SERVER_ADDRESS] = host + port = base_url.port if port and port != 443 and port > 0: attributes[ServerAttributes.SERVER_PORT] = port diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py index 4e26de26da..2b9769d096 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/utils.py @@ -18,7 +18,20 @@ import base64 import json -from typing import Any, cast +from dataclasses import dataclass +from typing import TYPE_CHECKING + +from anthropic.types import ( + InputJSONDelta, + RedactedThinkingBlock, + ServerToolUseBlock, + TextBlock, + TextDelta, + ThinkingBlock, + ThinkingDelta, + ToolUseBlock, + WebSearchToolResultBlock, +) from opentelemetry.util.genai.types import ( Blob, @@ -29,6 +42,26 @@ ToolCallResponse, ) +if TYPE_CHECKING: + from collections.abc import Iterable, Mapping + + from anthropic.types import ( + ContentBlock, + ContentBlockParam, + RawContentBlockDelta, + ) + + +@dataclass +class StreamBlockState: + type: str + text: str = "" + tool_id: str | None = None + tool_name: str = "" + tool_input: dict[str, object] | None = None + input_json: str = "" + thinking: str = "" + def normalize_finish_reason(stop_reason: str | None) -> str | None: if stop_reason is None: @@ -42,167 +75,167 @@ def normalize_finish_reason(stop_reason: str | None) -> str | None: return normalized or stop_reason -def _get_field(obj: Any, name: str, default: Any = None) -> Any: - if isinstance(obj, dict): - return cast(dict[str, Any], obj).get(name, default) - return getattr(obj, name, default) +def _decode_base64(data: str) -> bytes | None: + try: + return base64.b64decode(data) + except Exception: # pylint: disable=broad-exception-caught + return None -def _as_str(value: Any) -> str | None: - if value is None: +def _extract_base64_blob(source: object, modality: str) -> Blob | None: + """Extract a Blob from a base64-encoded source dict.""" + if not isinstance(source, dict): + return None + # source is a TypedDict (e.g. Base64ImageSourceParam) narrowed to dict; + # pyright cannot infer value types from isinstance-narrowed dicts. + data: object = source.get("data") # type: ignore[reportUnknownMemberType] + if not isinstance(data, str): return None - if isinstance(value, str): - return value - return str(value) + decoded = _decode_base64(data) + if decoded is None: + return None + media_type: object = source.get("media_type") # type: ignore[reportUnknownMemberType] + return Blob( + mime_type=media_type if isinstance(media_type, str) else None, + modality=modality, + content=decoded, + ) -def as_int(value: Any) -> int | None: - if isinstance(value, bool): - return None - if isinstance(value, int): - return value - return None +def _convert_dict_block_to_part( + block: Mapping[str, object], +) -> MessagePart | None: + """Convert a request-param content block (TypedDict/dict) to a MessagePart.""" + block_type = block.get("type") + if block_type == "text": + text = block.get("text") + return Text(content=str(text) if text is not None else "") -def _to_dict_if_possible(value: Any) -> Any: - if isinstance(value, dict): - return cast(dict[str, Any], value) - if hasattr(value, "to_dict"): - to_dict = getattr(value, "to_dict") - if callable(to_dict): - try: - return to_dict() - except Exception: # pylint: disable=broad-exception-caught - return value - if hasattr(value, "__dict__"): - return cast(dict[str, Any], dict(value.__dict__)) - return value + if block_type == "tool_use": + inp = block.get("input") + return ToolCall( + arguments=inp if isinstance(inp, dict) else None, + name=str(block.get("name", "")), + id=str(block.get("id", "")), + ) + if block_type == "tool_result": + return ToolCallResponse( + response=block.get("content"), + id=str(block.get("tool_use_id", "")), + ) -def _decode_base64(data: str | None) -> bytes | None: - if not data: - return None - try: - return base64.b64decode(data) - except Exception: # pylint: disable=broad-exception-caught - return None + if block_type in ("thinking", "redacted_thinking"): + thinking = block.get("thinking") or block.get("data") + return Reasoning(content=str(thinking) if thinking is not None else "") + if block_type in ("image", "audio", "video", "document", "file"): + return _extract_base64_blob(block.get("source"), str(block_type)) -def _convert_content_block_to_part(content_block: Any) -> MessagePart | None: - block_type = _as_str(_get_field(content_block, "type")) - if block_type is None: - return None + return None - result: MessagePart | None = None - if block_type == "text": - text = _as_str(_get_field(content_block, "text")) - result = Text(content=text or "") - elif block_type == "tool_use": - result = ToolCall( - arguments=_to_dict_if_possible(_get_field(content_block, "input")), - name=_as_str(_get_field(content_block, "name")) or "", - id=_as_str(_get_field(content_block, "id")), + +def _convert_content_block_to_part( + block: ContentBlock | ContentBlockParam, +) -> MessagePart | None: + """Convert an Anthropic content block to a MessagePart.""" + if isinstance(block, TextBlock): + return Text(content=block.text) + + if isinstance(block, (ToolUseBlock, ServerToolUseBlock)): + return ToolCall(arguments=block.input, name=block.name, id=block.id) + + if isinstance(block, (ThinkingBlock, RedactedThinkingBlock)): + content = ( + block.thinking if isinstance(block, ThinkingBlock) else block.data ) - elif block_type == "tool_result": - result = ToolCallResponse( - response=_to_dict_if_possible( - _get_field(content_block, "content") - ), - id=_as_str(_get_field(content_block, "tool_use_id")), + return Reasoning(content=content) + + if isinstance(block, WebSearchToolResultBlock): + return ToolCallResponse( + response=block.model_dump().get("content"), + id=block.tool_use_id, ) - elif block_type in ("thinking", "redacted_thinking"): - content = _as_str(_get_field(content_block, "thinking")) - if content is None: - content = _as_str(_get_field(content_block, "data")) - result = Reasoning(content=content or "") - elif block_type in ("image", "audio", "video", "document", "file"): - source = _get_field(content_block, "source") - mime_type = _as_str(_get_field(source, "media_type")) - raw_data = _as_str(_get_field(source, "data")) - data = _decode_base64(raw_data) - if data is not None: - modality = _as_str(_get_field(content_block, "type")) or "file" - result = Blob(mime_type=mime_type, modality=modality, content=data) - else: - result = _to_dict_if_possible(content_block) - - return result - - -def convert_content_to_parts(content: Any) -> list[MessagePart]: + + # ContentBlockParam variants are TypedDicts (dicts at runtime); + # newer SDK versions may add Pydantic block types not handled above. + if isinstance(block, dict): + return _convert_dict_block_to_part(block) + + return None + + +def convert_content_to_parts( + content: str | Iterable[ContentBlock | ContentBlockParam] | None, +) -> list[MessagePart]: if content is None: return [] if isinstance(content, str): return [Text(content=content)] - if isinstance(content, list): - parts: list[MessagePart] = [] - for item in cast(list[Any], content): - part = _convert_content_block_to_part(item) - if part is not None: - parts.append(part) - return parts - part = _convert_content_block_to_part(content) - return [part] if part is not None else [] - - -def create_stream_block_state(content_block: Any) -> dict[str, Any]: - block_type = _as_str(_get_field(content_block, "type")) or "text" - state: dict[str, Any] = {"type": block_type} - if block_type == "text": - state["text"] = _as_str(_get_field(content_block, "text")) or "" - elif block_type == "tool_use": - state["id"] = _as_str(_get_field(content_block, "id")) - state["name"] = _as_str(_get_field(content_block, "name")) or "" - state["input"] = _get_field(content_block, "input") - state["input_json"] = "" - elif block_type in ("thinking", "redacted_thinking"): - state["thinking"] = ( - _as_str(_get_field(content_block, "thinking")) or "" + parts: list[MessagePart] = [] + for item in content: + part = _convert_content_block_to_part(item) + if part is not None: + parts.append(part) + return parts + + +def create_stream_block_state(content_block: ContentBlock) -> StreamBlockState: + if isinstance(content_block, TextBlock): + return StreamBlockState(type="text", text=content_block.text) + + if isinstance(content_block, (ToolUseBlock, ServerToolUseBlock)): + return StreamBlockState( + type="tool_use", + tool_id=content_block.id, + tool_name=content_block.name, + tool_input=content_block.input, ) - return state - -def update_stream_block_state(state: dict[str, Any], delta: Any) -> None: - delta_type = _as_str(_get_field(delta, "type")) - if delta_type == "text_delta": - state["type"] = "text" - state["text"] = ( - f"{state.get('text', '')}" - f"{_as_str(_get_field(delta, 'text')) or ''}" - ) - return - if delta_type == "input_json_delta": - state["type"] = "tool_use" - state["input_json"] = ( - f"{state.get('input_json', '')}" - f"{_as_str(_get_field(delta, 'partial_json')) or ''}" - ) - return - if delta_type == "thinking_delta": - state["type"] = "thinking" - state["thinking"] = ( - f"{state.get('thinking', '')}" - f"{_as_str(_get_field(delta, 'thinking')) or ''}" + if isinstance(content_block, ThinkingBlock): + return StreamBlockState( + type="thinking", thinking=content_block.thinking ) + if isinstance(content_block, RedactedThinkingBlock): + return StreamBlockState(type="redacted_thinking") -def stream_block_state_to_part(state: dict[str, Any]) -> MessagePart | None: - block_type = _as_str(state.get("type")) - if block_type == "text": - return Text(content=_as_str(state.get("text")) or "") - if block_type == "tool_use": - arguments: Any = state.get("input") - partial_json = _as_str(state.get("input_json")) - if partial_json: + return StreamBlockState(type=content_block.type) + + +def update_stream_block_state( + state: StreamBlockState, delta: RawContentBlockDelta +) -> None: + if isinstance(delta, TextDelta): + state.type = "text" + state.text += delta.text + elif isinstance(delta, InputJSONDelta): + state.type = "tool_use" + state.input_json += delta.partial_json + elif isinstance(delta, ThinkingDelta): + state.type = "thinking" + state.thinking += delta.thinking + + +def stream_block_state_to_part(state: StreamBlockState) -> MessagePart | None: + if state.type == "text": + return Text(content=state.text) + + if state.type == "tool_use": + arguments: str | dict[str, object] | None = state.tool_input + if state.input_json: try: - arguments = json.loads(partial_json) + arguments = json.loads(state.input_json) except ValueError: - arguments = partial_json + arguments = state.input_json return ToolCall( arguments=arguments, - name=_as_str(state.get("name")) or "", - id=_as_str(state.get("id")), + name=state.tool_name, + id=state.tool_id, ) - if block_type in ("thinking", "redacted_thinking"): - return Reasoning(content=_as_str(state.get("thinking")) or "") + + if state.type in ("thinking", "redacted_thinking"): + return Reasoning(content=state.thinking) + return None diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py index 9d069c96f7..9cea13fca6 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py @@ -33,7 +33,7 @@ get_output_messages_from_message, ) from .utils import ( - _get_field, + StreamBlockState, create_stream_block_state, normalize_finish_reason, stream_block_state_to_part, @@ -122,7 +122,7 @@ def __init__( self._cache_creation_input_tokens: Optional[int] = None self._cache_read_input_tokens: Optional[int] = None self._capture_content = capture_content - self._content_blocks: dict[int, dict[str, object]] = {} + self._content_blocks: dict[int, StreamBlockState] = {} self._finalized = False def _update_usage(self, usage: Usage | MessageDeltaUsage | None) -> None: @@ -145,32 +145,25 @@ def _process_chunk(self, chunk: RawMessageStreamEvent) -> None: """Extract telemetry data from a streaming chunk.""" if chunk.type == "message_start": message = chunk.message - if message: - if hasattr(message, "id") and message.id: - self._response_id = message.id - if hasattr(message, "model") and message.model: - self._response_model = message.model - if hasattr(message, "usage") and message.usage: - self._update_usage(message.usage) + if message.id: + self._response_id = message.id + if message.model: + self._response_model = message.model + self._update_usage(message.usage) elif chunk.type == "message_delta": - delta = chunk.delta - if delta and hasattr(delta, "stop_reason") and delta.stop_reason: - self._stop_reason = normalize_finish_reason(delta.stop_reason) - usage = chunk.usage - self._update_usage(usage) - elif self._capture_content and chunk.type == "content_block_start": - index = _get_field(chunk, "index") - content_block = _get_field(chunk, "content_block") - if isinstance(index, int): - self._content_blocks[index] = create_stream_block_state( - content_block + if chunk.delta.stop_reason: + self._stop_reason = normalize_finish_reason( + chunk.delta.stop_reason ) + self._update_usage(chunk.usage) + elif self._capture_content and chunk.type == "content_block_start": + self._content_blocks[chunk.index] = create_stream_block_state( + chunk.content_block + ) elif self._capture_content and chunk.type == "content_block_delta": - index = _get_field(chunk, "index") - delta = _get_field(chunk, "delta") - if isinstance(index, int) and delta is not None: - block = self._content_blocks.setdefault(index, {}) - update_stream_block_state(block, delta) + block = self._content_blocks.get(chunk.index) + if block is not None: + update_stream_block_state(block, chunk.delta) @staticmethod def _safe_instrumentation( @@ -285,7 +278,6 @@ def __exit__( def close(self) -> None: try: - if hasattr(self._stream, "close"): - self._stream.close() + self._stream.close() finally: self._stop() diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml index b4df860b7f..e6ac40e646 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_stream_wrapper_finalize_idempotent.yaml @@ -57,29 +57,29 @@ interactions: body: string: |+ event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01H6rLTyoXw2bmGDRrqebTks","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01PJ2JUkNkA7g8oZhVFZr4FZ","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } event: ping data: {"type": "ping"} event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello."} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } event: content_block_stop - data: {"type":"content_block_stop","index":0 } + data: {"type":"content_block_stop","index":0 } event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } event: message_stop - data: {"type":"message_stop" } + data: {"type":"message_stop" } headers: CF-RAY: - - 9d3b38fa8f2d31cb-EWR + - 9d43406fcfec1a5c-EWR Cache-Control: - no-cache Connection: @@ -89,7 +89,7 @@ interactions: Content-Type: - text/event-stream; charset=utf-8 Date: - - Thu, 26 Feb 2026 00:11:00 GMT + - Thu, 26 Feb 2026 23:34:12 GMT Server: - cloudflare Transfer-Encoding: @@ -101,33 +101,37 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-26T00:10:59Z' + - '2026-02-26T23:34:11Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-26T00:10:59Z' + - '2026-02-26T23:34:11Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-26T00:10:59Z' + - '2026-02-26T23:34:11Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-26T00:10:59Z' + - '2026-02-26T23:34:11Z' cf-cache-status: - DYNAMIC + content-length: + - '1134' request-id: - - req_011CYViC3gVvbQccjvnUK4qs + - req_011CYXZCAm6y8MuXWCF1YQhY strict-transport-security: - max-age=31536000; includeSubDomains; preload + vary: + - Accept-Encoding x-envoy-upstream-service-time: - - '923' + - '1627' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_aggregates_cache_tokens.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_aggregates_cache_tokens.yaml index a5c55501e2..00d584de8c 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_aggregates_cache_tokens.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_aggregates_cache_tokens.yaml @@ -57,7 +57,7 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_01YM2FALrDv6M4wXGzYmL1NK", + "id": "msg_016rZmFAqBwocMJPynTw59VW", "type": "message", "role": "assistant", "content": [ @@ -83,7 +83,7 @@ interactions: } headers: CF-RAY: - - 9d3b3901ea5a8abe-EWR + - 9d43407bb986c34e-EWR Connection: - keep-alive Content-Security-Policy: @@ -91,7 +91,7 @@ interactions: Content-Type: - application/json Date: - - Thu, 26 Feb 2026 00:11:02 GMT + - Thu, 26 Feb 2026 23:34:14 GMT Server: - cloudflare Transfer-Encoding: @@ -103,35 +103,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-26T00:11:02Z' + - '2026-02-26T23:34:14Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-26T00:11:02Z' + - '2026-02-26T23:34:14Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-26T00:11:01Z' + - '2026-02-26T23:34:13Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-26T00:11:02Z' + - '2026-02-26T23:34:14Z' cf-cache-status: - DYNAMIC content-length: - '441' request-id: - - req_011CYViC8mb2JZhazchQ29qj + - req_011CYXZCJxUVNdTSnXuC8xvk strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1865' + - '1182' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml index 89db81a0f3..d74a78518a 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_api_error.yaml @@ -61,11 +61,11 @@ interactions: "type": "not_found_error", "message": "model: invalid-model-name" }, - "request_id": "req_011CYViAuU7DmHrwTiP5n98M" + "request_id": "req_011CYXZB4QLX5jSBkzfgUcn7" } headers: CF-RAY: - - 9d3b3899bfea151b-EWR + - 9d434011aefdcd7c-EWR Connection: - keep-alive Content-Security-Policy: @@ -73,7 +73,7 @@ interactions: Content-Type: - application/json Date: - - Thu, 26 Feb 2026 00:10:44 GMT + - Thu, 26 Feb 2026 23:33:56 GMT Server: - cloudflare Transfer-Encoding: @@ -85,11 +85,11 @@ interactions: content-length: - '133' request-id: - - req_011CYViAuU7DmHrwTiP5n98M + - req_011CYXZB4QLX5jSBkzfgUcn7 strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '50' + - '66' x-should-retry: - 'false' status: diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml index 72b04ea175..84d567f200 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_basic.yaml @@ -57,7 +57,7 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_01EyT4W1amM9qQRUGKXEQtKE", + "id": "msg_01AaCx2TjLiN5JUc1d8y6yj5", "type": "message", "role": "assistant", "content": [ @@ -83,7 +83,7 @@ interactions: } headers: CF-RAY: - - 9d3b3863dc6058af-EWR + - 9d433fe00fb0012e-EWR Connection: - keep-alive Content-Security-Policy: @@ -91,7 +91,7 @@ interactions: Content-Type: - application/json Date: - - Thu, 26 Feb 2026 00:10:36 GMT + - Thu, 26 Feb 2026 23:33:49 GMT Server: - cloudflare Transfer-Encoding: @@ -103,35 +103,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-26T00:10:36Z' + - '2026-02-26T23:33:49Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-26T00:10:36Z' + - '2026-02-26T23:33:49Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-26T00:10:35Z' + - '2026-02-26T23:33:48Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-26T00:10:36Z' + - '2026-02-26T23:33:49Z' cf-cache-status: - DYNAMIC content-length: - '441' request-id: - - req_011CYViAGeo3XGFByeCrP8XD + - req_011CYXZAUSRcWb3CfyAW5tBH strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1191' + - '1087' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml index 50f6d3ab5a..01f97a8689 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_content.yaml @@ -57,7 +57,7 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_018pm1e8M2sq6wFbuWi66Mzi", + "id": "msg_01MX8SyzXjwPncft5XtVKf8Y", "type": "message", "role": "assistant", "content": [ @@ -83,7 +83,7 @@ interactions: } headers: CF-RAY: - - 9d3b386c6b5920f8-EWR + - 9d433fe86db4c540-EWR Connection: - keep-alive Content-Security-Policy: @@ -91,7 +91,7 @@ interactions: Content-Type: - application/json Date: - - Thu, 26 Feb 2026 00:10:38 GMT + - Thu, 26 Feb 2026 23:33:50 GMT Server: - cloudflare Transfer-Encoding: @@ -103,35 +103,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-26T00:10:37Z' + - '2026-02-26T23:33:50Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-26T00:10:38Z' + - '2026-02-26T23:33:50Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-26T00:10:37Z' + - '2026-02-26T23:33:49Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-26T00:10:37Z' + - '2026-02-26T23:33:50Z' cf-cache-status: - DYNAMIC content-length: - '441' request-id: - - req_011CYViANVXrHMDpqf67PSep + - req_011CYXZAaCSwAhvfCgF262WH strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1449' + - '1031' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml index 70568f92c9..73902b8104 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_thinking_content.yaml @@ -61,18 +61,18 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_01SAeJ8UJd4oULnubnoGU5td", + "id": "msg_01Wr63EVQ99qSimMzVWidt6S", "type": "message", "role": "assistant", "content": [ { "type": "thinking", - "thinking": "I need to calculate 17 * 19.\n\nLet me think about this step by step.\n\nI can use the standard multiplication method:\n17 * 19\n\nOne way is to break this down:\n17 * 19 = 17 * (20 - 1) = 17 * 20 - 17 * 1 = 340 - 17 = 323\n\nLet me double-check this:\n17 * 20 = 340\n17 * 1 = 17\n340 - 17 = 323\n\nOr I can do it the traditional way:\n 17\n \u00d7 19\n ----\n 153 (17 \u00d7 9)\n 170 (17 \u00d7 10)\n ----\n 323\n\nLet me verify the first line: 17 \u00d7 9\n17 \u00d7 9 = 17 \u00d7 (10 - 1) = 170 - 17 = 153 \u2713\n\nAnd 17 \u00d7 10 = 170 \u2713\n\n153 + 170 = 323 \u2713\n\nSo 17 \u00d7 19 = 323", - "signature": "EsUFCkYICxgCKkAnODd4PdhUxMLqu22G9c3tMkOjFSSENuRRZ2ByZwrTTnOPVzlgFlSb07WVM4fkNQWRL+HQW6Sa92QmizG9a4w+Egxp8ECwLs0DYAAfoGwaDHSL7ulnOrb+ToEFTSIweI7AyqUtDgqaXgMcB7LXIx0rtAb4m8/CEzcO5QoalHVTuowRTxaWjSeScouRN1Z5KqwEuYzsnig6MJER60OSnZz+TaJL+/VCgqgsfCYrbBhshsFrYFwLgce2s/eLMPRtC+5gTz3JFDgQmoMYSw4O7FUP3jrHu73RMFXEqo5sWtLK2Rr9UF9ovU3HFIawAK1jC0TJ3zyupJ616mNRILu0xeEc35u5RcYIr9UITAhlrpknJCKlGnll2OGUWe7Bs0ygixflZ4CiF6oHH+AIdrnAnU1TxVbF3r2IpufWpA0B20f3/P6Z6eHgGdBVnlfIhFXMjEvDO+nUw48mXt9v8SwffMWVM02yOsdKGNiPr7EQ4cgMKXEswpzX1O4rjTUejhjZqQmu4hWBf8p/hiOeyda7wJ355kX1a5V0uYyZ+fPNO1ZbRUz4SDtw/f81lC6DiedD6WebSflRHFmryf1TpCmzS0I/s8TVwLRrCY4jnHWXA2be41oan48vp/7mhy2aNnZYDp8dNLmmgIWYddU8899AINccZDi5Yj1Th9A/GFtCJXWUkIKkOJopritOmydTWRAqnopTHZ/gpjIxXDM9u8fSiIRUKbWVz0lobVNobrOjsqkG0x8Eg7UMbaduLyOAqRwaTJZY2jNpcmrArH+8LI+HGCxYXPbvrXsPJxHjkY+vrehTrAtJGA8KdNhxisn7cwf1UOUiPtXQI6+iW157UhTWwrhXKIDEwKui5hXEUym+2HfB/peEqY1Nwt/vquU2Wtn6ki3kHtc5vcK1WVic/lven6v+mucecLa145Hm/OpZVhgB" + "thinking": "I need to calculate 17 * 19.\n\nLet me think about this step by step.\n\nI can use the standard multiplication method:\n17 \u00d7 19\n\nI can break this down:\n17 \u00d7 19 = 17 \u00d7 (20 - 1) = 17 \u00d7 20 - 17 \u00d7 1 = 340 - 17 = 323\n\nOr I can do it the traditional way:\n 17\n\u00d7 19\n----\n 153 (17 \u00d7 9)\n170 (17 \u00d7 10)\n----\n323\n\nLet me double-check the first line: 17 \u00d7 9\n17 \u00d7 9 = 17 \u00d7 (10 - 1) = 170 - 17 = 153 \u2713\n\nAnd 17 \u00d7 10 = 170 \u2713\n\nSo 153 + 170 = 323\n\nLet me verify this another way:\n17 \u00d7 19 = (20 - 3) \u00d7 (20 - 1) = 20\u00b2 - 20 - 3\u00d720 + 3 = 400 - 20 - 60 + 3 = 400 - 80 + 3 = 320 + 3 = 323 \u2713\n\nYes, 17 \u00d7 19 = 323.", + "signature": "EogGCkYICxgCKkAxs8t07yMFiwAaO61FwoyqVpxj3ia/JWKx1cE7b9xqI/c2lYLIGy5eof9e1k5fEUix5OWHCLkCaon0dm5LUBtkEgz/oDM2mTBB27Xx6GYaDDYsQqXAIlkTkWyC0yIwHCKfezWvrT/BpU0Z09wqT19UNXjC0twg31t9lQYBV1/9glQtQgBkU8ml19Qd8JvJKu8EYW3lxaCiu7m0crt48lNhluutl9L6J/OGE9P5AbsQw6oNUY0VmRXSJZTAibR3Hy7IfxDLXFDak2f/K0oK31ouuN19lCoXkL/s64IqrWA5AvXALoKSoCaCv4Rkv1decZgyamVlYnIa4dbDaHlVzMYeO+qm9dG/haPObJ09F5nDhB1dfjggGSZhumLoli5jwN6PKwOH9enwpAymb1pSvbQpcYh3GoCdo0qzrzX3ScIeXZ40Vv6vfn49+glSDFRGUnG4xwv3ikefdSXiUBiuIIsub4oDADMfsZV/1dci03F59p2nEJ52TGGuIkRVNTFOoEzbRpnrdZiCF7zeXdAN8Jfefqrw6hUWrdkaBwVmhiqkpwMEnTfF204ZYSuHMbSwlYcM4GVqZn63htgtPBD132ym0oaPe3w28kJFbDfG0jea9maXn0YtfOc060/tt/ftvGVBXORZENhrt+kbKcczK2IBvRjciqgxUJeqlyyiagY+KWa+qHymO21d+HYG+WEyTTRgHpoz8dAVW2aK3S3AcnU79narB3rqJXQGBfDc/5jo+mzjPV2zBb7NYp6doGNpwEAlkDnPqTzPVNecSwL9/GrrvWYfR0ABKrDPAD2XVCbOpm8pURZSMThSpailrIBz5+WiY/jOVUSjZlR4SMpBsOnXm6/VyxW/XvlJ/YrBkpQnHE1gyZfVN1d1FPFjGUzd2RPH127ThANP+ZDQxCfPZ6L1pIbEDEddehMCLTjkCmqNkQsIxBYsVR3pAGCmCOJtVFc311SpHiryVdmeDnV9PVP096M930a5+O4EdZSX+2PMgRPhpQzc+REpCeoErBPm5kEYAQ==" }, { "type": "text", - "text": "I need to calculate 17 \u00d7 19.\n\nLet me break this down using the distributive property:\n17 \u00d7 19 = 17 \u00d7 (20 - 1)\n= 17 \u00d7 20 - 17 \u00d7 1\n= 340 - 17\n= 323\n\nLet me verify with standard multiplication:\n```\n 17\n\u00d7 19\n-----\n 153 (17 \u00d7 9)\n 170 (17 \u00d7 1, shifted one place)\n-----\n 323\n```\n\nTherefore, 17 \u00d7 19 = 323." + "text": "Looking at 17 \u00d7 19, I'll calculate this step by step.\n\nI can use the method of breaking down one number:\n17 \u00d7 19 = 17 \u00d7 (20 - 1) = (17 \u00d7 20) - (17 \u00d7 1) = 340 - 17 = 323\n\nLet me verify with traditional multiplication:\n```\n 17\n\u00d7 19\n-----\n 153 (17 \u00d7 9)\n 170 (17 \u00d7 10, shifted one place)\n-----\n 323\n```\n\nTherefore, 17 \u00d7 19 = 323." } ], "stop_reason": "end_turn", @@ -85,14 +85,14 @@ interactions: "ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0 }, - "output_tokens": 417, + "output_tokens": 469, "service_tier": "standard", "inference_geo": "not_available" } } headers: CF-RAY: - - 9d3b38d21818f3bb-EWR + - 9d434044d9205d8f-EWR Connection: - keep-alive Content-Security-Policy: @@ -100,7 +100,7 @@ interactions: Content-Type: - application/json Date: - - Thu, 26 Feb 2026 00:10:59 GMT + - Thu, 26 Feb 2026 23:34:11 GMT Server: - cloudflare Transfer-Encoding: @@ -112,35 +112,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-26T00:10:54Z' + - '2026-02-26T23:34:05Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-26T00:10:59Z' + - '2026-02-26T23:34:11Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-26T00:10:53Z' + - '2026-02-26T23:34:04Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-26T00:10:54Z' + - '2026-02-26T23:34:05Z' cf-cache-status: - DYNAMIC content-length: - - '2342' + - '2523' request-id: - - req_011CYViBa3b8ctAu7Xkm6zNL + - req_011CYXZBfP2AZrnRcZpL7v33 strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '6252' + - '6707' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml index 7c3de9606b..6994c0a4d2 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_captures_tool_use_content.yaml @@ -78,13 +78,13 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_019yWjxTF7xZwvSo32EGeLRe", + "id": "msg_01CAX3NfQbrV1V1L38j8HFoN", "type": "message", "role": "assistant", "content": [ { "type": "tool_use", - "id": "toolu_01Hqe6XnkTWQkryxNHtk8kTw", + "id": "toolu_01KxvRJ8rVKcC69hTfFXvwnU", "name": "get_weather", "input": { "city": "San Francisco" @@ -111,7 +111,7 @@ interactions: } headers: CF-RAY: - - 9d3b38c7fae6a0fb-EWR + - 9d43403ccf2ebe82-EWR Connection: - keep-alive Content-Security-Policy: @@ -119,7 +119,7 @@ interactions: Content-Type: - application/json Date: - - Thu, 26 Feb 2026 00:10:52 GMT + - Thu, 26 Feb 2026 23:34:04 GMT Server: - cloudflare Transfer-Encoding: @@ -131,35 +131,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-26T00:10:52Z' + - '2026-02-26T23:34:04Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-26T00:10:52Z' + - '2026-02-26T23:34:04Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-26T00:10:51Z' + - '2026-02-26T23:34:03Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-26T00:10:52Z' + - '2026-02-26T23:34:04Z' cf-cache-status: - DYNAMIC content-length: - '550' request-id: - - req_011CYViBT9c3zdmSZzK2BRk4 + - req_011CYXZBZsscGf21yQ2EnhRJ strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1422' + - '1131' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml index e3f7868551..5eb661dc10 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_event_only_no_content_in_span.yaml @@ -57,7 +57,7 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_01GGtjbGqbadf1kdUv24ce2F", + "id": "msg_01CjYy52FHcPjyvxXbu3CBtw", "type": "message", "role": "assistant", "content": [ @@ -83,7 +83,7 @@ interactions: } headers: CF-RAY: - - 9d3b392fbbfe583f-EWR + - 9d4340a3695606a1-EWR Connection: - keep-alive Content-Security-Policy: @@ -91,7 +91,7 @@ interactions: Content-Type: - application/json Date: - - Thu, 26 Feb 2026 00:11:09 GMT + - Thu, 26 Feb 2026 23:34:20 GMT Server: - cloudflare Transfer-Encoding: @@ -103,35 +103,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-26T00:11:09Z' + - '2026-02-26T23:34:20Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-26T00:11:09Z' + - '2026-02-26T23:34:20Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-26T00:11:08Z' + - '2026-02-26T23:34:19Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-26T00:11:09Z' + - '2026-02-26T23:34:20Z' cf-cache-status: - DYNAMIC content-length: - '441' request-id: - - req_011CYViCg7zFhWkmNGucF9FG + - req_011CYXZCn77hQNGjLFsEhmk7 strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1114' + - '1134' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_instrumentation_error_swallowed.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_instrumentation_error_swallowed.yaml index 9fdad5a8b0..2780ab5541 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_instrumentation_error_swallowed.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_instrumentation_error_swallowed.yaml @@ -57,29 +57,29 @@ interactions: body: string: |+ event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01DJ9j2gWyEJVviKj7Q6pgjv","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_0135WGDEevMwHieJDYDUWtFi","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } event: ping data: {"type": "ping"} event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } event: content_block_stop - data: {"type":"content_block_stop","index":0 } + data: {"type":"content_block_stop","index":0 } event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } event: message_stop - data: {"type":"message_stop" } + data: {"type":"message_stop" } headers: CF-RAY: - - 9d3b3927ecd24396-EWR + - 9d43409be9491dcc-EWR Cache-Control: - no-cache Connection: @@ -89,7 +89,7 @@ interactions: Content-Type: - text/event-stream; charset=utf-8 Date: - - Thu, 26 Feb 2026 00:11:07 GMT + - Thu, 26 Feb 2026 23:34:19 GMT Server: - cloudflare Transfer-Encoding: @@ -101,33 +101,37 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-26T00:11:06Z' + - '2026-02-26T23:34:18Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-26T00:11:06Z' + - '2026-02-26T23:34:18Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-26T00:11:06Z' + - '2026-02-26T23:34:18Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-26T00:11:06Z' + - '2026-02-26T23:34:18Z' cf-cache-status: - DYNAMIC + content-length: + - '1112' request-id: - - req_011CYViCak2u4rCZvC1rFVaF + - req_011CYXZCgxJTcRprqcP37XSX strict-transport-security: - max-age=31536000; includeSubDomains; preload + vary: + - Accept-Encoding x-envoy-upstream-service-time: - - '925' + - '952' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml index 2e0d6e8055..d4a259c928 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stop_reason.yaml @@ -57,7 +57,7 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_018voDg2j9DfJRDo9cqg7Lzs", + "id": "msg_011rhQfbitTJY8ks1WedEbRj", "type": "message", "role": "assistant", "content": [ @@ -83,7 +83,7 @@ interactions: } headers: CF-RAY: - - 9d3b3887cee5ccb6-EWR + - 9d4340007d7109a2-EWR Connection: - keep-alive Content-Security-Policy: @@ -91,7 +91,7 @@ interactions: Content-Type: - application/json Date: - - Thu, 26 Feb 2026 00:10:42 GMT + - Thu, 26 Feb 2026 23:33:54 GMT Server: - cloudflare Transfer-Encoding: @@ -103,35 +103,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-26T00:10:42Z' + - '2026-02-26T23:33:54Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-26T00:10:42Z' + - '2026-02-26T23:33:54Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-26T00:10:41Z' + - '2026-02-26T23:33:53Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-26T00:10:42Z' + - '2026-02-26T23:33:54Z' cf-cache-status: - DYNAMIC content-length: - '464' request-id: - - req_011CYViAhDAfDMmNJMVgE6iV + - req_011CYXZArcvEvEw5LVGezFBd strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1292' + - '1160' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stream_propagation_error.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stream_propagation_error.yaml index 2c1dc0200a..55ed1dc693 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stream_propagation_error.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_stream_propagation_error.yaml @@ -57,29 +57,29 @@ interactions: body: string: |+ event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01PimXT91pHrfmpMZo4yfBUK","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01MhLKxY2xkfCF72SSTxUgQf","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } event: ping data: {"type": "ping"} event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } event: content_block_stop - data: {"type":"content_block_stop","index":0 } + data: {"type":"content_block_stop","index":0 } event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } event: message_stop - data: {"type":"message_stop"} + data: {"type":"message_stop" } headers: CF-RAY: - - 9d3b39167de86d50-EWR + - 9d43408bdcfdb295-EWR Cache-Control: - no-cache Connection: @@ -89,7 +89,7 @@ interactions: Content-Type: - text/event-stream; charset=utf-8 Date: - - Thu, 26 Feb 2026 00:11:05 GMT + - Thu, 26 Feb 2026 23:34:16 GMT Server: - cloudflare Transfer-Encoding: @@ -101,33 +101,37 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-26T00:11:04Z' + - '2026-02-26T23:34:15Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-26T00:11:04Z' + - '2026-02-26T23:34:15Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-26T00:11:04Z' + - '2026-02-26T23:34:15Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-26T00:11:04Z' + - '2026-02-26T23:34:15Z' cf-cache-status: - DYNAMIC + content-length: + - '1145' request-id: - - req_011CYViCNoCLnN2DGG7MPDTD + - req_011CYXZCVzk8sXGKiZDjKsRG strict-transport-security: - max-age=31536000; includeSubDomains; preload + vary: + - Accept-Encoding x-envoy-upstream-service-time: - - '964' + - '996' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml index cb85df54b0..5a9d8420c9 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming.yaml @@ -57,29 +57,29 @@ interactions: body: string: |+ event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01Ljp7MtYoLaeYxJ4JktUEhe","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_015fGzcRwVixKfgX3TK7WfTX","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } event: ping data: {"type": "ping"} event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } event: content_block_stop data: {"type":"content_block_stop","index":0 } event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } event: message_stop - data: {"type":"message_stop" } + data: {"type":"message_stop" } headers: CF-RAY: - - 9d3b389b1f235541-EWR + - 9d4340131ee7f2f9-EWR Cache-Control: - no-cache Connection: @@ -89,7 +89,7 @@ interactions: Content-Type: - text/event-stream; charset=utf-8 Date: - - Thu, 26 Feb 2026 00:10:45 GMT + - Thu, 26 Feb 2026 23:33:57 GMT Server: - cloudflare Transfer-Encoding: @@ -101,33 +101,37 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-26T00:10:44Z' + - '2026-02-26T23:33:56Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-26T00:10:44Z' + - '2026-02-26T23:33:56Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-26T00:10:44Z' + - '2026-02-26T23:33:56Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-26T00:10:44Z' + - '2026-02-26T23:33:56Z' cf-cache-status: - DYNAMIC + content-length: + - '1132' request-id: - - req_011CYViAvPfy215EsADmjHTw + - req_011CYXZB5RMcxBgcANAjoGWQ strict-transport-security: - max-age=31536000; includeSubDomains; preload + vary: + - Accept-Encoding x-envoy-upstream-service-time: - - '1002' + - '936' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_aggregates_cache_tokens.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_aggregates_cache_tokens.yaml index 4cf649ba38..a2ca41f879 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_aggregates_cache_tokens.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_aggregates_cache_tokens.yaml @@ -57,29 +57,29 @@ interactions: body: string: |+ event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_015SPzdGP6SSWMmVsXzkxPoe","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01BUsYc9vsjw9jfoJ527C7Xq","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } event: ping data: {"type": "ping"} event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } event: content_block_stop - data: {"type":"content_block_stop","index":0 } + data: {"type":"content_block_stop","index":0 } event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } event: message_stop - data: {"type":"message_stop" } + data: {"type":"message_stop" } headers: CF-RAY: - - 9d3b390e8b8823dd-EWR + - 9d4340845b9b6d50-EWR Cache-Control: - no-cache Connection: @@ -89,7 +89,7 @@ interactions: Content-Type: - text/event-stream; charset=utf-8 Date: - - Thu, 26 Feb 2026 00:11:03 GMT + - Thu, 26 Feb 2026 23:34:15 GMT Server: - cloudflare Transfer-Encoding: @@ -101,33 +101,37 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-26T00:11:02Z' + - '2026-02-26T23:34:14Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-26T00:11:02Z' + - '2026-02-26T23:34:14Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-26T00:11:02Z' + - '2026-02-26T23:34:14Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-26T00:11:02Z' + - '2026-02-26T23:34:14Z' cf-cache-status: - DYNAMIC + content-length: + - '1127' request-id: - - req_011CYViCHMmnHDrnQPoTjub7 + - req_011CYXZCQuQNimM1GZwNVqEj strict-transport-security: - max-age=31536000; includeSubDomains; preload + vary: + - Accept-Encoding x-envoy-upstream-service-time: - - '967' + - '950' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml index 57d2f51c5e..1e5b7a8ea5 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_captures_content.yaml @@ -57,29 +57,29 @@ interactions: body: string: |+ event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_015xcfsHjWyzeJNhLUN2XY1A","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01BKdCiHiwMjwTnmgTRdLJbq","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } event: ping data: {"type": "ping"} event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } event: content_block_stop - data: {"type":"content_block_stop","index":0 } + data: {"type":"content_block_stop","index":0 } event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } event: message_stop data: {"type":"message_stop" } headers: CF-RAY: - - 9d3b38a33bc293b9-EWR + - 9d43401a9c7f43d0-EWR Cache-Control: - no-cache Connection: @@ -89,7 +89,7 @@ interactions: Content-Type: - text/event-stream; charset=utf-8 Date: - - Thu, 26 Feb 2026 00:10:46 GMT + - Thu, 26 Feb 2026 23:33:58 GMT Server: - cloudflare Transfer-Encoding: @@ -101,33 +101,37 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-26T00:10:45Z' + - '2026-02-26T23:33:57Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-26T00:10:45Z' + - '2026-02-26T23:33:57Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-26T00:10:45Z' + - '2026-02-26T23:33:57Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-26T00:10:45Z' + - '2026-02-26T23:33:57Z' cf-cache-status: - DYNAMIC + content-length: + - '1144' request-id: - - req_011CYViB1zWtZDrhgf4gQowM + - req_011CYXZBAVhhGEfySc8q42Tv strict-transport-security: - max-age=31536000; includeSubDomains; preload + vary: + - Accept-Encoding x-envoy-upstream-service-time: - - '1102' + - '1011' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_delegates_response_attribute.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_delegates_response_attribute.yaml index 83ff88ea00..e4ee85afcf 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_delegates_response_attribute.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_delegates_response_attribute.yaml @@ -57,38 +57,41 @@ interactions: body: string: |+ event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01AfpfPhdXq6t3UGyaDvXBik","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_014sguaNvcSCgDympoX7TmPT","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } event: ping data: {"type": "ping"} event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"}} + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"! How"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"!"} } event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" How"} } event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" you doing today?"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"} } + + event: content_block_delta + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" you doing today?"} } event: content_block_stop - data: {"type":"content_block_stop","index":0 } + data: {"type":"content_block_stop","index":0 } event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } event: message_stop - data: {"type":"message_stop" } + data: {"type":"message_stop" } headers: CF-RAY: - - 9d3b38b38dc0a10a-EWR + - 9d43402b8933f793-EWR Cache-Control: - no-cache Connection: @@ -98,7 +101,7 @@ interactions: Content-Type: - text/event-stream; charset=utf-8 Date: - - Thu, 26 Feb 2026 00:10:49 GMT + - Thu, 26 Feb 2026 23:34:01 GMT Server: - cloudflare Transfer-Encoding: @@ -110,33 +113,37 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-26T00:10:48Z' + - '2026-02-26T23:34:00Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-26T00:10:48Z' + - '2026-02-26T23:34:00Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-26T00:10:48Z' + - '2026-02-26T23:34:00Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-26T00:10:48Z' + - '2026-02-26T23:34:00Z' cf-cache-status: - DYNAMIC + content-length: + - '1619' request-id: - - req_011CYViBD9EnGW4myALEXtBD + - req_011CYXZBN6x8ePkJKHHEM3YC strict-transport-security: - max-age=31536000; includeSubDomains; preload + vary: + - Accept-Encoding x-envoy-upstream-service-time: - - '1029' + - '1035' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml index fc34cb691b..571d1dfc68 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_iteration.yaml @@ -57,38 +57,38 @@ interactions: body: string: |+ event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_0121nnwh1G3cPTAEX74JsHTk","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01YQkMnqaSZTZ1tCXoVrzqoP","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":1,"service_tier":"standard","inference_geo":"not_available"}} } event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } event: ping data: {"type": "ping"} event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hi"} } event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"! How"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"! How"} } event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" are"} } event: content_block_delta data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":" you doing today?"} } event: content_block_stop - data: {"type":"content_block_stop","index":0 } + data: {"type":"content_block_stop","index":0 } event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":11} } event: message_stop - data: {"type":"message_stop" } + data: {"type":"message_stop" } headers: CF-RAY: - - 9d3b38ab9a1fed71-EWR + - 9d434022da8bb734-EWR Cache-Control: - no-cache Connection: @@ -98,7 +98,7 @@ interactions: Content-Type: - text/event-stream; charset=utf-8 Date: - - Thu, 26 Feb 2026 00:10:47 GMT + - Thu, 26 Feb 2026 23:33:59 GMT Server: - cloudflare Transfer-Encoding: @@ -110,33 +110,37 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-26T00:10:47Z' + - '2026-02-26T23:33:58Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-26T00:10:47Z' + - '2026-02-26T23:33:58Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-26T00:10:47Z' + - '2026-02-26T23:33:58Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-26T00:10:47Z' + - '2026-02-26T23:33:58Z' cf-cache-status: - DYNAMIC + content-length: + - '1540' request-id: - - req_011CYViB7iojRRL4v9f2JaEX + - req_011CYXZBG836JU3tAPte1soW strict-transport-security: - max-age=31536000; includeSubDomains; preload + vary: + - Accept-Encoding x-envoy-upstream-service-time: - - '857' + - '998' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_user_exception.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_user_exception.yaml index b911864f70..36f4b54107 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_user_exception.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_streaming_user_exception.yaml @@ -57,29 +57,29 @@ interactions: body: string: |+ event: message_start - data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_014oR3DpZKsLw65binJNTdxe","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":5,"service_tier":"standard","inference_geo":"not_available"}} } + data: {"type":"message_start","message":{"model":"claude-sonnet-4-20250514","id":"msg_01V4xbJHGawdjruyUCZ6imGT","type":"message","role":"assistant","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"output_tokens":2,"service_tier":"standard","inference_geo":"not_available"}} } event: content_block_start - data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } + data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""} } event: ping data: {"type": "ping"} event: content_block_delta - data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } + data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello!"} } event: content_block_stop - data: {"type":"content_block_stop","index":0} + data: {"type":"content_block_stop","index":0 } event: message_delta - data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } + data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":5} } event: message_stop - data: {"type":"message_stop" } + data: {"type":"message_stop" } headers: CF-RAY: - - 9d3b391e6c42b734-EWR + - 9d4340940cef9cdd-EWR Cache-Control: - no-cache Connection: @@ -89,7 +89,7 @@ interactions: Content-Type: - text/event-stream; charset=utf-8 Date: - - Thu, 26 Feb 2026 00:11:06 GMT + - Thu, 26 Feb 2026 23:34:17 GMT Server: - cloudflare Transfer-Encoding: @@ -101,33 +101,37 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-26T00:11:05Z' + - '2026-02-26T23:34:17Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-26T00:11:05Z' + - '2026-02-26T23:34:17Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-26T00:11:05Z' + - '2026-02-26T23:34:17Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-26T00:11:05Z' + - '2026-02-26T23:34:17Z' cf-cache-status: - DYNAMIC + content-length: + - '1124' request-id: - - req_011CYViCUG7E3FEZv5dbGhze + - req_011CYXZCbabapLuDEi6anyVX strict-transport-security: - max-age=31536000; includeSubDomains; preload + vary: + - Accept-Encoding x-envoy-upstream-service-time: - - '1282' + - '979' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml index 37fd939ef1..b08d18409d 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_token_usage.yaml @@ -57,7 +57,7 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_01QwHjvtC6ugf49hNKNXotxJ", + "id": "msg_01BenGkMmyoqjV3wcoTksLFe", "type": "message", "role": "assistant", "content": [ @@ -83,7 +83,7 @@ interactions: } headers: CF-RAY: - - 9d3b387fea1f3ea9-EWR + - 9d433ff7c9bd939a-EWR Connection: - keep-alive Content-Security-Policy: @@ -91,7 +91,7 @@ interactions: Content-Type: - application/json Date: - - Thu, 26 Feb 2026 00:10:41 GMT + - Thu, 26 Feb 2026 23:33:53 GMT Server: - cloudflare Transfer-Encoding: @@ -103,35 +103,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-26T00:10:40Z' + - '2026-02-26T23:33:53Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-26T00:10:41Z' + - '2026-02-26T23:33:53Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-26T00:10:40Z' + - '2026-02-26T23:33:52Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-26T00:10:40Z' + - '2026-02-26T23:33:53Z' cf-cache-status: - DYNAMIC content-length: - '449' request-id: - - req_011CYViAbqTfhdQbBTBUpcA6 + - req_011CYXZAkgV5nXq6SWeYx1xy strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1075' + - '1233' status: code: 200 message: OK diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml index 03ae29b305..0100ed7640 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/cassettes/test_sync_messages_create_with_all_params.yaml @@ -63,13 +63,13 @@ interactions: string: |- { "model": "claude-sonnet-4-20250514", - "id": "msg_01YLYw2WP65AdfrhVYQHxknf", + "id": "msg_01TmHCb7QRNTPGCbdZCsFH8q", "type": "message", "role": "assistant", "content": [ { "type": "text", - "text": "Hello! How are you doing today?" + "text": "Hello! It's nice to meet you. How are you doing today?" } ], "stop_reason": "end_turn", @@ -82,14 +82,14 @@ interactions: "ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 0 }, - "output_tokens": 11, + "output_tokens": 18, "service_tier": "standard", "inference_geo": "not_available" } } headers: CF-RAY: - - 9d3b387668c69175-EWR + - 9d433fefb83acd8b-EWR Connection: - keep-alive Content-Security-Policy: @@ -97,7 +97,7 @@ interactions: Content-Type: - application/json Date: - - Thu, 26 Feb 2026 00:10:39 GMT + - Thu, 26 Feb 2026 23:33:51 GMT Server: - cloudflare Transfer-Encoding: @@ -109,35 +109,35 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '450000' anthropic-ratelimit-input-tokens-reset: - - '2026-02-26T00:10:39Z' + - '2026-02-26T23:33:51Z' anthropic-ratelimit-output-tokens-limit: - '90000' anthropic-ratelimit-output-tokens-remaining: - '90000' anthropic-ratelimit-output-tokens-reset: - - '2026-02-26T00:10:39Z' + - '2026-02-26T23:33:51Z' anthropic-ratelimit-requests-limit: - '1000' anthropic-ratelimit-requests-remaining: - '999' anthropic-ratelimit-requests-reset: - - '2026-02-26T00:10:38Z' + - '2026-02-26T23:33:50Z' anthropic-ratelimit-tokens-limit: - '540000' anthropic-ratelimit-tokens-remaining: - '540000' anthropic-ratelimit-tokens-reset: - - '2026-02-26T00:10:39Z' + - '2026-02-26T23:33:51Z' cf-cache-status: - DYNAMIC content-length: - - '467' + - '490' request-id: - - req_011CYViAVL3Y2XRNdwzAJwav + - req_011CYXZAfAqyTW82t5hSJb5z strict-transport-security: - max-age=31536000; includeSubDomains; preload x-envoy-upstream-service-time: - - '1346' + - '1150' status: code: 200 message: OK From f62dd6dc89aac94ae751c9f397710eaebdc3a35f Mon Sep 17 00:00:00 2001 From: Teja Date: Thu, 26 Feb 2026 18:44:19 -0500 Subject: [PATCH 32/35] Update anthropic dependency version to 0.51.0 in pyproject.toml and requirements.oldest.txt for compatibility improvements. --- .../opentelemetry-instrumentation-anthropic/pyproject.toml | 2 +- .../tests/requirements.oldest.txt | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/pyproject.toml b/instrumentation-genai/opentelemetry-instrumentation-anthropic/pyproject.toml index 32642eaf2b..74c411a1a5 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/pyproject.toml +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/pyproject.toml @@ -34,7 +34,7 @@ dependencies = [ [project.optional-dependencies] instruments = [ - "anthropic >= 0.16.0", + "anthropic >= 0.51.0", ] [project.entry-points.opentelemetry_instrumentor] diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/requirements.oldest.txt b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/requirements.oldest.txt index b962a02555..0b77b1a7cb 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/requirements.oldest.txt +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/tests/requirements.oldest.txt @@ -16,8 +16,7 @@ # the oldest supported version of external dependencies. -e util/opentelemetry-util-genai -anthropic==0.16.0 -httpx>=0.25.2,<0.28.0 # Pin to version compatible with anthropic 0.16.0 (proxies arg removed in 0.28) +anthropic==0.51.0 pytest==7.4.4 pytest-vcr==1.0.2 pytest-asyncio==0.21.0 From 1bf76952522200aac84725cdd775350c47db4064 Mon Sep 17 00:00:00 2001 From: Teja Date: Thu, 26 Feb 2026 19:10:07 -0500 Subject: [PATCH 33/35] Refactor usage token extraction to utilize a new UsageTokens dataclass for improved clarity and type safety. Update extract_usage_tokens function to return UsageTokens instead of a tuple, and adjust related invocations in MessageWrapper and MessagesStreamWrapper accordingly. --- .../anthropic/messages_extractors.py | 22 +++++++--- .../instrumentation/anthropic/wrappers.py | 44 ++++++++----------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/messages_extractors.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/messages_extractors.py index 319ed183cb..907aa08d39 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/messages_extractors.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/messages_extractors.py @@ -75,11 +75,19 @@ class MessageRequestParams: GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS = "gen_ai.usage.cache_read.input_tokens" +@dataclass +class UsageTokens: + input_tokens: int | None = None + output_tokens: int | None = None + cache_creation_input_tokens: int | None = None + cache_read_input_tokens: int | None = None + + def extract_usage_tokens( usage: Usage | MessageDeltaUsage | None, -) -> tuple[int | None, int | None, int | None, int | None]: +) -> UsageTokens: if usage is None: - return None, None, None, None + return UsageTokens() input_tokens = usage.input_tokens output_tokens = usage.output_tokens @@ -99,11 +107,11 @@ def extract_usage_tokens( + (cache_read_input_tokens or 0) ) - return ( - total_input_tokens, - output_tokens, - cache_creation_input_tokens, - cache_read_input_tokens, + return UsageTokens( + input_tokens=total_input_tokens, + output_tokens=output_tokens, + cache_creation_input_tokens=cache_creation_input_tokens, + cache_read_input_tokens=cache_read_input_tokens, ) diff --git a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py index 9cea13fca6..585d70a9f9 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py +++ b/instrumentation-genai/opentelemetry-instrumentation-anthropic/src/opentelemetry/instrumentation/anthropic/wrappers.py @@ -73,21 +73,16 @@ def extract_into(self, invocation: LLMInvocation) -> None: invocation.finish_reasons = [finish_reason] if self._message.usage: - ( - input_tokens, - output_tokens, - cache_creation_input_tokens, - cache_read_input_tokens, - ) = extract_usage_tokens(self._message.usage) - invocation.input_tokens = input_tokens - invocation.output_tokens = output_tokens - if cache_creation_input_tokens is not None: + tokens = extract_usage_tokens(self._message.usage) + invocation.input_tokens = tokens.input_tokens + invocation.output_tokens = tokens.output_tokens + if tokens.cache_creation_input_tokens is not None: invocation.attributes[ GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS - ] = cache_creation_input_tokens - if cache_read_input_tokens is not None: + ] = tokens.cache_creation_input_tokens + if tokens.cache_read_input_tokens is not None: invocation.attributes[GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS] = ( - cache_read_input_tokens + tokens.cache_read_input_tokens ) if self._capture_content: @@ -126,20 +121,17 @@ def __init__( self._finalized = False def _update_usage(self, usage: Usage | MessageDeltaUsage | None) -> None: - ( - input_tokens, - output_tokens, - cache_creation_input_tokens, - cache_read_input_tokens, - ) = extract_usage_tokens(usage) - if input_tokens is not None: - self._input_tokens = input_tokens - if output_tokens is not None: - self._output_tokens = output_tokens - if cache_creation_input_tokens is not None: - self._cache_creation_input_tokens = cache_creation_input_tokens - if cache_read_input_tokens is not None: - self._cache_read_input_tokens = cache_read_input_tokens + tokens = extract_usage_tokens(usage) + if tokens.input_tokens is not None: + self._input_tokens = tokens.input_tokens + if tokens.output_tokens is not None: + self._output_tokens = tokens.output_tokens + if tokens.cache_creation_input_tokens is not None: + self._cache_creation_input_tokens = ( + tokens.cache_creation_input_tokens + ) + if tokens.cache_read_input_tokens is not None: + self._cache_read_input_tokens = tokens.cache_read_input_tokens def _process_chunk(self, chunk: RawMessageStreamEvent) -> None: """Extract telemetry data from a streaming chunk.""" From 3d2bd639d187e002dee5d1b1b64832ca265728cb Mon Sep 17 00:00:00 2001 From: Teja Date: Thu, 26 Feb 2026 19:14:44 -0500 Subject: [PATCH 34/35] Update anthropic dependency version in uv.lock to 0.51.0 for compatibility improvements. --- uv.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uv.lock b/uv.lock index d75bd7e73c..f7cb5dc20b 100644 --- a/uv.lock +++ b/uv.lock @@ -2858,7 +2858,7 @@ instruments = [ [package.metadata] requires-dist = [ - { name = "anthropic", marker = "extra == 'instruments'", specifier = ">=0.16.0" }, + { name = "anthropic", marker = "extra == 'instruments'", specifier = ">=0.51.0" }, { name = "opentelemetry-api", git = "https://github.com/open-telemetry/opentelemetry-python?subdirectory=opentelemetry-api&branch=main" }, { name = "opentelemetry-instrumentation", editable = "opentelemetry-instrumentation" }, { name = "opentelemetry-semantic-conventions", git = "https://github.com/open-telemetry/opentelemetry-python?subdirectory=opentelemetry-semantic-conventions&branch=main" }, From cc8e4d1b588972077dc5077587ebb9028a3164dd Mon Sep 17 00:00:00 2001 From: Teja Date: Thu, 26 Feb 2026 22:40:11 -0500 Subject: [PATCH 35/35] Add tests for should_capture_content function in test_events_options.py. --- .../tests/test_events_options.py | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/util/opentelemetry-util-genai/tests/test_events_options.py b/util/opentelemetry-util-genai/tests/test_events_options.py index 78476de880..f83fc9562e 100644 --- a/util/opentelemetry-util-genai/tests/test_events_options.py +++ b/util/opentelemetry-util-genai/tests/test_events_options.py @@ -25,6 +25,7 @@ OTEL_INSTRUMENTATION_GENAI_EMIT_EVENT, ) from opentelemetry.util.genai.utils import ( + should_capture_content, should_emit_event, ) @@ -206,3 +207,45 @@ def test_should_emit_event_user_setting_overrides_default_for_no_content( ): # pylint: disable=no-self-use # User explicitly setting emit_event="true" should override the default (False for NO_CONTENT) assert should_emit_event() is True + + +class TestShouldCaptureContent(unittest.TestCase): + @patch_env_vars( + stability_mode="default", + content_capturing="SPAN_AND_EVENT", + emit_event="true", + ) + def test_should_capture_content_false_when_not_experimental( + self, + ): # pylint: disable=no-self-use + assert should_capture_content() is False + + @patch_env_vars( + stability_mode="gen_ai_latest_experimental", + content_capturing="NO_CONTENT", + emit_event="true", + ) + def test_should_capture_content_false_when_no_content( + self, + ): # pylint: disable=no-self-use + assert should_capture_content() is False + + @patch_env_vars( + stability_mode="gen_ai_latest_experimental", + content_capturing="EVENT_ONLY", + emit_event="false", + ) + def test_should_capture_content_false_when_event_only_but_event_disabled( + self, + ): # pylint: disable=no-self-use + assert should_capture_content() is False + + @patch_env_vars( + stability_mode="gen_ai_latest_experimental", + content_capturing="SPAN_ONLY", + emit_event="", + ) + def test_should_capture_content_true_for_span_only( + self, + ): # pylint: disable=no-self-use + assert should_capture_content() is True