Code Examples
Provider migration
Orqen's chat endpoint accepts the OpenAI Chat Completions shape. If your agent already uses an OpenAI-compatible SDK, you usually only change the API key and base URL. If your agent uses native Anthropic Messages or Bedrock Converse tool calls, map those native tool objects into OpenAI-compatible tools, tool_calls, and role: "tool" messages before sending through Orqen.
Your provider credentials can stay in the Orqen dashboard. For Bedrock, you can also pass temporary AWS credentials per request when needed.
from openai import OpenAI
TOOLS = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather for a city.",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
},
}
]
# Before: direct to OpenAI or another OpenAI-compatible endpoint.
client = OpenAI(api_key="sk-proj-...")
# After: same request shape, routed through Orqen.
client = OpenAI(
api_key="sk-orq-YOUR_KEY",
base_url="https://api.orqen.app/v1",
)
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Weather in London?"}],
tools=TOOLS,
tool_choice="auto",
)Tool-shape mapping
The main migration work is mechanical: preserve your tool names, descriptions, and JSON schemas, then express calls and results in the OpenAI-compatible message format.
| Native shape | Orqen shape | Notes |
|---|---|---|
Anthropic input_schema | function.parameters | Same JSON Schema, moved under the OpenAI function wrapper. |
Anthropic tool_use | assistant.tool_calls[] | Use the tool call id when you send the result back. |
Anthropic tool_result | role: tool | Send the result as a tool message with tool_call_id and JSON content. |
Bedrock toolSpec.inputSchema.json | function.parameters | Lift the inner json schema into the OpenAI function parameters field. |
Bedrock toolUse/toolResult | assistant.tool_calls[] / role: tool | Keep the same tool name and arguments, but use OpenAI-compatible call/result messages. |
Rule of thumb
Route agent traffic through /v1/chat/completions using an Orqen API key. Keep native provider credentials either stored in the dashboard or passed as Orqen-specific request fields. See the Chat API reference for the complete request schema.