Skip to main content

🔑
Get your Incredible API key
Generate your API key to start using the SDK
→

Quick Start with Fetch

const response = await fetch('https://api.incredible.one/v1/messages', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    // 'Authorization': `Bearer ${process.env.INCREDIBLE_API_KEY}`, // Optional for now
  },
  body: JSON.stringify({
    model: 'small-1',
    max_tokens: 150,
    messages: [
      { role: 'user', content: 'Give me 3 productivity tips.' }
    ],
  }),
});

const data = await response.json();
console.log(data.content[0].text);
console.log('Token usage:', data.token_usage);

TypeScript Client Example

Here’s a simple TypeScript client you can use:
interface Message {
  role: 'user' | 'assistant' | 'system';
  content: string;
}

interface MessageResponse {
  content: Array<{ text: string }>;
  token_usage: {
    input_tokens: number;
    output_tokens: number;
  };
  stop_reason: string;
}

class IncredibleClient {
  private baseUrl: string;
  private apiKey?: string;

  constructor(config?: { baseUrl?: string; apiKey?: string }) {
    this.baseUrl = config?.baseUrl || 'https://api.incredible.one';
    this.apiKey = config?.apiKey || process.env.INCREDIBLE_API_KEY;
  }

  async messages(params: {
    model: string;
    max_tokens: number;
    messages: Message[];
    temperature?: number;
  }): Promise<MessageResponse> {
    const response = await fetch(`${this.baseUrl}/v1/messages`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        ...(this.apiKey && { Authorization: `Bearer ${this.apiKey}` }),
      },
      body: JSON.stringify(params),
    });

    if (!response.ok) {
      const error = await response.json();
      throw new Error(`API error: ${error.message || response.statusText}`);
    }

    return response.json();
  }

  async answer(params: { query: string }): Promise<{ answer: string; success: boolean }> {
    const response = await fetch(`${this.baseUrl}/v1/answer`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        ...(this.apiKey && { Authorization: `Bearer ${this.apiKey}` }),
      },
      body: JSON.stringify(params),
    });

    if (!response.ok) {
      const error = await response.json();
      throw new Error(`API error: ${error.message || response.statusText}`);
    }

    return response.json();
  }

  async conversation(params: {
    messages: Message[];
    model?: string;
    max_tokens?: number;
  }): Promise<{ response: string; success: boolean }> {
    const response = await fetch(`${this.baseUrl}/v1/conversation`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        ...(this.apiKey && { Authorization: `Bearer ${this.apiKey}` }),
      },
      body: JSON.stringify(params),
    });

    if (!response.ok) {
      const error = await response.json();
      throw new Error(`API error: ${error.message || response.statusText}`);
    }

    return response.json();
  }
}

// Usage
const client = new IncredibleClient({
  apiKey: process.env.INCREDIBLE_API_KEY,
});

const response = await client.messages({
  model: 'small-1',
  max_tokens: 150,
  messages: [{ role: 'user', content: 'Hello!' }],
});

console.log(response.content[0].text);

Using with Axios

import axios from 'axios';

const client = axios.create({
  baseURL: 'https://api.incredible.one',
  headers: {
    'Content-Type': 'application/json',
    // Authorization: `Bearer ${process.env.INCREDIBLE_API_KEY}`, // Optional
  },
});

// Messages
const response = await client.post('/v1/messages', {
  model: 'small-1',
  max_tokens: 150,
  messages: [{ role: 'user', content: 'Hello!' }],
});

console.log(response.data.content[0].text);

// Answer
const answer = await client.post('/v1/answer', {
  query: 'What is the speed of light?',
});

console.log(answer.data.answer);

Function Calling

interface FunctionCall {
  name: string;
  arguments: Record<string, any>;
  id: string;
}

// Initial request with functions
const response = await fetch('https://api.incredible.one/v1/messages', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    model: 'small-1',
    max_tokens: 256,
    messages: [{ role: 'user', content: 'What is 127 + 349?' }],
    functions: [
      {
        name: 'calculate',
        description: 'Perform basic math',
    parameters: {
      type: 'object',
      properties: {
            operation: { type: 'string', enum: ['add', 'subtract', 'multiply', 'divide'] },
        a: { type: 'number' },
        b: { type: 'number' },
      },
          required: ['operation', 'a', 'b'],
        },
      },
    ],
  }),
});

const data = await response.json();

// Execute function calls if any
if (data.tool_calls && data.tool_calls.length > 0) {
  const toolCalls = data.tool_calls;
  const results = toolCalls.map((call: FunctionCall) => {
    const { operation, a, b } = call.arguments;
    let result: number;
    
    switch (operation) {
      case 'add':
        result = a + b;
        break;
      case 'subtract':
        result = a - b;
        break;
      case 'multiply':
        result = a * b;
        break;
      case 'divide':
        result = a / b;
        break;
      default:
        throw new Error(`Unknown operation: ${operation}`);
    }
    
    return {
      type: 'function_call_result',
      function_call_id: call.id,
      function_call_results: [result],
    };
  });

  // Follow-up request with results
  const followUp = await fetch('https://api.incredible.one/v1/messages', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
  model: 'small-1',
      max_tokens: 256,
      messages: [
        { role: 'user', content: 'What is 127 + 349?' },
        {
          type: 'function_call',
          function_call_id: toolCalls[0].id,
          function_calls: [{ name: toolCalls[0].name, input: toolCalls[0].arguments }],
        },
        results[0],
      ],
      functions: [/* same functions as before */],
    }),
  });

  const final = await followUp.json();
  console.log(final.content[0].text);
}

Streaming Responses

const response = await fetch('https://api.incredible.one/v1/messages/stream', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
  model: 'small-1',
  max_tokens: 256,
    messages: [{ role: 'user', content: 'Write a haiku about coding.' }],
  }),
});

const reader = response.body?.getReader();
const decoder = new TextDecoder();

if (reader) {
  while (true) {
    const { done, value } = await reader.read();
    if (done) break;

    const chunk = decoder.decode(value);
    const lines = chunk.split('\n');

    for (const line of lines) {
      if (line.startsWith('data: ')) {
        const data = line.slice(6);
        if (data === '[DONE]') break;

        try {
          const event = JSON.parse(data);
          if (event.content?.type === 'content_chunk') {
            process.stdout.write(event.content.content);
          }
        } catch (e) {
          // Skip invalid JSON
        }
      }
    }
  }
}

Available Endpoints

Messages

  • POST /v1/messages - Chat completions
  • POST /v1/messages/stream - Streaming chat

Text Services

  • POST /v1/answer - Simple Q&A
  • POST /v1/conversation - Multi-turn conversations
  • POST /v1/agent - Autonomous agents with tools

Research

  • POST /v1/web-search - Web search
  • POST /v1/deep-research - Deep research

Media

  • POST /v1/generate-image - Image generation
  • POST /v1/generate-video - Video generation

OCR

  • POST /v1/ocr/image - Extract text from images
  • POST /v1/ocr/pdf - Extract text from PDFs

Files

  • POST /v1/files/upload - Upload file
  • POST /v1/files/upload-url - Upload from URL
  • GET /v1/files - List files
  • GET /v1/files/{file_id} - Get file metadata
  • DELETE /v1/files/{file_id} - Delete file

Integrations

  • GET /v1/integrations - List integrations
  • GET /v1/integrations/{integration_id} - Get integration details
  • POST /v1/integrations/{integration_id}/connect - Connect integration
  • POST /v1/integrations/{integration_id}/execute - Execute integration feature

Models

  • GET /v1/models - List available models

Error Handling

try {
  const response = await fetch('https://api.incredible.one/v1/messages', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      model: 'small-1',
      messages: [{ role: 'user', content: 'Hello' }],
      max_tokens: 100,
    }),
  });

  if (!response.ok) {
    const error = await response.json();
    
    if (response.status === 401) {
      throw new Error('Authentication failed');
    } else if (response.status === 429) {
      const retryAfter = response.headers.get('Retry-After');
      throw new Error(`Rate limited. Retry after ${retryAfter}s`);
    } else if (response.status === 400) {
      throw new Error(`Invalid request: ${error.message}`);
    } else {
      throw new Error(`API error: ${error.message || response.statusText}`);
    }
  }

  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error('Request failed:', error);
}

TypeScript Types

For better type safety, you can define types for API requests and responses:
// Request types
interface MessageRequest {
  model: string;
  max_tokens: number;
  messages: Array<{
    role: 'user' | 'assistant' | 'system';
    content: string;
  }>;
  temperature?: number;
  functions?: Array<{
    name: string;
    description: string;
    parameters: Record<string, any>;
  }>;
}

interface AnswerRequest {
  query: string;
  model?: string;
  max_tokens?: number;
  response_format?: Record<string, any>;
}

// Response types
interface MessageResponse {
  content: Array<{ text: string }>;
  token_usage: {
    input_tokens: number;
    output_tokens: number;
  };
  stop_reason: string;
  tool_calls?: Array<{
    id: string;
    name: string;
    arguments: Record<string, any>;
  }>;
}

interface AnswerResponse {
  success: boolean;
  answer: string;
  data?: Record<string, any>; // For structured output
}

Coming Soon

The official TypeScript SDK (@incredible-ai/sdk) is in development and will provide:
  • Anthropic-compatible client interface
  • Full TypeScript type definitions
  • Helper utilities for function calling
  • Streaming support with async iterators
  • Automatic retry and error handling
  • Token counting utilities
Stay tuned for updates!

Additional Resources