NuevoConecta cualquier agente a UberLLM: una clave, todos los modelos, a precio de lista o menos.
UberLLM

LangChain

El ChatOpenAI de LangChain (desde langchain-openai) apunta a UberLLM con un base_url y api_key. Todo lo demás — chains, agents, tools, streaming — funciona sin cambios.

Instalar

pip install langchain langchain-openai

Python

import os
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="deepseek/deepseek-v4-flash",
    base_url="https://api.uberllm.dev/v1",
    api_key=os.environ["UBERLLM_API_KEY"],
)

print(llm.invoke("Say hello in one sentence.").content)

base_url tiene precedencia sobre las variables de entorno OPENAI_API_BASE / OPENAI_BASE_URL, por lo que un kwarg explícito es lo más fiable.

Streaming

for chunk in llm.stream("Count to five."):
    print(chunk.content, end="", flush=True)

Herramientas / agentes

Dado que ChatOpenAI utiliza el formato de llamada a herramientas de OpenAI, bind_tools y los ejecutores de agentes funcionan tal cual con cualquier modelo UberLLM compatible con herramientas:

from langchain_core.tools import tool

@tool
def get_weather(city: str) -> str:
    "Return the weather for a city."
    return f"Sunny in {city}."

agent_llm = llm.bind_tools([get_weather])
print(agent_llm.invoke("What's the weather in Paris?").tool_calls)

JavaScript / TypeScript

import { ChatOpenAI } from "@langchain/openai";

const llm = new ChatOpenAI({
  model: "deepseek/deepseek-v4-flash",
  apiKey: process.env.UBERLLM_API_KEY,
  configuration: { baseURL: "https://api.uberllm.dev/v1" },
});

const res = await llm.invoke("Say hello in one sentence.");
console.log(res.content);

Notas

  • Cada llamada se envía a un proveedor externo disponible para el modelo (Modelos y enrutamiento).
  • Cada llamada se factura según lo que cobró el proveedor, sin tarifa de UberLLM (Precios).