DEV Community

ModelFild
ModelFild

Posted on

Switch between Gemini, DeepSeek and Kimi with one OpenAI Python client

Disclosure: I work on ModelFold. This is a configuration walkthrough based on our public docs, not a benchmark. I didn't send a paid request to prepare it.

Suppose your Python script already sends a chat message. To try it with a different model, you shouldn't have to edit the prompt, swap SDKs or maintain another copy of the script. Make the model ID a command-line argument and keep the client configuration in one place.

Install the SDK with python -m pip install openai. Set MODELFOLD_API_KEY in your environment using your own ModelFold key; don't paste it into the script. Save this as chat.py:

import argparse
import os

from openai import OpenAI

models = {
    "gemini": "gemini-2-5-flash",
    "deepseek": "deepseek-chat",
    "kimi": "kimi-k2",
}

parser = argparse.ArgumentParser()
parser.add_argument("model", choices=models)
parser.add_argument("prompt")
args = parser.parse_args()

client = OpenAI(
    base_url="https://modelfold.ai/v1",
    api_key=os.environ["MODELFOLD_API_KEY"],
)
reply = client.chat.completions.create(
    model=models[args.model],
    messages=[{"role": "user", "content": args.prompt}],
)
print(reply.choices[0].message.content)
Enter fullscreen mode Exit fullscreen mode

python chat.py --help checks the available choices without making a request. To send a request, pick one of these commands. Each invocation sends its own billable request:

python chat.py gemini 'Write a one-sentence release note for CSV export.'
python chat.py deepseek 'Write a one-sentence release note for CSV export.'
python chat.py kimi 'Write a one-sentence release note for CSV export.'
Enter fullscreen mode Exit fullscreen mode

The names on the left of the dictionary are yours; the strings on the right are API identifiers. In particular, the Gemini ID here uses hyphens, not the punctuation in the product's display name. If a model isn't found, check the exact string against the model ID list. If the route isn't found, check base_url: the SDK appends the chat-completions path, so the base should end at /v1.

This example keeps only the text-chat fields in common. A shared request shape isn't a promise that the models support the same optional features, cost the same or produce equivalent answers. See the quickstart before extending the script.

Top comments (0)