On this page

Can I use the OpenAI SDK with ModelRiver?

Updated

Yes. ModelRiver speaks the OpenAI Chat Completions format, so you change two things, the base URL and the API key, and set model to your workflow's name. Everything else in your code stays the same.

What do I change?#

from openai import OpenAI

client = OpenAI(
    base_url="https://api.modelriver.com/v1",
    api_key="mr_live_...",   # your ModelRiver API key
)

reply = client.chat.completions.create(
    model="support_reply",   # your ModelRiver workflow name
    messages=[{"role": "user", "content": "Where is my order?"}],
)

In Node.js it's baseURL and apiKey. The same works for LangChain, LlamaIndex and the Vercel AI SDK.

Why is model a workflow name, not a model like gpt-4o?#

Because the workflow decides the provider, model, backups and instructions. Your code asks for support_reply, and you can move it from one provider to another in the console without touching the app.

Does it work with Claude, Gemini and other models too?#

Yes. The workflow can use any connected provider. ModelRiver converts the request and response, so your OpenAI-style code gets answers from Anthropic, Google, Mistral or any other supported provider.

What isn't supported?#

  • functions and function_call (the old style). Use tools and tool_choice instead; they're supported.
  • logprobs and top_logprobs
  • n greater than 1

Streaming with stream: true works as usual.

Can I keep conversation memory?#

Yes. Send session_id in the request body; it's returned in the x-modelriver-session-id header. See Do I have to send the whole chat history?

Learn more#

Was this article helpful?