Code
Python
The official openai package works as is. Change the base URL and the key; everything else is OpenAI’s SDK.
Checked 26 October 2026
Install and connect
pip install openai
export NOKEEP_API_KEY="sk-nokeep-test" # your own key once it connectsimport os
from openai import OpenAI
client = OpenAI(
base_url="https://nokeep.ai/v1",
api_key=os.environ["NOKEEP_API_KEY"],
)Send a message
reply = client.chat.completions.create(
model="deepseek-v4.1-flash-uncensored",
messages=[
{"role": "system", "content": "You are a blunt editor."},
{"role": "user", "content": "Cut this opening line to ten words: ..."},
],
)
print(reply.choices[0].message.content)
print("credits:", reply.usage.model_extra.get("nokeep_credits"))Stream
stream = client.chat.completions.create(
model="deepseek-v4.1-flash-uncensored",
messages=[{"role": "user", "content": "Write a limerick about a cat."}],
stream=True,
)
for chunk in stream:
if chunk.choices:
print(chunk.choices[0].delta.content or "", end="", flush=True)Async
import asyncio
import os
from openai import AsyncOpenAI
client = AsyncOpenAI(base_url="https://nokeep.ai/v1", api_key=os.environ["NOKEEP_API_KEY"])
async def main():
reply = await client.chat.completions.create(
model="deepseek-v4.1-flash-uncensored",
messages=[{"role": "user", "content": "Hello"}],
)
print(reply.choices[0].message.content)
asyncio.run(main())Errors
The SDK raises one exception per kind of error and retries 429 and 5xx on its own, waiting the Retry-After time. The code names what went wrong; Errors lists them all.
import openai
try:
reply = client.chat.completions.create(model="deepseek-v4.1-flash-uncensored", messages=messages)
except openai.APIStatusError as error:
print(error.status_code, error.body["error"]["code"])Fields the SDK has no argument for
Send min_p, top_k and repetition_penalty in extra_body={...}. See Samplers for fiction.