> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# AWS Bedrock AgentCore integration

> Connect the Toqan Router AI Gateway or invoke Toqan Router agents from AWS Bedrock AgentCore Runtime with fallbacks, cost tracking, and OpenTelemetry tracing.

**AWS Bedrock AgentCore Runtime** is a serverless hosting environment for deploying agents built with any framework (Strands, LangGraph, CrewAI) at production scale, without managing infrastructure. Connect the **AI Gateway** from inside AgentCore to access 500+ models across 30+ providers with automatic fallbacks, cost tracking, and full observability.

> [card] [AI Gateway](#ai-gateway)
>
> Route LLM calls through the **AI Gateway** inside AgentCore with a single base URL change.

> [card] [Toqan Router Agents](#toqan-router-agents)
>
> Invoke any **Toqan Router** Agent by key from inside AgentCore using the OpenAI Responses API.

## AI Gateway

Connect the **AI Gateway** to an AgentCore entrypoint to access 500+ LLMs across 30+ providers, with automatic fallbacks, cost tracking, and observability.

### OpenAI Agents SDK

**Install:**

```bash Bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
pip install openai-agents openai bedrock-agentcore
```

Configure an `AsyncOpenAI` client with the **AI Gateway** base URL, then wrap the agent in a `BedrockAgentCoreApp` entrypoint:

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
import os
from openai import AsyncOpenAI
from agents import Agent, Runner, set_default_openai_client, set_tracing_disabled
from bedrock_agentcore.runtime import BedrockAgentCoreApp

client = AsyncOpenAI(
    api_key=os.getenv("TOQAN_API_KEY"),
    base_url="https://router.toqan.ai/eu/v3/router"
)
set_tracing_disabled(True)
set_default_openai_client(client)

agent = Agent(
    name="Assistant",
    instructions="You are a helpful assistant.",
    model="openai/gpt-5.6-sol"
)

app = BedrockAgentCoreApp()

@app.entrypoint
async def agent_invocation(payload, context):
    query = payload.get("prompt", "How can I help you?")
    result = await Runner.run(agent, query)
    return {"result": result.final_output}

app.run()
```

### Strands Agents

**Install:**

```bash Bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
pip install strands-agents bedrock-agentcore
```

Use `OpenAIModel` with the **AI Gateway** base URL inside a Strands agent:

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
import os
from strands import Agent
from strands.models.openai import OpenAIModel
from bedrock_agentcore.runtime import BedrockAgentCoreApp

model = OpenAIModel(
    model_id="openai/gpt-5.6-sol",
    client_args={
        "api_key": os.getenv("TOQAN_API_KEY"),
        "base_url": "https://router.toqan.ai/eu/v3/router"
    }
)

agent = Agent(
    model=model,
    system_prompt="You are a helpful assistant."
)

app = BedrockAgentCoreApp()

@app.entrypoint
def agent_invocation(payload, context):
    result = agent(payload.get("prompt", "How can I help?"))
    return {"result": str(result)}

app.run()
```

## Toqan Router Agents

Invoke any **Toqan Router** Agent by key using `model="agent/YOUR_AGENT_KEY"` with the OpenAI Responses API. The **AI Gateway** executes the configured agent including its system prompt, tools, evaluators, and model settings.

> [!NOTE]
>
> Find the agent key on the Agents page in **Toqan Router**.

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
import os
from openai import AsyncOpenAI
from bedrock_agentcore.runtime import BedrockAgentCoreApp

client = AsyncOpenAI(
    api_key=os.getenv("TOQAN_API_KEY"),
    base_url="https://router.toqan.ai/eu/v3/router"
)

app = BedrockAgentCoreApp()

@app.entrypoint
async def agent_invocation(payload, context):
    query = payload.get("prompt", "How can I help you?")
    response = await client.responses.create(
        model="agent/YOUR_AGENT_KEY",
        input=query
    )
    return {"result": response.output_text}

app.run()
```

## Observability

Capture traces from AgentCore runs and send them to **Toqan Router** using OpenTelemetry.

### Installation

```bash Bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
pip install openai bedrock-agentcore opentelemetry-sdk opentelemetry-exporter-otlp-proto-http openinference-instrumentation-openai
```

### Configuration

Set up the OTLP exporter and instrument the OpenAI client before starting the app:

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
import os
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from openinference.instrumentation.openai import OpenAIInstrumentor
from openai import AsyncOpenAI
from bedrock_agentcore.runtime import BedrockAgentCoreApp

exporter = OTLPSpanExporter(
    endpoint="https://router.toqan.ai/eu/v2/otel/v1/traces",
    headers={"Authorization": f"Bearer {os.getenv('TOQAN_API_KEY')}"}
)
provider = TracerProvider()
provider.add_span_processor(BatchSpanProcessor(exporter))
OpenAIInstrumentor().instrument(tracer_provider=provider)

client = AsyncOpenAI(
    api_key=os.getenv("OPENAI_API_KEY")
)

app = BedrockAgentCoreApp()

@app.entrypoint
async def agent_invocation(payload, context):
    query = payload.get("prompt", "How can I help you?")
    response = await client.responses.create(
        model="gpt-5.6-sol",
        input=query
    )
    return {"result": response.output_text}

app.run()
```

View traces in [AI Studio](https://router.toqan.ai/eu) under the **Traces** tab.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.