EN ▾
Start now

Integrating an Uncensored LLM API with Python

Connecting an uncensored language model to your Python scripts requires understanding the specific endpoint structure and token limits. This guide walks you through the essential steps for integration, from initial configuration to handling streaming responses.

Server rack with glowing data streams representing an uncensored LLM API

Setting Up the Base Connection

Begin by importing the necessary libraries for HTTP requests or using the official OpenAI Python SDK. Since our API is OpenAI-compatible, you can use existing client libraries with minimal adjustments. Set your base URL to https://api.llmnsfw.com/v1 and ensure you are using the model identifier uncensored for all requests. This model is an open-weight text model designed for uncensored output, meaning it does not refuse lawful adult, fictional, or controversial topics.

You will need to obtain an API key during signup. You can continue with Google or use an email and password combination. The key is shown immediately after registration, so copy it securely. This key is required for all subsequent requests to the /v1/chat/completions endpoint. Without a valid key, you will receive a 401 error, indicating an invalid or missing key.

It is important to note that this service is an independent offering. It is not an official partner or reseller of any major tech company. The API serves only text-in and text-out requests. There are no embeddings, image generation, audio processing, or video capabilities. If you need those features, you will need to integrate additional services separately.

When initializing your client, ensure you handle the API key securely. Avoid hardcoding it in your source code if you are sharing your project. Use environment variables or a configuration file to store the key. This practice helps prevent accidental exposure of your credentials, especially if you are working in a team or publishing your code to a public repository.

Configuring the System Prompt

The system prompt is important for defining the behavior of the uncensored model. It sets the context and rules for how the model should respond. For an uncensored LLM, you might want to instruct the model to stay in character or avoid standard safety refusals. This is particularly useful for role-playing applications or creative writing where the model needs to explore mature themes without interruption.

Construct your system prompt to be clear and specific. For example, you might define a character's personality, speech patterns, and boundaries. Since the model is uncensored, it will not refuse lawful adult content, but it will refuse sexual content involving minors. Ensure your prompt reflects this limit to avoid unwanted refusals during generation.

You can also use the system prompt to define the format of the responses. If you are building a chatbot, you might want the model to respond in a specific JSON format or with a certain tone. The uncensored model is flexible and can adapt to various prompting styles. Experiment with different prompts to find the one that best fits your application's needs.

Remember that the system prompt is part of the context window, which is limited to 100,000 tokens. This includes both the prompt and the completion. Be mindful of the length of your system prompt to ensure you have enough space for the conversation history and the model's response. If your prompt is too long, it may consume too much of the context window, leaving less room for the actual dialogue.

Handling Text Responses and Streaming

Once you have configured the system prompt and sent a request, you need to handle the response. The API supports streaming over Server-Sent Events (SSE), which allows you to receive the model's output in real-time. This is particularly useful for chat applications where you want to display the response as it is being generated, rather than waiting for the entire response to complete.

When using streaming, the usage information is provided in the last chunk of the response. This allows you to track token consumption accurately. The API charges based on real token usage, with errors and refusals being free. The price is $0.15 per 1 million input tokens and $0.50 per 1 million output tokens. Prepaid credit is charged by real token usage, and paid credit never expires.

For non-streaming requests, you receive the full response at once. This can be simpler to implement but may result in a longer wait time for the user. Choose the method that best suits your application's user experience requirements. If you are building a simple script or a batch processing tool, non-streaming might be sufficient. For interactive chatbots, streaming is generally preferred.

Ensure your code handles the streaming response correctly. You should process each chunk as it arrives and update your user interface accordingly. This provides a smoother and more engaging experience for the user. Additionally, you can use the stream parameter to enable streaming in your API requests.

Managing Tokens and Pricing

Understanding token usage is essential for managing your costs. The API charges based on the number of tokens in the input and output. The context window is 100,000 tokens, which includes both the prompt and the completion. This means you have a significant amount of space for conversation history and complex prompts.

To estimate costs, you can use the formula: (tokens divided by 1,000,000) times the per-million price. For example, if you use 100,000 input tokens, the cost would be (100,000 / 1,000,000) * $0.15. This helps you budget for your API usage and avoid unexpected charges. Keep in mind that errors and refusals are free, so you only pay for successful completions.

You can top up your credit using crypto only. The accepted currencies are USDT on TRC20 or USDC on Base. The minimum top-up amount is $20, and the maximum is $500. If you top up from $50, you may receive bonus credit ranging from +5% to +15%. This can help you get more value for your money. There are no monthly fees or subscriptions, so you only pay for what you use.

Monitor your token usage regularly to ensure you are not exceeding your budget. You can check your remaining credit in your account dashboard. If you run out of credit, you will receive a 402 error, indicating that you have no credit. You can top up your account at any time to continue using the API.

When This API Is Not the Right Choice

While our API is powerful for text generation, it may not be the right choice for every project. If you need image generation, audio processing, or video creation, this API will not meet your needs. The service is focused solely on text-in and text-out requests. It does not support embeddings, OCR, or fine-tuning. If your application requires these features, you will need to integrate additional services or choose a different provider.

Additionally, if you are looking for a provider with an SLA guarantee or certifications like SOC2 or HIPAA, this service may not be suitable. The provider does not claim these certifications or offer on-prem deployment options. If data privacy and compliance are critical for your application, you should verify these details with other providers.

Furthermore, if you need a provider with a wide range of model routing options or benchmark scores, this API offers a single uncensored model. It does not support model routing or multiple model versions. If you require flexibility in choosing different models for different tasks, you might want to explore other options.

Finally, if you prefer to pay with credit cards or PayPal, this service only accepts crypto payments. The top-up process requires USDT on TRC20 or USDC on Base. If you are not comfortable with cryptocurrency, this payment method might be a barrier. Consider these factors before deciding if this API is the right fit for your project.

Addressing Common Developer Questions

Developers often ask about the best models for local deployment with limited hardware. Discussions on Reddit threads, such as those on r/LocalLLaMA, highlight the challenge of running smart uncensored LLMs on machines with 20GB VRAM and 24GB RAM. Users seek models that are fast, creative, and can stay in character. While our API is hosted, the principles of prompt engineering and model selection apply similarly.

Another common question is how to choose the best NSFW LLM for a local chatbot website. Users with hardware like an RTX 5080 with 16GB VRAM and 64GB DDR5 RAM often look for models that balance performance and quality. Our API offers a hosted solution that removes the need for local hardware constraints, allowing you to access a powerful uncensored model without managing local resources.

Developers also inquire about the best RP NSFW LLM for role-playing. The focus is often on maintaining character and immersion. Our uncensored model is designed to handle these scenarios effectively, providing a smooth experience for role-playing applications. You can configure the system prompt to enhance the role-playing experience and ensure the model stays in character.

Finally, users ask about setting up NSFW LLMs for writing, especially for those who are not very technical. They often use tools like LM Studio and download various models. Our API simplifies this process by providing a hosted solution with an OpenAI-compatible endpoint. You can integrate it into your Python scripts without needing to manage local model files or hardware specifications.

Troubleshooting and Error Handling

When integrating the API, you may encounter various errors. A 401 error indicates an invalid or missing API key. Ensure that you have copied the key correctly and that it is included in the request headers. A 402 error means you have no credit. You can top up your account using crypto to resolve this issue. A 429 error indicates that you have exceeded the rate limit of 300 requests per minute per key.

To handle these errors, implement retry logic in your code. If you receive a 429 error, wait for a short period before retrying the request. This helps prevent overwhelming the API and ensures smooth operation. You can also monitor your API usage to ensure you are not approaching the rate limit.

Additionally, ensure that your requests are formatted correctly. The API expects specific parameters for the chat completions endpoint. If you send an invalid request, you may receive an error. Refer to the API documentation for the correct format and parameters. This includes the model ID, messages, and optional parameters like temperature and top_p.

Finally, test your integration thoroughly before deploying it to production. Use the trial credit of $0.50 to test your scripts and ensure they work as expected. This allows you to identify and fix any issues before you start using your paid credit. Regular testing helps maintain a stable and reliable application.

Frequently asked questions

How do I get started with the API?

Sign up using Google or email to receive an API key immediately. Then, configure your Python client with the base URL https://api.llmnsfw.com/v1 and use the model ID 'uncensored' for your requests.

What payment methods are accepted?

The API accepts only crypto payments. You can top up with USDT on TRC20 or USDC on Base. The minimum top-up amount is $20, and the maximum is $500.

Is there a free trial?

Yes, every new account receives $0.50 of trial credit. No credit card is required to start. You can use this to test the API before purchasing credit.

What are the rate limits?

The API allows 300 requests per minute per key. If you exceed this limit, you will receive a 429 error. Implement retry logic in your code to handle this gracefully.