本文へ移動
メイン ドキュメント
ドキュメント

Frameworks

Any framework that speaks OpenAI chat.completions works on two settings: the base URL and the model id. Each one's configuration, and where it tends to snag.

LangChain

Python
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(model="qwen3.8-flash-next-whitehacker", base_url="https://api.kotoba.cloud/v1",
                 api_key=os.environ["KOTOBA_API_TOKEN"], max_tokens=2048)
llm.invoke("Summarize the auth flow in this file: ...")

streaming=True works (the answer arrives as one chunk). bind_tools works on native tool_calls.

LlamaIndex

Python
from llama_index.llms.openai_like import OpenAILike
llm = OpenAILike(model="qwen3.8-flash-next-whitehacker", api_base="https://api.kotoba.cloud/v1",
                 api_key=os.environ["KOTOBA_API_TOKEN"], is_chat_model=True, max_tokens=2048)

Use OpenAILike, not OpenAI (it does not reject an unknown model id).

Vercel AI SDK

TypeScript
import { createOpenAI } from "@ai-sdk/openai";
import { generateText } from "ai";

const kotoba = createOpenAI({ baseURL: "https://api.kotoba.cloud/v1", apiKey: process.env.KOTOBA_API_TOKEN });
const { text } = await generateText({ model: kotoba.chat("qwen3.8-flash-next-whitehacker"), maxTokens: 2048, prompt: "..." });

Use kotoba.chat(...): the default kotoba(...) may pick the Responses API, which is 405 here.

OpenAI Agents SDK

Python
from agents import Agent, Runner, OpenAIChatCompletionsModel, set_tracing_disabled
from openai import AsyncOpenAI

client = AsyncOpenAI(base_url="https://api.kotoba.cloud/v1", api_key=os.environ["KOTOBA_API_TOKEN"])
set_tracing_disabled(True)   # tracing posts to OpenAI, not here
agent = Agent(name="reviewer", model=OpenAIChatCompletionsModel(model="qwen3.8-flash-next-whitehacker", openai_client=client))
Runner.run_sync(agent, "Review src/auth.py")

Name OpenAIChatCompletionsModel explicitly (the default is the Responses API).

LiteLLM

Python
import litellm
litellm.completion(model="openai/qwen3.8-flash-next-whitehacker", api_base="https://api.kotoba.cloud/v1",
                   api_key=os.environ["KOTOBA_API_TOKEN"], max_tokens=2048,
                   messages=[{"role": "user", "content": "..."}])

The openai/ prefix pins chat.completions. For proxy mode see the Anthropic SDK page.

Common snags