Best Practices

Get the most out of the Nascentist API with these proven patterns and techniques.

Prompt Engineering

Be Specific

The more context you provide, the better the results:

// Good: Specific with context
"Write a Python function to calculate Fibonacci numbers recursively.
Include type hints, handle edge cases for negative numbers,
and add a docstring explaining the time complexity."

// Avoid: Too vague
"Write a Fibonacci function"

Use Language Hints

Specify the programming language when possible:

// Good: Explicit language
"Convert this JavaScript function to Python: function add(a, b) { return a + b; }"

// The language parameter also helps
{ "prompt": "...", "language": "python" }

Token Optimization

Use max_tokens Wisely

Set max_tokens to the minimum needed for your use case:

  • • Small completions: 50-200 tokens
  • • Function bodies: 200-500 tokens
  • • Full files: 1000-4000 tokens

Temperature Settings

Adjust temperature based on your needs:

  • 0.0 - 0.2: Deterministic, best for code fixes
  • 0.3 - 0.5: Balanced, good for general completion
  • 0.6 - 0.8: Creative, good for brainstorming

Performance Tips

Caching

Cache responses for identical prompts:

import hashlib

def cache_key(prompt, **kwargs):
    data = {"prompt": prompt, **kwargs}
    return hashlib.sha256(str(data).encode()).hexdigest()

def get_completion(prompt, **kwargs):
    key = cache_key(prompt, **kwargs)
    if key in cache:
        return cache[key]
    # Make API call and cache result
    return response

Batch Processing

Process multiple prompts concurrently with async:

import asyncio
import aiohttp

async def process_batch(prompts):
    async with aiohttp.ClientSession() as session:
        tasks = [make_request(session, p) for p in prompts]
        return await asyncio.gather(*tasks)

Error Prevention

Validate Input

Always validate before sending to API:

def validate_request(prompt, max_tokens, temperature):
    errors = []
    
    if not prompt or len(prompt.strip()) == 0:
        errors.append("Prompt cannot be empty")
    
    if max_tokens and (max_tokens < 1 or max_tokens > 8000):
        errors.append("max_tokens must be between 1 and 8000")
    
    if temperature and (temperature < 0 or temperature > 1):
        errors.append("temperature must be between 0 and 1")
    
    return errors

Security

  • • Never expose API keys in client-side code
  • • Use environment variables for keys
  • • Rotate keys periodically
  • • Never log sensitive data
  • • Use HTTPS for all API calls
← PreviousEnd of guides