OpenAI SDK

Use the OpenAI Python or Node.js SDK to send requests through agentgateway deployed in Kubernetes.

Before you begin

  1. Set up an agentgateway proxy.
  2. Set up access to the OpenAI LLM provider.

Get the gateway URL

export INGRESS_GW_ADDRESS=$(kubectl get svc -n agentgateway-system agentgateway-proxy \
  -o jsonpath='{.status.loadBalancer.ingress[0].ip}')

echo "Gateway address: $INGRESS_GW_ADDRESS"
export INGRESS_GW_ADDRESS=$(kubectl get svc -n agentgateway-system agentgateway-proxy \
  -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')

echo "Gateway address: $INGRESS_GW_ADDRESS"

After port-forwarding, the gateway is accessible at http://localhost:8080. Use localhost:8080 wherever the instructions reference $INGRESS_GW_ADDRESS.

kubectl port-forward -n agentgateway-system svc/agentgateway-proxy 8080:80

Python

  1. Install the OpenAI SDK in your Python project.

    pip install openai
  2. Create and run the following script to send a request through agentgateway. Replace <route-path> with the path from your HTTPRoute configuration (for example, /openai).

    ℹ️
    Do not include /v1 in the base_url — the OpenAI SDK appends it automatically.
    import os
    from openai import OpenAI
    
    gateway_address = os.environ["INGRESS_GW_ADDRESS"]
    
    client = OpenAI(
        base_url=f"http://{gateway_address}/<route-path>",
        api_key="anything",  # placeholder if gateway has no auth
    )
    
    response = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[{"role": "user", "content": "Hello from Kubernetes!"}],
    )
    print(response.choices[0].message.content)

Node.js

  1. Install the OpenAI SDK in your Node.js project.

    npm install openai
  2. Create and run the following script to send a request through agentgateway. Replace <route-path> with the path from your HTTPRoute configuration (for example, /openai).

    ℹ️
    Do not include /v1 in the baseURL — the OpenAI SDK appends it automatically.
    import OpenAI from "openai";
    
    const gatewayAddress = process.env.INGRESS_GW_ADDRESS;
    
    const client = new OpenAI({
      baseURL: `http://${gatewayAddress}/<route-path>`,
      apiKey: "anything",
    });
    
    const response = await client.chat.completions.create({
      model: "gpt-4o-mini",
      messages: [{ role: "user", content: "Hello from Kubernetes!" }],
    });
    console.log(response.choices[0].message.content);
Agentgateway assistant

Ask me anything about agentgateway configuration, features, or usage.

Note: AI-generated content might contain errors; please verify and test all returned information.

Tip: one topic per conversation gives the best results. Use the + button in the chat header to start a new conversation.

Switching topics? Starting a new conversation improves accuracy.
↑↓ navigate select esc dismiss

What could be improved?

Your feedback helps us improve assistant answers and identify docs gaps we should fix.

Need more help? Join us on Discord: https://discord.gg/y9efgEmppm

Want to use your own agent? Add the Solo MCP server to query our docs directly. Get started here: https://search.solo.io/.