EN ▾
Get API key

Integrating WanAPI with Ollama Locally

Connecting local language models to cloud-based endpoints is a common workflow for developers seeking uncensored text generation. This guide details how to configure your SDK and environment variables to ensure reliable text-in, text-out operations with our API.

Developer workspace showing integration between local code and cloud text API

Understanding the API Architecture

Our API is designed as a hosted, OpenAI-compatible service that serves a single uncensored open-weight text model. The model identifier you must send is simply uncensored. This simplicity means you do not need to manage multiple model versions or routing logic. The service handles text input and returns text output, focusing exclusively on this core capability. You will interact with the API through standard HTTP methods, primarily POST requests for completions and responses.

The base URL for all requests is https://api.wanapi.cc/v1. This URL remains constant regardless of the specific endpoint you are calling. You will use the /v1/chat/completions endpoint for standard conversational flows and the /v1/responses endpoint for newer response formats. Additionally, you can use GET /v1/models to verify available models, though only the uncensored model is active. This consistent URL structure simplifies integration across different programming languages and frameworks.

It is important to note that this service does not offer embeddings, image generation, audio processing, or video creation. There is no OCR capability, no fine-tuning options, and no model routing features. If your project requires these additional capabilities, you will need to integrate other services alongside this text-focused API. The API is strictly for text generation, ensuring high performance for that specific task without the overhead of multimodal processing.

The context window for this API is 100,000 tokens, which includes both the prompt and the completion. This large context window allows for extensive document analysis and long-form content generation. You can send large blocks of text and receive coherent responses that maintain context over long distances. This feature is particularly useful for developers building applications that require deep understanding of large documents or extended conversational histories.

Configuration and Environment Variables

To integrate with our API, you need to configure your SDK with the correct base URL and authentication headers. The base URL is https://api.wanapi.cc/v1, which should be set in your environment variables. This ensures that your application can easily switch between different environments without hardcoding the URL. You should also set the API key in the Authorization header, which is generated immediately after signup.

Signups can be done via Google or using an email and password combination. Once registered, your API key is shown immediately, allowing you to start making requests without delay. The key is unique to your account and should be kept secure. You can generate multiple keys if needed, but each key is tied to your prepaid credit balance. This flexibility allows you to manage different projects or environments with separate keys.

When configuring your SDK, ensure that you are using the correct model ID, which is uncensored. This ID must be included in every request to the /v1/chat/completions endpoint. The API will ignore any other model IDs, so using the correct one is important for successful responses. You can also explore other parameters such as temperature, top_p, stop sequences, and seed values to control the output behavior.

Streaming is supported over Server-Sent Events (SSE), which allows you to receive usage information in the last chunk of the response. This feature is useful for real-time applications where you need to display text as it is generated. You can also use function calling and JSON mode to structure your outputs more precisely. These features enhance the flexibility of the API, allowing you to build complex applications that require structured data or dynamic tool usage.

Pricing and Credit Management

The pricing model for our API is straightforward and based on token usage. You are charged $0.15 per 1 million input tokens and $0.50 per 1 million output tokens. This prepaid credit system means you pay only for what you use, with no monthly subscription fees. Your credit never expires, so you can use it whenever you need it. Errors and refusals are free, which means you do not pay for failed requests or content that is filtered out.

To add credit, you can use crypto payments, specifically USDT on the TRC20 network or USDC on the Base network. The minimum top-up amount is $20, and the maximum is $500. If you top up $50 or more, you receive a bonus credit ranging from 5% to 15%. This bonus credit is added to your account immediately, allowing you to start using the API with extra funds. No cards, PayPal, or bank transfers are accepted, so you must have a crypto wallet to fund your account.

Every new account receives $0.50 of trial credit, which requires no card verification. This allows you to test the API without any financial commitment. The trial credit is sufficient for a small number of requests, giving you a good sense of the API's performance and output quality. You can use this trial credit to experiment with different parameters and see how they affect the generated text.

When estimating costs, remember that the price is based on token counts, not characters. You can estimate the number of tokens by dividing the character count by approximately 4, though this is a rough estimate. For more accurate pricing, you can use the tokenizers provided by most SDKs. This helps you budget your usage and avoid unexpected charges. The prepaid system ensures that you always know exactly how much credit you have available.

SDK Integration and Code Examples

Integrating our API with your application is straightforward, thanks to its OpenAI compatibility. You can use any SDK that supports the OpenAI API format, such as the Python, JavaScript, or Go SDKs. Simply set the base URL to https://api.wanapi.cc/v1 and your API key in the authentication header. The model ID should be set to uncensored for all requests. This compatibility allows you to use familiar tools and libraries to interact with our API.

Here is a simple example of how to make a request using the Python SDK. You can install the SDK using pip and then import it into your project. Set the base URL and API key in the client initialization. Then, make a POST request to the /v1/chat/completions endpoint with the desired parameters. The response will contain the generated text, which you can process as needed.

You can also use streaming to receive responses in real-time. This is useful for applications that display text as it is generated, such as chatbots or live documentation tools. The streaming feature uses Server-Sent Events, which allows you to receive chunks of text as they are produced. You can handle these chunks in your application to provide a smooth user experience.

Function calling and JSON mode are also supported, allowing you to structure your outputs more precisely. You can define tools that the model can call, and the API will return the tool calls in the response. This is useful for applications that require structured data or dynamic tool usage. You can also use JSON mode to ensure that the output is valid JSON, which is useful for integrating with other systems.

Error Handling and Rate Limits

When integrating with our API, it is important to handle errors and rate limits correctly. The API returns specific error codes to help you diagnose issues. A 401 error indicates an invalid API key, which means you should check your authentication header. A 402 error indicates that you have no credit left, which means you need to top up your account. A 429 error indicates that you have exceeded the rate limit of 300 requests per minute per key.

To handle rate limits, you can implement exponential backoff in your application. This means that if you receive a 429 error, you wait for a short period before retrying the request. The wait time increases with each retry, which helps to prevent overwhelming the API. This is particularly useful for applications that make many requests in a short period, such as batch processing or real-time data ingestion.

Errors and refusals are free, which means you do not pay for failed requests or content that is filtered out. This is important to note when budgeting your usage. You can test your application with different inputs to see how the API handles various scenarios. This helps you understand the behavior of the API and adjust your application accordingly.

The hard content limit for our API is that it refuses requests involving sexual content with minors. This limit is enforced by the model, so you do not need to implement additional filtering in your application. However, you should be aware of this limit when designing your application, especially if it is intended for a broad audience. You can also implement your own filtering logic if you need more control over the content.

When Our API Is Not the Right Choice

While our API is excellent for text generation, it may not be the right choice for every project. If you need image generation, audio processing, or video creation, our API will not meet your needs. The API is strictly for text, so you will need to integrate other services for multimodal tasks. Similarly, if you require embeddings for semantic search or fine-tuning for custom model behavior, our API does not offer these features.

OCR capabilities are also not available, so if you need to extract text from images, you will need a separate service. Model routing is another feature that is not supported, meaning you cannot switch between different models based on your needs. If your application requires these capabilities, you will need to build a more complex architecture that integrates multiple services.

Additionally, if you need on-premises deployment for data privacy or compliance reasons, our hosted API may not be suitable. The API is hosted on our servers, so your data is processed there. If you need to keep your data on your own infrastructure, you may need to look for a different solution. However, for most text generation tasks, our API provides a reliable and cost-effective solution.

Finally, if you need a free unlimited tier, our API may not be the best fit. While we offer a trial credit, all other usage is prepaid. If you have a high volume of requests and want to avoid per-token costs, you might need to consider a different pricing model. However, for most developers and indie builders, the prepaid model offers flexibility and control over costs.

Common Developer Questions and Answers

Developers often ask how to estimate token usage for budgeting purposes. The best way to estimate is to use the tokenizers provided by your SDK. These tokenizers convert text into tokens, which you can then multiply by the per-million price to get the cost. For example, if you have 10,000 tokens, the cost for input tokens would be 10,000 divided by 1,000,000 times $0.15. This method gives you a precise estimate of your costs.

Another common question is how to handle streaming responses. Streaming is supported over Server-Sent Events, which allows you to receive text as it is generated. You can handle these chunks in your application to provide a real-time experience. The usage information is included in the last chunk, so you can track your token usage in real-time. This is useful for applications that need to display text immediately.

Developers also ask about the difference between the /v1/chat/completions and /v1/responses endpoints. The /v1/chat/completions endpoint is the standard OpenAI-compatible endpoint for chat-based interactions. The /v1/responses endpoint is a newer format that may offer additional features or better performance. You can use either endpoint depending on your needs, but most SDKs are optimized for the chat-completions endpoint.

Finally, developers often ask about the bonus credit for top-ups. If you top up $50 or more, you receive a bonus credit ranging from 5% to 15%. This bonus is added to your account immediately, allowing you to start using the API with extra funds. The bonus credit is a great way to get more value from your top-ups, especially if you are planning to use the API extensively.

Frequently asked questions

How do I get an API key?

You can sign up using Google or an email and password. Your API key is shown immediately after registration, allowing you to start making requests without delay.

What is the context window size?

The context window is 100,000 tokens, which includes both the prompt and the completion. This allows for extensive document analysis and long-form content generation.

How do I add credit to my account?

You can top up using USDT on TRC20 or USDC on Base. The minimum amount is $20, and the maximum is $500. Bonus credit is available for top-ups of $50 or more.

Does the API support image generation?

No, the API is strictly for text generation. It does not support image, audio, video, or OCR capabilities. You will need to integrate other services for multimodal tasks.