Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/ruby_llm/aliases.json
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,15 @@
"openai": "gpt-5.5-pro",
"openrouter": "openai/gpt-5.5-pro"
},
"gpt-5.6-luna": {
"bedrock": "openai.gpt-5.6-luna"
},
"gpt-5.6-sol": {
"bedrock": "openai.gpt-5.6-sol"
},
"gpt-5.6-terra": {
"bedrock": "openai.gpt-5.6-terra"
},
"gpt-audio": {
"openai": "gpt-audio",
"openrouter": "openai/gpt-audio"
Expand Down
4 changes: 2 additions & 2 deletions lib/ruby_llm/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ def self.basic(&)
end
end

def initialize(provider, config)
def initialize(provider, config, base_url: provider.api_base)
@provider = provider
@config = config

@connection = Faraday.new(provider.api_base) do |faraday|
@connection = Faraday.new(base_url) do |faraday|
setup_timeout(faraday)
setup_logging(faraday)
setup_retry(faraday)
Expand Down
198 changes: 198 additions & 0 deletions lib/ruby_llm/models.json
Original file line number Diff line number Diff line change
Expand Up @@ -16784,6 +16784,204 @@
"knowledge": "2025-12-01"
}
},
{
"id": "openai.gpt-5.6-sol",
"name": "GPT-5.6 Sol",
"provider": "bedrock",
"family": "gpt",
"created_at": "2026-07-13 00:00:00 UTC",
"context_window": 272000,
"max_output_tokens": 128000,
"knowledge_cutoff": null,
"modalities": {
"input": [
"text",
"image",
"pdf"
],
"output": [
"text"
]
},
"capabilities": [
"function_calling",
"structured_output",
"reasoning",
"vision"
],
"pricing": {
"text_tokens": {
"standard": {
"input_per_million": 5.0,
"output_per_million": 30.0,
"cache_read_input_per_million": 0.5
}
}
},
"metadata": {
"source": "models.dev",
"provider_id": "amazon-bedrock",
"open_weights": false,
"attachment": true,
"temperature": false,
"last_updated": "2026-06-01",
"reasoning_options": [
{
"type": "effort",
"values": [
"none",
"low",
"medium",
"high",
"xhigh",
"max"
]
}
],
"cost": {
"input": 5.0,
"output": 30.0,
"cache_read": 0.5
},
"limit": {
"context": 272000,
"output": 128000
},
"knowledge": null
}
},
{
"id": "openai.gpt-5.6-terra",
"name": "GPT-5.6 Terra",
"provider": "bedrock",
"family": "gpt",
"created_at": "2026-07-13 00:00:00 UTC",
"context_window": 272000,
"max_output_tokens": 128000,
"knowledge_cutoff": null,
"modalities": {
"input": [
"text",
"image",
"pdf"
],
"output": [
"text"
]
},
"capabilities": [
"function_calling",
"structured_output",
"reasoning",
"vision"
],
"pricing": {
"text_tokens": {
"standard": {
"input_per_million": 2.5,
"output_per_million": 15.0,
"cache_read_input_per_million": 0.25
}
}
},
"metadata": {
"source": "models.dev",
"provider_id": "amazon-bedrock",
"open_weights": false,
"attachment": true,
"temperature": false,
"last_updated": "2026-06-01",
"reasoning_options": [
{
"type": "effort",
"values": [
"none",
"low",
"medium",
"high",
"xhigh",
"max"
]
}
],
"cost": {
"input": 2.5,
"output": 15.0,
"cache_read": 0.25
},
"limit": {
"context": 272000,
"output": 128000
},
"knowledge": null
}
},
{
"id": "openai.gpt-5.6-luna",
"name": "GPT-5.6 Luna",
"provider": "bedrock",
"family": "gpt",
"created_at": "2026-07-13 00:00:00 UTC",
"context_window": 272000,
"max_output_tokens": 128000,
"knowledge_cutoff": null,
"modalities": {
"input": [
"text",
"image",
"pdf"
],
"output": [
"text"
]
},
"capabilities": [
"function_calling",
"structured_output",
"reasoning",
"vision"
],
"pricing": {
"text_tokens": {
"standard": {
"input_per_million": 1.0,
"output_per_million": 6.0,
"cache_read_input_per_million": 0.1
}
}
},
"metadata": {
"source": "models.dev",
"provider_id": "amazon-bedrock",
"open_weights": false,
"attachment": true,
"temperature": false,
"last_updated": "2026-06-01",
"reasoning_options": [
{
"type": "effort",
"values": [
"none",
"low",
"medium",
"high",
"xhigh",
"max"
]
}
],
"cost": {
"input": 1.0,
"output": 6.0,
"cache_read": 0.1
},
"limit": {
"context": 272000,
"output": 128000
},
"knowledge": null
}
},
{
"id": "openai.gpt-oss-120b",
"name": "gpt-oss-120b",
Expand Down
46 changes: 46 additions & 0 deletions lib/ruby_llm/protocols/mantle_responses.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# frozen_string_literal: true

module RubyLLM
module Protocols
# AWS Bedrock's bedrock-mantle endpoint, speaking the OpenAI Responses API.
# Reachable only via bedrock-mantle (not bedrock-runtime), and only for models
# that physically cannot serve Converse or InvokeModel (the GPT-5.x frontier
# family). Talks to the provider's mantle connection instead of the default
# bedrock-runtime connection, and SigV4-signs every request against the
# "bedrock-mantle" service namespace instead of "bedrock".
class MantleResponses < Responses
# Frontier openai.gpt-5.x models are served at /openai/v1/responses; every other
# mantle model (e.g. openai.gpt-oss-*) is served at /v1/responses. See the
# AWS Bedrock model cards for GPT-5.6.
FRONTIER_GPT5_PATTERN = /\Aopenai\.gpt-5/

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: FRONTIER_GPT5_PATTERN here duplicates Bedrock::MANTLE_ONLY_MODEL_PATTERN (same regex, same intent). Since MantleResponses only ever handles models protocol_for already routed via mantle_only_model?, consider referencing Providers::Bedrock::MANTLE_ONLY_MODEL_PATTERN here instead of maintaining two copies that could silently diverge.


def initialize(provider, model = nil)
super
@connection = provider.mantle_connection
end

def completion_url
FRONTIER_GPT5_PATTERN.match?(@model.id) ? '/openai/v1/responses' : '/v1/responses'
end

private

def sync_response(payload, additional_headers = {})
super(payload, additional_headers.merge(mantle_signature_headers(payload)))
end

def stream_response(payload, additional_headers = {}, &)
super(payload, additional_headers.merge(mantle_signature_headers(payload)), &)
end

def mantle_signature_headers(payload)
body = JSON.generate(payload)
@provider.sign_headers(
'POST', completion_url, body,
base_url: @provider.mantle_api_base,
service: Providers::Bedrock::MANTLE_SIGNING_SERVICE
)
end
end
end
end
2 changes: 1 addition & 1 deletion lib/ruby_llm/protocols/responses/chat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def parse_output_citations(output, content)
end

def reasoning_model?(model_id)
model_id.match?(/^o\d|^gpt-5/)
model_id.match?(/\A(?:openai\.)?(?:o\d|gpt-5)/)
end

def parse_usage(usage)
Expand Down
45 changes: 43 additions & 2 deletions lib/ruby_llm/providers/bedrock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,20 @@ class Bedrock < Provider

protocol :converse, Protocols::Converse, batches: Protocols::Converse::Batches
protocol :bedrock_invoke_model, Protocols::BedrockInvokeModel
protocol :mantle_responses, Protocols::MantleResponses
files Bedrock::Files

# SigV4 requests to bedrock-mantle sign against this service namespace, not "bedrock" —
# AWS models bedrock-mantle as a separate service (see the AmazonBedrockMantleFullAccess
# managed policy and the bedrock-mantle:CreateInference IAM action). Named here so it is a
# one-line change if this assumption turns out to be wrong.
MANTLE_SIGNING_SERVICE = 'bedrock-mantle'

# openai.gpt-5.x ids are only reachable on bedrock-mantle (no Converse, no InvokeModel).
# Deliberately narrower than /\Aopenai\./ — openai.gpt-oss-* models ARE served by
# bedrock-runtime and must keep routing to Converse.
MANTLE_ONLY_MODEL_PATTERN = /\Aopenai\.gpt-5/

def api_base
@config.bedrock_api_base || "https://bedrock-runtime.#{bedrock_region}.amazonaws.com"
end
Expand All @@ -19,15 +31,26 @@ def control_api_base
@config.bedrock_api_base || "https://bedrock.#{bedrock_region}.amazonaws.com"
end

def mantle_api_base
@config.bedrock_mantle_api_base || "https://bedrock-mantle.#{mantle_region}.api.aws"
end

def mantle_connection
@mantle_connection ||= Connection.new(self, @config, base_url: mantle_api_base)
end

def headers
{}
end

def complete(messages, model:, params: {}, **rest, &)
super(messages, model:, params: normalize_params(params, model:), **rest, &)
params = normalize_params(params, model:) unless mantle_only_model?(model)
super
end

def protocol_for(model, **)
return fetch_protocol(:mantle_responses) if mantle_only_model?(model)

invoke_model?(model) ? fetch_protocol(:bedrock_invoke_model) : fetch_protocol(:converse)
end

Expand All @@ -37,7 +60,7 @@ def parse_error(response)
body = try_parse_json(response.body)
return body if body.is_a?(String)

body['message'] || body['Message'] || body['error'] || body['__type'] || super
extract_error_message(body) || super
end

def list_models
Expand All @@ -54,6 +77,8 @@ def configuration_options
bedrock_session_token
bedrock_credential_provider
bedrock_api_base
bedrock_mantle_api_base
bedrock_mantle_region
bedrock_batch_s3_uri
bedrock_batch_role_arn
bedrock_use_invoke_model
Expand Down Expand Up @@ -96,10 +121,26 @@ def ensure_configured!

private

# Bedrock errors are shaped like {"message" => "..."} or {"__type" => "..."};
# mantle (OpenAI Responses) errors are shaped like {"error" => {"message" => "..."}}.
def extract_error_message(body)
body.dig('error', 'message') || body['message'] || body['Message'] || body['error'] || body['__type']
end

def bedrock_region
@config.bedrock_region
end

def mantle_region
@config.bedrock_mantle_region || bedrock_region
end

# openai.gpt-5.x ids cannot serve Converse or InvokeModel; routing here is automatic and
# needs no config knob (unlike bedrock_use_invoke_model, which is an optimization choice).
def mantle_only_model?(model)
MANTLE_ONLY_MODEL_PATTERN.match?(model.id.to_s)
end

def bedrock_credentials_requirement
if @config.bedrock_credential_provider
'bedrock_credential_provider responding to #credentials'
Expand Down
Loading