EN ▾
Get API key

Integrating Local NSFW API with Python SDK

Developers often struggle to configure uncensored text endpoints for reliable roleplay experiences. This guide outlines a step-by-step integration process using our Python SDK, focusing on the specific settings needed for consistent text-in, text-out flows.

Laptop screen showing Python code and terminal output for API integration

Understanding the API Structure

The foundation of integrating with our service begins with understanding its structure. We offer a hosted, OpenAI-compatible chat-completions API that serves one specific uncensored open-weight text model. This means you can use familiar tools and libraries if you are already accustomed to the OpenAI ecosystem. The model identifier you must send in your requests is simply uncensored. This ensures that the output is tailored for adult, fictional, security-research, or controversial topics without the typical refusals found in other models.

Our base URL for all API interactions is https://api.localnsfwllm.com/v1. It is important to note that this service is focused purely on text. We do not offer embeddings, image generation, audio processing, video creation, OCR, fine-tuning, or model routing. By keeping the scope narrow, we ensure high reliability for text-based applications. Developers looking for multimodal features should check the documentation of other vendors for those specific capabilities.

The context window for this API is 100,000 tokens, which includes both the prompt and the completion. This generous limit allows for long-running conversations and detailed character profiles without losing context. When integrating, ensure your client library can handle this token count efficiently. The API supports streaming over Server-Sent Events (SSE), which is important for real-time roleplay applications where users expect instant feedback.

Parameters such as temperature, top_p, stop sequences, seed, and penalties are fully supported. These allow you to fine-tune the creativity and consistency of the model. For instance, adjusting the temperature can make the responses more predictable or more diverse. Understanding these parameters is key to getting the best performance from the uncensored model we provide.

Setting Up Your Python Environment

Before writing any code, you need to set up your Python environment correctly. The most straightforward way to interact with our API is using the official OpenAI Python SDK, as our endpoint is fully compatible. You can install the SDK using pip, which is the standard package installer for Python. This library handles the HTTP requests, authentication, and response parsing for you, saving you time on implementation details.

Once installed, you will need to obtain an API key. You can sign up using your Google account or by creating an email and password. Upon registration, your API key is shown immediately, so make sure to copy it securely. This key is required for all requests to the API. You can test your connection by making a simple request to the /v1/models endpoint to verify that your key is valid and active.

It is important to manage your API key securely in your Python scripts. Avoid hardcoding the key directly in your source code. Instead, use environment variables or a configuration file to store it. This practice prevents accidental exposure of your credentials if you share your code or push it to a version control system. The SDK allows you to pass the key via environment variables, which is a common and safe practice.

After setting up the SDK and your key, you can begin constructing your first request. The API supports both standard chat completions and the newer responses format. For most roleplay applications, the chat completions endpoint is sufficient. Ensure that your Python script is configured to handle the specific base URL of our service, which differs from the default OpenAI endpoint.

Configuring Request Parameters

Configuring the request parameters correctly is essential for achieving the desired output from the uncensored model. The most critical parameter is the model ID, which must be set to uncensored. This tells the API which model to use for generating the response. Without this specific identifier, the API may not return the expected uncensored behavior.

Temperature is a key setting that controls the randomness of the output. A higher temperature value will result in more creative and varied responses, while a lower value will produce more consistent and deterministic outputs. For roleplay, you might experiment with different temperature values to find the right balance between creativity and coherence. The API also supports top_p, which further refines the sampling process.

Stop sequences allow you to define specific strings that will halt the generation process. This is useful for controlling the length of responses or ensuring that the model does not continue generating beyond a certain point. You can also set a seed value to make the output reproducible, which is helpful for debugging and testing. These parameters give you fine-grained control over the generation process.

Penalties are another important feature. They allow you to penalize certain tokens or phrases, which can help in steering the conversation or reducing repetitive behavior. By adjusting these parameters, you can tailor the API's behavior to fit the specific needs of your application. It is recommended to test different combinations of these settings to see how they affect the output quality.

Handling Responses and Streaming

Handling responses efficiently is important for a smooth user experience, especially in real-time applications. Our API supports streaming over Server-Sent Events (SSE), which allows you to receive tokens as they are generated. This is particularly useful for roleplay bots, where users expect immediate feedback. The SDK makes it easy to implement streaming by providing built-in support for SSE.

When using streaming, you receive usage information in the last chunk of the response. This includes the number of tokens used, which is important for tracking costs. Since our pricing is based on actual token usage, monitoring the token count helps you manage your prepaid credit effectively. Errors and refusals do not incur charges, so you only pay for the tokens that are successfully generated.

For applications that do not require real-time feedback, you can also use non-streaming responses. This approach waits for the entire response to be generated before returning it. While this may introduce a slight delay, it can be simpler to implement for some use cases. The choice between streaming and non-streaming depends on the specific requirements of your application.

It is also important to handle potential errors gracefully. The API returns specific error codes for different issues. A 401 error indicates an invalid key, a 402 error means you have no credit, and a 429 error signifies that you have exceeded the rate limit. By handling these errors appropriately, you can ensure that your application remains reliable and user-friendly.

Pricing and Credit Management

Understanding the pricing structure is important for managing your budget effectively. Our API charges $0.15 per 1 million input tokens and $0.50 per 1 million output tokens. This pay-as-you-go model means you only pay for what you use, with no monthly subscription fees. Prepaid credit is charged based on real token usage, and any unused credit never expires.

To add credit to your account, you can use crypto payments. We accept USDT on the TRC20 network or USDC on the Base network. You can top up with any whole amount between $20 and $500. Additionally, if you top up with $50 or more, you receive bonus credit ranging from 5% to 15%. This incentive makes larger top-ups more cost-effective for heavy users.

It is important to note that we do not accept credit cards, PayPal, or bank transfers. All payments must be made using the specified cryptocurrencies. This policy simplifies the payment process and reduces transaction fees. You can monitor your credit balance through the dashboard to ensure you have sufficient funds for your requests.

New accounts start with $0.50 of trial credit, allowing you to test the API without any initial investment. This trial credit is a great way to evaluate the service before committing to a larger top-up. By understanding the pricing and credit system, you can plan your usage and avoid unexpected charges.

When Our API Is Not the Right Choice

While our API is excellent for uncensored text generation, it may not be the right choice for every project. If you need image, audio, or video generation, our service does not offer these capabilities. We focus solely on text, so if your application requires multimodal outputs, you should look for a vendor that specializes in those areas.

Similarly, if you need embeddings for semantic search or fine-tuning for custom model behavior, our API does not support these features. We provide a simple text-in, text-out interface, which is ideal for chatbots and roleplay but may lack the advanced features needed for more complex AI applications. Always assess your specific needs before integrating.

Another consideration is the context window. While 100,000 tokens is generous, it may not be sufficient for applications that require extremely long-term memory or processing of massive documents. If your use case involves analyzing large datasets or maintaining context over very long periods, you might need a different solution.

Finally, if you require strict SLA guarantees or specific certifications like SOC2 or HIPAA, our service may not meet those requirements. We are an independent service that focuses on providing high-quality uncensored text generation without the overhead of enterprise-level compliance. For applications with strict regulatory needs, it is advisable to check the documentation of other vendors for current prices and limits.

Addressing Common Developer Questions

Developers often ask about the best way to handle repetitive responses in roleplay applications. Many users find that chatbot apps can feel repetitive after a while, with characters sounding similar regardless of the context. This is often due to the underlying model or the settings used for inference. By adjusting parameters like temperature and top_p, you can introduce more variety into the responses.

Another common question is how to maintain character consistency. Users want their characters to stay in role and not break the immersion. This can be achieved by providing detailed character descriptions and using stop sequences to control the output. Additionally, using a seed value can help ensure that the model generates consistent responses for similar inputs.

Developers also inquire about the best practices for integrating uncensored models. It is important to test the model with various prompts to understand its behavior. Some models may be better suited for certain types of content than others. By experimenting with different settings, you can find the optimal configuration for your specific use case.

Finally, many developers want to know how to handle errors and rate limits. Our API has a limit of 300 requests per minute per key. If you exceed this limit, you will receive a 429 error. To avoid this, you can implement exponential backoff in your code to retry requests after a delay. This ensures that your application remains responsive even under high load.

Frequently asked questions

How do I get an API key?

You can sign up using your Google account or an email and password. Your API key is shown immediately upon registration.

What is the model ID?

The model ID to send in your requests is 'uncensored'. This ensures you get the uncensored text model.

Does the API support streaming?

Yes, the API supports streaming over Server-Sent Events (SSE), which is ideal for real-time applications.

How is pricing calculated?

Pricing is $0.15 per 1M input tokens and $0.50 per 1M output tokens. You only pay for actual token usage.