Call with the OpenAI SDK

This page assumes that your application already uses the OpenAI Python SDK. After completing it, the application receives one text response through the Genesis Chat Completions shape.

For full integration details and usage boundaries, see Genesis SDK.

How the call progresses

Point the existing client to the Genesis API base URL, then send a chat request with the current credential and model ID. The first message in the response is the result of this call. A returned request does not establish support for every request shape, streaming mode, or tool feature.

Prepare the call

Prepare the following:

Required item

How to obtain it

Purpose on this page

Existing OpenAI Python SDK

Use the dependency already used by the application; this page does not install or select a version

Creates the client

Genesis API base URL

Obtain the complete value from the Genesis connection information for the current environment

Client service address

Genesis access credential

Obtain it from the Genesis connection information for the current environment

Client credential

Available model ID

Select one from the model information for the current environment or list models

Selects the model for this call

Use the version path included in the supplied base URL. Do not append another path or mix it with an address or credential for another product.

Send a chat request

The following example creates a client and submits one text chat request. It reads the text result from the first response message.

import os

from openai import OpenAI

client = OpenAI(
    base_url=os.environ["GENESIS_BASE_URL"],
    api_key=os.environ["GENESIS_ACCESS_TOKEN"],
)

response = client.chat.completions.create(
    model=os.environ["GENESIS_MODEL_ID"],
    messages=[
        {"role": "user", "content": "Explain data lineage in one sentence."},
    ],
)

print(response.choices[0].message.content)

Printed text means that this Chat Completions call returned. Do not treat empty content, a request error, or an unavailable model as a successful result; check the error and confirm that the model supports this request shape.

Next steps

Last updated on