Math Utilities

Fibonacci

Calculate the nth Fibonacci number using TinyFn's deterministic math endpoint. Access via MCP in Cursor or Windsurf for instant sequence generation, or call GET /v1/math/fibonacci?n=10 directly. Returns precise integers for any position in the sequence. Perfect when AI agents need exact mathematical computations instead of approximate answers.

API Endpoint

GET /v1/math/fibonacci

Code Examples

curl "https://tinyfn.io/v1/math/fibonacci" \
  -H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/math/fibonacci', {
  headers: { 'X-API-Key': 'YOUR_API_KEY' }
});
const data = await response.json();
console.log(data);
import requests

response = requests.get('https://tinyfn.io/v1/math/fibonacci',
    headers={'X-API-Key': 'YOUR_API_KEY'})
data = response.json()
print(data)

Use via MCP

Add to your AI agent

Connect your AI agent (Claude, Cursor, Windsurf, etc.) to TinyFn's math tools:

{
  "mcpServers": {
    "tinyfn-math": {
      "url": "https://tinyfn.io/mcp/math",
      "headers": {
        "X-API-Key": "YOUR_API_KEY"
      }
    }
  }
}

Learn more about MCP setup →

FAQ

How do I get the 50th Fibonacci number using MCP?

Call the fibonacci tool with n=50 through your MCP-enabled editor like Cursor or Claude Code. The tool returns the exact value: 12586269025.

What's the largest Fibonacci number this API can calculate?

The endpoint handles arbitrarily large Fibonacci numbers, limited only by computational resources. For practical use, values up to n=1000+ work reliably.

Does the Fibonacci API use 0-based or 1-based indexing?

The API uses 1-based indexing: fibonacci(1)=1, fibonacci(2)=1, fibonacci(3)=2. This matches mathematical convention rather than programming arrays.

Can I calculate multiple Fibonacci numbers in one request?

No, each request calculates a single Fibonacci number. For sequences, make multiple calls or use the deterministic nature to cache results efficiently.

Why use this instead of coding Fibonacci myself?

AI agents get guaranteed correct results without implementing recursive algorithms. Eliminates off-by-one errors and handles edge cases like negative inputs automatically.

Try Fibonacci Now

Get your free API key and start using Fibonacci in seconds.

Get Free API Key