Troubleshooting Ollama API Migration: Handling Prompts and Limits
Moving from a local Ollama instance to a hosted API often reveals hidden constraints in prompt handling and rate limiting. This guide helps developers manage token windows and errors gracefully while migrating large preprompts.

Understanding Context Windows and Token Limits
When migrating from a local setup, the first change you will notice is how context windows are handled. Local models on low-spec hardware often struggle with long contexts, but a hosted service can handle much larger inputs. Our API supports a context window of 100,000 tokens, which includes both the prompt and the completion. This is significantly higher than what many smaller local models can manage, allowing you to feed in large documents or long conversation histories without immediate truncation.
However, 100,000 tokens is still a finite limit. If you are migrating large preprompts, such as those mentioned in discussions about moving from Opus to self-hosted Ollama, you need to ensure your input fits within this window. You should calculate the token count of your prompt before sending it. If the prompt exceeds the limit, you must truncate or summarize the oldest parts of the context to make room for new input.
It is important to remember that this limit applies to the total tokens in the request. This means your system prompt, the user message, and any existing conversation history all count toward this 100,000 token budget. If you are building an application that maintains long-term memory, you need to implement a strategy for managing this window, such as sliding window summaries or relevance-based filtering.
For developers new to API integration, testing with smaller prompts first is advisable. You can monitor the token usage in the response to understand how much context is being consumed. This helps in planning how much history you can retain in a single session. Always verify the specific token limits in the vendor documentation for any other tools you might be using alongside our service.
Handling Rate Limits and Request Throttling
Rate limits are a critical aspect of migrating from a self-hosted environment to a cloud API. In a local setup, you might not have strict limits on how often you can call the model, but hosted services enforce limits to ensure fairness and stability. Our API allows 300 requests per minute per key. This is a generous limit for most use cases, but it is something you must account for in your code.
If you exceed this limit, you will receive a 429 error. Your application should handle this error gracefully by implementing exponential backoff. This means that if you get a 429 response, you wait for a short period, then try again, doubling the wait time with each subsequent failure. This prevents your application from flooding the API and helps you stay within the allowed limits.
It is also important to monitor your request volume. If you are processing large batches of data, you might hit the rate limit quickly. You can spread out your requests over time to stay under the 300 requests per minute threshold. This is especially important if you are migrating scripts that were previously running locally without such constraints.
Always check the status code of your responses. A 429 response indicates that you have hit the rate limit. By handling this error correctly, you can ensure that your migration is smooth and that your application remains responsive even under heavy load. You can also use this error to inform users that the service is busy, if appropriate for your application.
Managing Prepaid Credits and Errors
Unlike many other services that use subscriptions, our API uses a prepaid credit system. You pay with crypto, and the credit is charged based on real token usage. This means you only pay for what you use, and there are no monthly fees. However, you need to ensure you have enough credit in your account to avoid interruptions. If you run out of credit, you will receive a 402 error.
The 402 error indicates that you have no credit left. To resolve this, you need to top up your account. You can add credit using USDT on TRC20 or USDC on Base, with amounts ranging from $20 to $500. There is also a bonus credit system for larger top-ups, which can give you extra value. You can also start with a free trial of $0.50 to test the service without any initial investment.
Errors are free, which is a significant advantage. If you send a request that results in an error, such as an invalid key or a rate limit, you are not charged for those tokens. This means you can test your integration extensively without worrying about costs. However, you should still monitor your usage to ensure you are not wasting credit on unnecessary requests.
Always handle the 401 error, which indicates an invalid key. This can happen if you update your key or if there is a typo in your API key. By checking for these specific error codes, you can provide better feedback to users and troubleshoot issues more effectively. You can also use these errors to debug your integration during the migration process.
Migrating Large Preprompts and Context
One of the common challenges in migrating from local Ollama to a hosted API is handling large preprompts. In local setups, you might have a large system prompt that sets the context for the model. When moving to a hosted API, you need to ensure that this preprompt fits within the context window. If your preprompt is too large, you might need to split it or summarize it.
For example, if you are migrating a 35kb preprompt, you need to check if it fits within the 100,000 token limit. If it does, you can send it as is. If it does not, you need to find a way to reduce its size. This might involve removing redundant information or using a more concise phrasing. You should also consider the length of the conversation history that you want to retain.
Another consideration is the format of the preprompt. Our API supports the OpenAI-compatible format, so you can use the same structure you are used to. This makes migration easier, as you do not need to rewrite your prompts. You can simply update the base URL and the API key in your code.
It is also important to test your preprompts with different models to see how they perform. While our API uses a single uncensored model, you might want to compare the output with your local model to ensure that the behavior is consistent. You can also use the streaming feature to get real-time feedback on the model's responses.
When Our API Is Not the Right Choice
While our API is a powerful tool for many use cases, it is not the right choice for everyone. If you need features like image generation, audio processing, or video creation, our API does not support these capabilities. We focus on text-only interactions, so if your project requires multimodal outputs, you might need to look for a different solution.
Similarly, if you need fine-tuning capabilities, our API does not offer this feature. You can only use the pre-trained model. If you need to customize the model for a specific domain, you might need to use a service that offers fine-tuning. Our API is designed for developers who want to use a high-quality uncensored model without the overhead of training their own.
Another limitation is that we do not offer model routing. You are always using the same uncensored model. If you need to switch between different models based on the task, our API might not be the best fit. You can, however, use our API for the text generation part of your workflow and combine it with other services for other tasks.
Finally, if you need an SLA or certifications like SOC2 or HIPAA, our API does not provide these guarantees. We are an independent service focused on providing a reliable and uncensored text API. If you are building a mission-critical application that requires strict compliance, you might need to evaluate other options. Always check the vendor documentation for current prices and limits to ensure the service meets your needs.
Addressing Community Concerns on Migration
Developers migrating from local Ollama often share their experiences on platforms like Reddit. In threads on r/ollama, users discuss the challenges of running Ollama on low-spec hardware. Some users find that their local models are slow or limited in their capabilities. This is a common reason for migrating to a hosted API, which offers more powerful models and faster response times.
Another common topic is the use of companion clients like PocketLLM Lite. Users who run Ollama on their home servers often look for mobile clients to interact with their models. When migrating to a hosted API, you can use similar clients to access the model from your mobile device. This allows you to continue using your preferred interface while benefiting from the scalability of a hosted service.
Users also discuss the trade-offs of self-hosting versus using a hosted API. While self-hosting gives you full control, it requires maintenance and hardware. A hosted API removes these burdens but introduces rate limits and costs. By understanding these trade-offs, you can make an informed decision about which approach is best for your project.
Finally, users often ask about the cost of migration. While our API uses a prepaid model, the costs are transparent and based on usage. You can start with a free trial to test the service before committing to a larger top-up. This allows you to evaluate the performance and quality of the model before investing in a subscription or larger credit package.
Best Practices for Integration and Testing
When integrating our API into your application, it is important to follow best practices for error handling and testing. Always check for specific error codes like 401, 402, and 429. These codes provide clear feedback on what went wrong, allowing you to fix issues quickly. You should also implement logging to track the performance of your API calls.
Testing is another important step. You should test your integration with different types of prompts to ensure that the model handles them correctly. You can use the streaming feature to get real-time feedback on the model's responses. This helps you identify any issues with the output format or the model's behavior.
It is also important to monitor your token usage. By tracking the number of tokens you use, you can estimate your costs and ensure that you have enough credit in your account. You can use the formula (tokens divided by 1,000,000 times the per-million price) to calculate the cost of a request. This helps you budget for your API usage.
Finally, keep your API key secure. The key is shown immediately after signup, so you should store it in a secure location. You can also rotate your key periodically to enhance security. By following these best practices, you can ensure a smooth migration and a reliable integration with our API.
Frequently asked questions
What is the context window size for this API?
The context window is 100,000 tokens, which includes both the prompt and the completion. This allows for large inputs and long conversation histories.
How do I handle rate limits?
Our API allows 300 requests per minute per key. If you exceed this, you will receive a 429 error. You should implement exponential backoff to handle this gracefully.
What payment methods are accepted?
We accept crypto only: USDT on TRC20 or USDC on Base. You can top up with amounts from $20 to $500. There is also a free trial of $0.50.
Does this API support image generation?
No, this API is text-only. It does not support image, audio, or video generation. You can use it for text interactions and combine it with other services for multimodal tasks.