Class: Telnyx::Resources::AI::Anthropic::V1

Inherits:
Object
  • Object
show all
Defined in:
lib/telnyx/resources/ai/anthropic/v1.rb,
sig/telnyx/resources/ai/anthropic/v1.rbs

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ V1

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of V1.

Parameters:



84
85
86
# File 'lib/telnyx/resources/ai/anthropic/v1.rb', line 84

def initialize(client:)
  @client = client
end

Instance Method Details

#messages(max_tokens:, messages:, model:, api_key_ref: nil, billing_group_id: nil, fallback_config: nil, max_retries: nil, mcp_servers: nil, metadata: nil, service_tier: nil, stop_sequences: nil, stream: nil, system_: nil, temperature: nil, thinking: nil, timeout: nil, tool_choice: nil, tools: nil, top_k: nil, top_p: nil, request_options: {}) ⇒ Hash{Symbol=>Object}

Some parameter documentations has been truncated, see Models::AI::Anthropic::V1MessagesParams for more details.

Send a message to a language model using the Anthropic Messages API format. This endpoint is compatible with the Anthropic Messages API and may be used with the Anthropic JS or Python SDK by setting the base URL to https://api.telnyx.com/v2/ai/anthropic.

The endpoint translates Anthropic-format requests into Telnyx's inference internals, then translates the response back to the Anthropic message shape. Streaming responses use Anthropic SSE event types (message_start, content_block_start, content_block_delta, content_block_stop, message_delta, message_stop).

Parameters:

  • max_tokens (Integer)

    The maximum number of tokens to generate in the response.

  • messages (Array<Hash{Symbol=>Object}>)

    The messages to send to the model, following the [Anthropic Messages API](https:

  • model (String)

    The model to use for generating the response, for example zai-org/GLM-5.2 or a

  • api_key_ref (String)

    If you are using an external inference provider, this field allows you to pass a

  • billing_group_id (String)

    The billing group ID to associate with this request.

  • fallback_config (Hash{Symbol=>Object})

    Configuration for model fallback behavior when the primary model is unavailable.

  • max_retries (Integer)

    Maximum number of retries for the request.

  • mcp_servers (Array<Hash{Symbol=>Object}>)

    List of MCP (Model Context Protocol) servers to make available to the model.

  • metadata (Hash{Symbol=>Object})

    An object describing metadata about the request.

  • service_tier (String)

    Service tier for the request.

  • stop_sequences (Array<String>)

    Custom sequences that will cause the model to stop generating.

  • stream (Boolean)

    Whether to stream the response as Anthropic-format Server-Sent Events.

  • system_ (String, Array<Hash{Symbol=>Object}>)

    System prompt. Can be a string or an array of content blocks following the Anthr

  • temperature (Float)

    Amount of randomness injected into the response. Ranges from 0 to 1.

  • thinking (Hash{Symbol=>Object})

    Extended thinking configuration for models that support it. Set type to `enabl

  • timeout (Float)

    Request timeout in seconds.

  • tool_choice (Hash{Symbol=>Object})

    Controls how the model uses tools, following the Anthropic API format.

  • tools (Array<Hash{Symbol=>Object}>)

    Definitions of tools that the model may use, following the Anthropic API format.

  • top_k (Integer)

    Top-k sampling parameter. Only sample from the top K options for each subsequent

  • top_p (Float)

    Nucleus sampling parameter. Use temperature or top_p, but not both.

  • request_options (Telnyx::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (Hash{Symbol=>Object})

See Also:



70
71
72
73
74
75
76
77
78
79
# File 'lib/telnyx/resources/ai/anthropic/v1.rb', line 70

def messages(params)
  parsed, options = Telnyx::AI::Anthropic::V1MessagesParams.dump_request(params)
  @client.request(
    method: :post,
    path: "ai/anthropic/v1/messages",
    body: parsed,
    model: Telnyx::Internal::Type::HashOf[Telnyx::Internal::Type::Unknown],
    options: options
  )
end