Skip to content
All docs

Code

LlamaIndex

Use LlamaIndex’s OpenAILike class with the base URL, your key and a model id. Set four flags it can’t guess, and the rest of LlamaIndex works on top.

Checked 29 October 2026

Install and connect

Shell
pip install llama-index-core llama-index-llms-openai-like
export NOKEEP_API_KEY="sk-nokeep-test"  # your own key once it connects
llm.py
import os
from llama_index.llms.openai_like import OpenAILike

llm = OpenAILike(
    model="deepseek-v4.1-flash-uncensored",
    api_base="https://nokeep.ai/v1",
    api_key=os.environ["NOKEEP_API_KEY"],
    is_chat_model=True,
    is_function_calling_model=True,
    context_window=1000000,
    temperature=0.8,
)

print(llm.complete("Name three good names for a tavern.").text)
  • is_chat_model=True sends chat completions. Without it, LlamaIndex calls /v1/completions, which nokeep doesn’t have.
  • is_function_calling_model=True lets agents and chat_with_tools send tools.
  • context_window defaults to 3,900 tokens, so LlamaIndex trims long chats and retrieved text to fit. Set it to the model’s real context: 1,000,000 for DeepSeek, 128,000 for GLM.
  • temperature defaults to 0.1, which makes fiction flat and repetitive. Set your own.

Chat and stream

Python
from llama_index.core.llms import ChatMessage

messages = [
    ChatMessage(role="system", content="You are a blunt editor."),
    ChatMessage(role="user", content="Cut this opening line to ten words: ..."),
]
print(llm.chat(messages).message.content)

for part in llm.stream_chat(messages):
    print(part.delta, end="", flush=True)

Tools and agents

Python
import asyncio
from llama_index.core.agent.workflow import FunctionAgent

def get_weather(city: str) -> str:
    """Get the weather in a city."""
    return f"18°C and clear in {city}"

agent = FunctionAgent(
    tools=[get_weather],
    llm=llm,
    system_prompt="You answer questions about the weather.",
)

async def main():
    print(await agent.run("What's the weather in Lisbon?"))

asyncio.run(main())

For one call with tools and no loop, use llm.chat_with_tools([tool], user_msg=...) and read the calls with llm.get_tool_calls_from_response(...). See Tool calls.

Thinking and other fields

Python
import os
from llama_index.llms.openai_like import OpenAILike

thinker = OpenAILike(
    model="deepseek-v4.1-flash-uncensored",
    api_base="https://nokeep.ai/v1",
    api_key=os.environ["NOKEEP_API_KEY"],
    is_chat_model=True,
    context_window=1000000,
    max_tokens=4000,
    additional_kwargs={"reasoning_effort": "high", "min_p": 0.05},
)

additional_kwargs goes into every request as it is. Thinking counts toward max_tokens, so give it room. See Thinking.

Gotchas

  • `reasoning_effort` takes only the model’s own values. deepseek-v4.1-flash-uncensored takes none, low, high, max; glm-5.3-flash-uncensored takes low, high. Other apps’ minimal, medium and xhigh run at the model’s nearest level (medium as high, xhigh as max where the model has it); any other value gets 400 invalid_reasoning_effort. See Thinking.
  • GLM picks its own tools. glm-5.3-flash-uncensored takes tool_choice auto or none only. Forcing a tool (required, or naming a function) gets 400 unsupported_tool_choice. Use DeepSeek when you need to force one.
  • Fields a model can’t take are dropped, not refused. The call still answers, and the x-nokeep-ignored response header names what was left out. GLM keeps only tools, tool_choice and reasoning_effort, so its temperature and response_format are dropped. See which fields each model takes.
  • `n` must be 1. Ask for several replies with several calls.
  • Chat completions only. There is no /v1/responses and no /v1/embeddings; a framework that defaults to either needs to be pointed at chat completions, and embeddings need another provider.

For a RAG app, set Settings.llm = llm and keep your embedding model where it is: nokeep runs the chat model, not the embeddings. With glm-5.3-flash-uncensored, the temperature LlamaIndex sends on every call is dropped and named in x-nokeep-ignored.

Questions

Why OpenAILike and not OpenAI?

LlamaIndex’s OpenAI class checks the model name against its own list and refuses names it doesn’t know. OpenAILike takes any name and any base URL.

Does LlamaIndex index my documents on nokeep?

No. Indexing and embeddings run where you set them up. Only the chat calls reach nokeep, and nokeep keeps only token counts for each one.