EN ▾
Get API key

Integrating NSFW TTS with Node.js SDK

Developers often seek a straightforward way to接入 uncensored text generation without the overhead of image or audio models. This guide walks you through configuring the Node.js SDK to connect with our API, ensuring you can send text and receive text efficiently. We focus on the specific settings required for our endpoint, helping you avoid common configuration pitfalls.

Server rack with glowing data streams and code symbols representing API integration

Setting Up the Node.js Environment

Before diving into the code, you need to prepare your development environment. Our API is designed to be compatible with standard OpenAI clients, which means you can use the official Node.js SDK or any compatible library. First, ensure you have Node.js installed on your machine. Then, create a new project directory and initialize it with npm. This will allow you to manage dependencies easily.

Install the OpenAI Node.js package using your preferred package manager. This package provides the necessary classes to interact with our API. You will also need to install a dotenv package to manage your API key securely. This prevents hardcoding sensitive information in your source files. Keep your key in a .env file and load it at the start of your application.

Next, import the OpenAI client in your JavaScript file. Configure the client with your API key and the base URL. The base URL for our service is https://api.nsfwtts.com/v1. This tells the client where to send your requests. Without the correct base URL, your requests will fail to reach our uncensored model.

Finally, verify that your environment is set up correctly by printing the client configuration. Ensure that the key is loaded and the base URL is correct. This simple setup step is important for all subsequent interactions. Once the environment is ready, you can proceed to make your first API call.

Configuring the API Client

With the environment ready, the next step is to configure the API client properly. Our API uses a standard OpenAI-compatible format for chat completions. You need to set the model ID to "uncensored" to access our specific text model. This model is designed to handle adult and controversial topics without the usual refusals.

Set the API key in the client configuration. This key is generated when you sign up via Google or email. It is shown immediately upon creation, so you can use it right away. The key is unique to your account and is used for authentication on every request. Keep it secure and do not share it publicly.

Configure the base URL to point to our service. This is https://api.nsfwtts.com/v1. Ensure that you do not include any trailing slashes unless the SDK requires them. The client will handle the rest of the URL structure. This configuration ensures that your requests are routed to the correct endpoint.

Test the connection by making a simple request. Send a message to the API and check for a response. If you receive a valid response, your configuration is correct. If you encounter errors, check your key and base URL. This step confirms that your client is ready for more complex interactions.

Handling Streaming Responses

Our API supports streaming responses over Server-Sent Events (SSE). This allows you to receive text tokens as they are generated, providing a smoother user experience. To enable streaming, set the stream parameter to true in your request. This tells the API to send chunks of text instead of waiting for the full response.

Implement a stream handler in your Node.js code. This handler processes each chunk of text as it arrives. You can append these chunks to a buffer or display them in real-time. Streaming is particularly useful for long responses, as it reduces the perceived latency for the user.

Monitor the usage information provided in the last chunk of the stream. This chunk contains details about the tokens consumed. You can use this information to track your credit usage. Our API charges $0.15 per million input tokens and $0.50 per million output tokens. Streaming helps you manage these costs more effectively.

Handle potential errors during streaming. If the connection drops or an error occurs, your code should handle it gracefully. Retry logic can be implemented to reconnect if necessary. This ensures that your application remains reliable even during network interruptions. Streaming adds complexity but offers significant benefits for user experience.

Managing Payments and Credit

Our API operates on a prepaid credit model. You can top up your account using cryptocurrency, specifically USDT on the TRC20 network or USDC on the Base network. The minimum top-up amount is $20, and the maximum is $500. This flexibility allows you to scale your usage as needed.

When you top up, you may receive bonus credit. For example, topping up from $50 may grant you a bonus ranging from 5% to 15%. This bonus is added to your account immediately. Credits never expire, so you can use them at your own pace. This model is ideal for developers who want predictable costs.

Errors and refusals are free of charge. This means you only pay for successful text generation. If your request fails due to an invalid key or rate limit, no credit is deducted. This feature protects your budget from wasted requests. Always check your account balance before making large batches of requests.

Track your usage through the API responses. Each response includes token counts that help you estimate costs. You can calculate the cost by dividing the token count by one million and multiplying by the per-million price. This transparency allows you to manage your budget effectively. Keep an eye on your balance to avoid service interruptions.

Testing Your Integration

Once your integration is set up, it is time to test it thoroughly. Start with a simple text request to verify that the API responds correctly. Send a prompt and check that the response is valid. This basic test ensures that your configuration is correct.

Test streaming functionality by sending a longer prompt. Verify that the chunks arrive in order and that the final chunk contains usage information. This test confirms that your stream handler is working as expected. Pay attention to any delays or missing chunks.

Check error handling by sending invalid requests. Try using an incorrect API key to trigger a 401 error. Then, try exceeding the rate limit to trigger a 429 error. Ensure that your code handles these errors gracefully. This step is important for production readiness.

Finally, test the uncensored nature of the model. Send a request with adult or controversial content and verify that it is not refused. Our model does not refuse lawful adult topics, so you should receive a response. This test confirms that you are using the correct model ID. A successful integration allows you to build powerful applications.

When Our API Is Not the Right Choice

While our API excels at uncensored text generation, it may not be the right choice for every project. Our service focuses solely on text-in, text-out interactions. If you need image generation, audio synthesis, or video creation, our API does not support these features. You would need to integrate with a different provider for those capabilities.

Similarly, if you require embeddings for semantic search, our API does not offer this functionality. The model is designed for chat completions, not for generating vector representations of text. Projects that rely heavily on RAG systems might find our API limited in this regard.

Our API also does not support fine-tuning. If you need to train the model on your specific dataset, you will need to look elsewhere. The model is pre-trained and uncensored, but you cannot customize its weights. This is a trade-off for the ease of use and immediate availability.

Additionally, if you need on-premises deployment for data privacy, our hosted service may not fit your needs. We do not offer on-prem options. For projects requiring strict data control, a self-hosted solution might be more appropriate. Evaluate your specific requirements before committing to our API.

Addressing Common Developer Questions

Developers often ask how to handle rate limits when integrating with our API. Our service allows 300 requests per minute per key. If you exceed this limit, you will receive a 429 error. To manage this, implement exponential backoff in your code. This ensures that your application does not overwhelm the API.

Another common question is about the difference between our API and other vendors. While many providers offer similar features, our focus is on uncensored text without the overhead of other modalities. We do not claim to be an official partner of any major vendor. Always check the vendor's documentation for their specific prices and limits.

Users also inquire about the trial credit. Every new account receives $0.50 of trial credit, no card required. This allows you to test the API without immediate payment. However, the trial credit is limited, so you will need to top up for sustained usage. This feature is great for initial testing.

Finally, developers ask about the model's behavior with controversial topics. Our model does not refuse lawful adult or controversial content. However, it does refuse sexual content involving minors. This hard limit is enforced to ensure compliance. Understanding this behavior helps you design your application accordingly.

Frequently asked questions

How do I set up the base URL for our API?

Set the base URL to https://api.nsfwtts.com/v1 in your OpenAI-compatible client. This ensures requests reach our uncensored text endpoint. Verify this setting before making any calls.

What model ID should I use?

Use the model ID "uncensored" to access our specific text model. This model handles adult and controversial topics without refusal. It is the only model available for text generation.

How are payments processed?

Payments are accepted via crypto only, specifically USDT on TRC20 or USDC on Base. Top-ups range from $20 to $500. Credits never expire and are charged by real token usage.

Does the API support streaming?

Yes, the API supports streaming over Server-Sent Events (SSE). Enable this by setting the stream parameter to true. This allows real-time text output, improving user experience.