Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.kymaapi.com/llms.txt

Use this file to discover all available pages before exploring further.

Install

pip install langchain-openai

Setup

from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    base_url="https://kymaapi.com/v1",
    api_key="ky-your-api-key",
    model="qwen-3.6-plus",
)

Basic Usage

response = llm.invoke("Explain RAG in simple terms")
print(response.content)

Streaming

for chunk in llm.stream("Write a short story"):
    print(chunk.content, end="", flush=True)

With Prompt Template

from langchain_core.prompts import ChatPromptTemplate

prompt = ChatPromptTemplate.from_messages([
    ("system", "You are a {role}."),
    ("user", "{question}")
])

chain = prompt | llm

response = chain.invoke({
    "role": "Python expert",
    "question": "How do decorators work?"
})
print(response.content)

Tool Calling

from langchain_core.tools import tool

@tool
def get_weather(city: str) -> str:
    """Get weather for a city."""
    return f"Sunny, 72°F in {city}"

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

RAG Example

from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate

llm = ChatOpenAI(
    base_url="https://kymaapi.com/v1",
    api_key="ky-your-api-key",
    model="gemini-2.5-flash",  # 1M context for large documents
)

prompt = ChatPromptTemplate.from_messages([
    ("system", "Answer based on the following context:\n\n{context}"),
    ("user", "{question}")
])

chain = prompt | llm

response = chain.invoke({
    "context": "Your retrieved documents here...",
    "question": "What is the main topic?"
})
Use CaseModelWhy
General chainsqwen-3.6-plusBest overall quality
RAG / long docsgemini-2.5-flash1M context window
Tool callingkimi-k2.6Best function calling
Fast responsesqwen-3-32bUltra-fast inference
Kyma’s API is OpenAI-compatible, so langchain-openai / @langchain/openai work directly. No special package needed.