Neurometric API Documentation

Neurometric API Documentation

Drop-in replacement for OpenAI with built-in analytics and cost optimization

Quick Start

Replace your OpenAI endpoint with Neurometric in just one line. All your existing code works exactly the same.

1. Get your API key

Create your API key to get started:

Create API Key

2. Update your code

Just change the base_url. Everything else stays the same.

Python
from openai import OpenAI

client = OpenAI(
    api_key=os.environ.get("NEUROMETRIC_API_KEY"),
    base_url="https://api.neurometric.ai/v1"
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "user", "content": "Hello!"}
    ]
)

print(response.choices[0].message.content)
JavaScript
import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: process.env.NEUROMETRIC_API_KEY,
  baseURL: 'https://api.neurometric.ai/v1',
});

const response = await client.chat.completions.create({
  model: 'gpt-4o',
  messages: [
    { role: 'user', content: 'Hello!' }
  ],
});

console.log(response.choices[0].message.content);
cURL
curl -X POST https://api.neurometric.ai/v1/chat/completions \
  -H "Authorization: Bearer $NEUROMETRIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'

Analytics & Observability

Zero Configuration Required

Analytics are automatic. Every request through Neurometric is tracked, analyzed, and available in your dashboard without any extra code or setup.

Usage Tracking

Monitor all API calls, models used, tokens consumed, and response times in real-time.

Cost Analysis

Automatic cost breakdown by model, task type, and time period. Identify optimization opportunities.

Performance Metrics

Track latency, throughput, error rates, and success metrics across all your LLM requests.

Smart Recommendations

Get AI-powered suggestions to reduce costs while maintaining quality based on your usage patterns.

View Your Analytics Dashboard

Access detailed analytics, usage reports, and optimization recommendations.

Open Dashboard

API Reference

Base URL

https://api.neurometric.ai/v1

Authentication

All API requests require authentication using a Bearer token in the Authorization header.

Authorization: Bearer YOUR_API_KEY

Endpoint

POST /chat/completions

Create a chat completion. Fully compatible with OpenAI's chat completions API format.

Supported Models

Use any model ID from OpenAI, Anthropic, Google, or other providers. Neurometric automatically routes to the correct provider.

OpenAI

gpt-4o, gpt-4-turbo, gpt-3.5-turbo

Anthropic

claude-3-5-sonnet, claude-3-opus

Google

gemini-pro, gemini-flash

Meta

llama-3-70b, llama-3-8b

Mistral

mistral-large, mistral-7b

...and more

100+ models supported

Request Format

Required

model string

ID of the model to use. See supported models above.

Example: "gpt-4o", "claude-3-5-sonnet"

messages array

Array of message objects with role and content.

Roles: "system", "user", "assistant"

Optional

temperature number

Sampling temperature between 0 and 2. Higher values = more random.

Default: 1

max_tokens integer

Maximum number of tokens to generate in the response.

Model-dependent default

top_p number

Nucleus sampling: consider tokens with top_p probability mass.

Default: 1

stop string | array

Sequences where the API will stop generating tokens.

Up to 4 sequences

Example Request

{
  "model": "gpt-4o",
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful assistant."
    },
    {
      "role": "user",
      "content": "What is the capital of France?"
    }
  ],
  "temperature": 0.7,
  "max_tokens": 150
}

Response Format

id string

Unique identifier for the completion.

model string

The model that generated the response.

choices array

Array of completion choices. Each contains:

message - The generated message object

finish_reason - Why generation stopped ("stop", "length", etc.)

index - Index of this choice

usage object

Token usage statistics:

prompt_tokens - Tokens in the prompt

completion_tokens - Tokens in the response

total_tokens - Total tokens used

Example Response

{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1706745600,
  "model": "gpt-4o",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "The capital of France is Paris."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 25,
    "completion_tokens": 8,
    "total_tokens": 33
  }
}

Error Handling

Errors follow a standard format with HTTP status codes and descriptive messages:

{ "error": { "message": "...", "type": "...", "code": "..." } }

401 - Invalid API key

429 - Rate limit exceeded

500 - Server error

TypeScript Types

If you're using TypeScript, here are the type definitions for request and response objects.

Type Definitions

// Message in a conversation
interface Message {
  role: 'system' | 'user' | 'assistant';
  content: string;
}

// Request body for /chat/completions
interface ChatCompletionRequest {
  model: string;
  messages: Message[];
  temperature?: number;      // 0-2, default 1
  max_tokens?: number;       // Model-dependent
  top_p?: number;            // 0-1, default 1
  stop?: string | string[];  // Up to 4 sequences
}

// Response from /chat/completions
interface ChatCompletionResponse {
  id: string;
  object: 'chat.completion';
  created: number;
  model: string;
  choices: {
    index: number;
    message: Message;
    finish_reason: 'stop' | 'length' | 'content_filter';
  }[];
  usage: {
    prompt_tokens: number;
    completion_tokens: number;
    total_tokens: number;
  };
}

Migration from OpenAI

Switch in 3 Steps

  1. 1

    Get your Neurometric API key

    Create an account and generate an API key

  2. 2

    Update your base URL

    Change https://api.openai.com/v1 to https://api.neurometric.ai/v1

  3. 3

    Replace your API key

    Use your Neurometric API key instead of your OpenAI key

Full Compatibility

No other code changes required. Neurometric uses the same request/response format as OpenAI, so your existing code works without modification. You can even continue using the official OpenAI SDK.

Support