AELDER

Connect through Portkey Gateway

Route an existing OpenAI SDK application through Portkey to the service's custom OpenAI-compatible host.

AELDER · SERVICE BASE URL
https://aelder.dev/v1

LOCAL CONFIGURATION

Let my agent set this up

Copy this task to an agent already running on your computer. Enter your API key locally when asked.

SETUP PROMPT
Help me connect Portkey to AELDER using this guide: https://aelder.dev/docs/portkey/
Service Base URL: https://aelder.dev/v1
First inspect my installed version, active profile and configuration. Explain any mismatch with the guide before changing anything.
Use the documented local configuration or CLI method. Do not automate the GUI, install software or change permissions without asking.
Preserve existing accounts, providers, models, defaults, permissions and unrelated settings. Propose the smallest change, show a redacted diff, and back up any files before editing.
Have me enter my API key locally using the tool's secret storage or an environment variable. Never ask me to paste a key into chat, print it, or include it in a command, diff, log or commit.
Use the exact model ID I choose from my account's model list. Do not invent model IDs or assume every model supports every API format or tool feature.
Validate syntax and configuration loading before making any generation request. If there is no dry-run, say so.
Explain any proposed paid test, the model and what it sends, and ask for approval before running it. Do not send project files or private conversation history as a test.
Finish with the settings changed, checks performed and steps to restore the backup.

Use this optional route with an existing Portkey account or a gateway you administer. The application also needs the OpenAI Python SDK. Portkey handles the service key, prompts and outputs while forwarding requests. Its logs can contain full request and response data; review access and retention before sending private content.

1. Prepare the connection

Define the following in your application’s private environment or ignored secret file:

Variable Value
SERVICE_BASE_URL The service Base URL above, including /v1
SERVICE_API_KEY Your service key
SERVICE_MODEL An exact text model ID from the authenticated models endpoint
PORTKEY_BASE_URL https://api.portkey.ai/v1, or your existing gateway’s API base
PORTKEY_API_KEY Your Portkey key, required for Portkey Cloud

Enter secrets locally, keeping values out of source code, shell history and setup chats. For a self-hosted gateway, retain its existing authentication requirements; omit PORTKEY_API_KEY only if that deployment does not use one.

2. Add a custom-host client

Save this as a separate script, or merge the connection arguments into the intended client:

import os
from openai import OpenAI

headers = {
    "x-portkey-provider": "openai",
    "x-portkey-custom-host": os.environ["SERVICE_BASE_URL"],
    "x-portkey-debug": "false",
}
if os.environ.get("PORTKEY_API_KEY"):
    headers["x-portkey-api-key"] = os.environ["PORTKEY_API_KEY"]

client = OpenAI(
    api_key=os.environ["SERVICE_API_KEY"],
    base_url=os.environ["PORTKEY_BASE_URL"],
    default_headers=headers,
    max_retries=0,
)

response = client.chat.completions.create(
    model=os.environ["SERVICE_MODEL"],
    messages=[{"role": "user", "content": "Reply with OK."}],
)
print(response.choices[0].message.content)

x-portkey-provider: openai selects OpenAI-compatible Chat Completions even for models from other vendors. The custom host includes /v1 and omits /chat/completions. The client’s Base URL is Portkey’s API base, which is a different setting.

x-portkey-debug: false requests Portkey’s DO NOT TRACK behavior: it omits request and response content from Portkey logs while retaining operational statistics. Portkey still processes that data. Keep keys out of metadata and application debug logs. Preserve other clients, gateway security settings and routing rules.

3. Run one explicit check

The environment and script persist locally. No gateway restart is needed for these per-request headers. Running the script sends a paid service request and may incur separate Portkey charges. Confirm the response and request in the service dashboard; Portkey’s cost estimates are separate from service billing.

For 404, check both Base URLs. For routing failures, confirm the gateway permits the custom host. This recipe does not configure fallback routes, media endpoints or other API formats.

See Portkey’s official custom-host headers, custom-host rules and logging controls.

Need the key? Open your AELDER dashboard. For direct API calls, see the API reference.