StarBlog
/ Blog Details

Documentation
That Makes Sense

Clear step-by-step guides, real-world examples, and all the essential resources you need to confidently get started and move forward.
Getting Started
Welcome to DevAPI! This guide will help you integrate our API into your application in minutes.
1
Quick Start
Get up and running in less than 5 minutes. No credit card required for the free tier.
Sign up for an account
Create your free account at dashboard.devapi.com
Generate your API key
Navigate to Settings → API Keys and create a new key
Make your first API call
Use the code examples below to test your integration
2
Installation
Install our SDK using your preferred package manager:
# Using npm
npm install @devapi/sdk

# Using pnpm
pnpm add @devapi/sdk

# Using yarn
yarn add @devapi/sdk
3
First API Call
Install our SDK using your preferred package manager:
import { DevAPI } from '@devapi/sdk';

const client = new DevAPI({
  apiKey: process.env.DEVAPI_KEY
});

async function main() {
 const response = await client.generate({
   prompt: "Hello, DevAPI!",
   model: "gpt-4",
   temperature: 0.7
 });

 console.log(response.data);
}

main();
Pro tip: Store your API key in environment variables to keep it secure. Never commit API keys to version control.
Authentication
Secure your API requests with API keys
1
Get your API key
Install our SDK using your preferred package manager:
// Visit dashboard.devapi.io to generate your API key
// Keep it secure and never commit it to version control
2
Set environment variable
Install our SDK using your preferred package manager:
// .env file
DEVAPI_KEY=your_api_key_here
3
Authenticate requests
Install our SDK using your preferred package manager:
client = new DevAPI({
  apiKey: process.env.DEVAPI_KEY
});

// Or use Bearer token directly
const response = await fetch( 'https://api.devapi.io/v1/generate' , {
  headers: {
    'Authorization'
: 'Bearer YOUR_API_KEY' ,
    'Content-Type': 'application/json'
  }
}];
Ready to dive deeper?
Explore our complete API reference and advanced guides
API Reference
Secure your API requests with API keys
1
Get your API key
// Generate AI completions
POST https://api.devapi.io/v1/generate

// Request body

  "prompt": "Your prompt here",
  "model": "gpt-4",
  "maxTokens": 500 ,
  "temperature": 0.7
}
2
GET /v1/models
// List available models
GET https://api.devapi.io/v1/models

// Response
"models": [
   { "id": "gpt-4", "name": "GPT-4" },
   { "id": "claude-3", "name": "Claude 3" }
  ]
}
3
GET /v1/usage
// Check your usage statistics
GET https://api.devapi.io/v1/usage

// Response

  "requests": 1247 ,
  "tokens": 45632 ,
  "cost": "$12.45"
}
Ready to dive deeper?
Explore our complete API reference and advanced guides
SDK Guides
Secure your API requests with API keys
1
Node.js SDK
import { DevAPI } from '@devapi/node';

const client = new DevAPI({ apiKey: 'YOUR_KEY' });

const response = await client.generate({
   prompt: "Hello, World!",
   model: "gpt-4" 
});
2
Python SDK
from devapi import Client

client = Client(apiKey="YOUR_KEY")

response = client.generate({
   prompt: "Hello, World!",
   model: "gpt-4" 
});
3
Go SDK
import "github.com/devapi/go-sdk"

client =: devapi.NewClient ("YOUR_KEY")

response, err := client.generate(&devapi.Request{
   prompt: "Hello, World!",
   model: "gpt-4" 
});
Ready to dive deeper?
Explore our complete API reference and advanced guides
Code Examples
Real-world use cases and implementations
1
Streaming responses
const stream = await client.generateStream({
   prompt: "Hello, World!",
   model: "gpt-4" 
});

for await (const chunk of stream) {
  process.stdout.write(chunk.text);
}
2
Batch processing
const prompts = ["Query 1", "Query 2", "Query 3"];

const results = await Promise.all(
  
prompts.map(prompt =>
    
client.generate({ prompt, model: "gpt-4" })
 
 )
);
3
Error handling with retry
async function generateWithRetry(prompt, retries = 3) {
  for (let i = 0; i < retries; i++) {
    try {
      return await client.generate({ prompt });
    } catch (error) {
      if (i === retries - 1) throw error;
      await new Promise(r => setTimeout(r, 1000 * (i + 1)));
    }
  }
}
Ready to dive deeper?
Explore our complete API reference and advanced guides
Webhooks
Real-world use cases and implementations
1
Set up webhook endpoint
// Express.js example
app.post('/webhook', express.json(), (req, res) => {
  const event = req.body;
 
  console.log('Event received:', event.type);
 
  res.status(200).send('OK');
});
2
Verify webhook signature
const crypto = require('crypto');

function verifyWebhook(payload, signature, secret) {
  const hash = crypto
    .createHmac('sha256', secret)
    .update(payload)
    .digest('hex');

  return hash === signature;
}
3
Handle webhook events
switch (event.type) {
  case 'request.completed':
    console.log('Request completed:', event.data);
    break;
  case 'request.failed':
    console.log('Request failed:', event.data);
    break;
  default:
    console.log('Unknown event type:', event.type);
}
Ready to dive deeper?
Explore our complete API reference and advanced guides
Rate Limits
Understand and optimize your API usage within rate limits.
1
Rate Limit Tiers
Free
Requests:
100 requests/day
Tokens:
10K tokens/day
Concurrent:
1 concurrent request
Starter
Requests:
10K requests/day
Tokens:
1M tokens/day
Concurrent:
5 concurrent requests
Pro
Requests:
100K requests/day
Tokens:
10M tokens/day
Concurrent:
20 concurrent requests
Free
Requests:
Custom limits
Tokens:
Custom limits
Concurrent:
Custom concurrency
2
Response Headers
Install our SDK using your preferred package manager:
X-RateLimit-Limit: 10000
X-RateLimit-Remaining: 9847
X-RateLimit-Reset: 1714089600
X-RateLimit-Retry-After: 3600
3
Handling Rate Limits
async function generateWithRetry(prompt, maxRetries = 3) {
  for (let attempt = 0; attempt < maxRetries; attempt++) {
    try {
      const response = await fetch('https://api.devapi.com/v1/generate', {
        method: 'POST',
        headers: {
          'Authorization': `Bearer ${apiKey}`,
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({ prompt })
      });

      if (response.status === 429) {
        const retryAfter = response.headers.get('X-RateLimit-Retry-After');
        const delay = (retryAfter || Math.pow(2, attempt)) * 1000;

        console.log(`Rate limited. Retrying in ${delay}ms...`);
        await new Promise(resolve => setTimeout(resolve, delay));
        continue;
      }

      if (!response.ok) {
        throw new Error(`HTTP ${response.status}`);
      }

      return await response.json();
    } catch (error) {
      if (attempt === maxRetries - 1) throw error;
    }
  }
}
4
Best Practices
Implement exponential backoff for retry logic
Cache responses when appropriate to reduce API calls
Monitor rate limit headers proactively
Batch requests when possible
Distribute load across multiple API keys if needed
Upgrade your plan before hitting limits regularly
Ready to dive deeper?
Explore our complete API reference and advanced guides
Error Handling
Handle errors gracefully in your application
1
Try-catch pattern
try {
  const response = await client.generate({
    prompt: "Hello",
    model: "gpt-4"
  });
  console.log(response.data);
} catch (error) {
  if (error.status === 429) {
    console.error('Rate limit exceeded');
  } else if (error.status === 401) {
    console.error('Invalid API key');
  } else {
    console.error('Error:', error.message);
  }
}
2
Error types
// Common error status codes
// 400 - Bad Request (invalid parameters)
// 401 - Unauthorized (invalid API key)
// 429 - Rate Limit Exceeded
// 500 - Internal Server Error

if (error.status === 429) {
  // Wait and retry
  const retryAfter = error.headers['retry-after'];
  await sleep(retryAfter * 1000);
}
3
Custom error handling
class APIError extends Error {
  constructor(message, status, code) {
    super(message);
    this.status = status;
    this.code = code;
  }
}

// Usage
if (!response.ok) {
  throw new APIError(
    'Request failed',
    response.status,
    response.data.code
  );
}
Ready to dive deeper?
Explore our complete API reference and advanced guides
Best Practice
Production-ready patterns and optimization tips
1
Use environment variables
// ✅ Good - Use environment variables
const client = new DevAPI({
  apiKey: process.env.DEVAPI_KEY
});

// ❌ Bad - Hardcoded API key
const client = new DevAPI({
  apiKey: 'sk_live_abc123...'
});
2
Implement rate limiting
import { RateLimiter } from 'limiter';

const limiter = new RateLimiter({
  tokensPerInterval: 10,
  interval: 'second'
});

async function makeRequest(prompt) {
  await limiter.removeTokens(1);
  return client.generate({ prompt });
}
3
Cache responses
const cache = new Map();

async function generateWithCache(prompt) {
  if (cache.has(prompt)) {
    return cache.get(prompt);
  }
 
  const response = await client.generate({ prompt });
  cache.set(prompt, response);
 
  return response;
}
Ready to dive deeper?
Explore our complete API reference and advanced guides