> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/cheahjs/free-llm-api-resources/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Make your first free LLM API call in under 5 minutes

## Overview

This guide will walk you through making your first API call to a free LLM provider. We'll use OpenRouter as our example since it offers 20+ free models with a simple OpenAI-compatible API.

<Steps>
  <Step title="Choose a Provider">
    For this quickstart, we'll use **OpenRouter** which offers:

    * 20+ free models including Llama 3.3 70B and Gemma 3
    * OpenAI-compatible API (easy migration)
    * 20 requests/minute, 50 requests/day (1000/day with \$10 lifetime top-up)

    <Tip>
      Other great options for getting started: **Groq** (fastest inference), **Cerebras** (high token limits), or **GitHub Models** (40+ models).
    </Tip>
  </Step>

  <Step title="Get Your API Key">
    1. Visit [OpenRouter.ai](https://openrouter.ai)
    2. Sign up for a free account
    3. Navigate to [API Keys](https://openrouter.ai/keys)
    4. Create a new API key and copy it

    <Warning>
      Keep your API key secure! Never commit it to version control or share it publicly.
    </Warning>
  </Step>

  <Step title="Install Dependencies">
    Install the OpenAI SDK (works with OpenRouter's compatible endpoint):

    <CodeGroup>
      ```bash Python theme={null}
      pip install openai
      ```

      ```bash Node.js theme={null}
      npm install openai
      ```

      ```bash cURL theme={null}
      # No installation needed - cURL is pre-installed on most systems
      ```
    </CodeGroup>
  </Step>

  <Step title="Make Your First API Call">
    <CodeGroup>
      ```python Python theme={null}
      from openai import OpenAI

      # Initialize client with OpenRouter
      client = OpenAI(
          base_url="https://openrouter.ai/api/v1",
          api_key="YOUR_OPENROUTER_API_KEY",
      )

      # Make a chat completion request
      response = client.chat.completions.create(
          model="meta-llama/llama-3.3-70b-instruct:free",
          messages=[
              {"role": "user", "content": "Explain quantum computing in simple terms"}
          ],
      )

      print(response.choices[0].message.content)
      ```

      ```javascript Node.js theme={null}
      import OpenAI from 'openai';

      // Initialize client with OpenRouter
      const client = new OpenAI({
        baseURL: 'https://openrouter.ai/api/v1',
        apiKey: process.env.OPENROUTER_API_KEY,
      });

      // Make a chat completion request
      const response = await client.chat.completions.create({
        model: 'meta-llama/llama-3.3-70b-instruct:free',
        messages: [
          { role: 'user', content: 'Explain quantum computing in simple terms' }
        ],
      });

      console.log(response.choices[0].message.content);
      ```

      ```bash cURL theme={null}
      curl https://openrouter.ai/api/v1/chat/completions \
        -H "Content-Type: application/json" \
        -H "Authorization: Bearer YOUR_OPENROUTER_API_KEY" \
        -d '{
          "model": "meta-llama/llama-3.3-70b-instruct:free",
          "messages": [
            {"role": "user", "content": "Explain quantum computing in simple terms"}
          ]
        }'
      ```
    </CodeGroup>
  </Step>
</Steps>

## Available Free Models on OpenRouter

OpenRouter offers 20+ free models. Here are some popular options:

<CardGroup cols={2}>
  <Card title="Llama 3.3 70B" icon="meta">
    General-purpose powerhouse - great for reasoning and complex tasks

    `meta-llama/llama-3.3-70b-instruct:free`
  </Card>

  <Card title="Gemma 3 27B" icon="google">
    Google's efficient model - balanced performance and speed

    `google/gemma-3-27b-it:free`
  </Card>

  <Card title="Mistral Small 24B" icon="message">
    Fast and capable for most tasks

    `mistralai/mistral-small-3.1-24b-instruct:free`
  </Card>

  <Card title="Qwen 3 Coder" icon="code">
    Specialized for code generation

    `qwen/qwen3-coder:free`
  </Card>
</CardGroup>

## Try Other Providers

All providers with OpenAI-compatible APIs work similarly - just change the `base_url` and model name:

### Groq (Ultra-Fast Inference)

<CodeGroup>
  ```python Python theme={null}
  from openai import OpenAI

  client = OpenAI(
      base_url="https://api.groq.com/openai/v1",
      api_key="YOUR_GROQ_API_KEY",
  )

  response = client.chat.completions.create(
      model="llama-3.3-70b-versatile",
      messages=[{"role": "user", "content": "Write a Python function to calculate fibonacci"}],
  )

  print(response.choices[0].message.content)
  ```

  ```javascript Node.js theme={null}
  import OpenAI from 'openai';

  const client = new OpenAI({
    baseURL: 'https://api.groq.com/openai/v1',
    apiKey: process.env.GROQ_API_KEY,
  });

  const response = await client.chat.completions.create({
    model: 'llama-3.3-70b-versatile',
    messages: [{ role: 'user', content: 'Write a Python function to calculate fibonacci' }],
  });

  console.log(response.choices[0].message.content);
  ```
</CodeGroup>

<Info>
  **Groq Limits:** 14,400 requests/day for Llama 3.1 8B, 1,000 requests/day for Llama 3.3 70B
</Info>

### Cerebras (High Token Limits)

<CodeGroup>
  ```python Python theme={null}
  from openai import OpenAI

  client = OpenAI(
      base_url="https://api.cerebras.ai/v1",
      api_key="YOUR_CEREBRAS_API_KEY",
  )

  response = client.chat.completions.create(
      model="llama3.3-70b",
      messages=[{"role": "user", "content": "What are the benefits of edge computing?"}],
  )

  print(response.choices[0].message.content)
  ```

  ```javascript Node.js theme={null}
  import OpenAI from 'openai';

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

  const response = await client.chat.completions.create({
    model: 'llama3.3-70b',
    messages: [{ role: 'user', content: 'What are the benefits of edge computing?' }],
  });

  console.log(response.choices[0].message.content);
  ```
</CodeGroup>

<Info>
  **Cerebras Limits:** 14,400 requests/day, 1,000,000 tokens/day - generous for most projects!
</Info>

## Advanced: Streaming Responses

For real-time applications like chatbots, use streaming to display responses as they're generated:

<CodeGroup>
  ```python Python theme={null}
  from openai import OpenAI

  client = OpenAI(
      base_url="https://openrouter.ai/api/v1",
      api_key="YOUR_OPENROUTER_API_KEY",
  )

  stream = client.chat.completions.create(
      model="meta-llama/llama-3.3-70b-instruct:free",
      messages=[{"role": "user", "content": "Write a short story about a robot"}],
      stream=True,
  )

  for chunk in stream:
      if chunk.choices[0].delta.content is not None:
          print(chunk.choices[0].delta.content, end="")
  ```

  ```javascript Node.js theme={null}
  import OpenAI from 'openai';

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

  const stream = await client.chat.completions.create({
    model: 'meta-llama/llama-3.3-70b-instruct:free',
    messages: [{ role: 'user', content: 'Write a short story about a robot' }],
    stream: true,
  });

  for await (const chunk of stream) {
    if (chunk.choices[0]?.delta?.content) {
      process.stdout.write(chunk.choices[0].delta.content);
    }
  }
  ```
</CodeGroup>

## Environment Variables Setup

Never hardcode API keys! Use environment variables:

<CodeGroup>
  ```bash .env theme={null}
  OPENROUTER_API_KEY=sk-or-v1-...
  GROQ_API_KEY=gsk_...
  CEREBRAS_API_KEY=...
  ```

  ```python Python theme={null}
  import os
  from openai import OpenAI

  client = OpenAI(
      base_url="https://openrouter.ai/api/v1",
      api_key=os.environ.get("OPENROUTER_API_KEY"),
  )
  ```

  ```javascript Node.js theme={null}
  // Install dotenv: npm install dotenv
  import 'dotenv/config';
  import OpenAI from 'openai';

  const client = new OpenAI({
    baseURL: 'https://openrouter.ai/api/v1',
    apiKey: process.env.OPENROUTER_API_KEY,
  });
  ```
</CodeGroup>

## Rate Limit Management

Most free providers have rate limits. Handle them gracefully:

```python Python theme={null}
from openai import OpenAI, RateLimitError
import time

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

def make_request_with_retry(messages, max_retries=3):
    for attempt in range(max_retries):
        try:
            response = client.chat.completions.create(
                model="meta-llama/llama-3.3-70b-instruct:free",
                messages=messages,
            )
            return response
        except RateLimitError:
            if attempt < max_retries - 1:
                wait_time = 2 ** attempt  # Exponential backoff
                print(f"Rate limited. Waiting {wait_time} seconds...")
                time.sleep(wait_time)
            else:
                raise

response = make_request_with_retry(
    [{"role": "user", "content": "Hello!"}]
)
```

## Next Steps

<CardGroup cols={2}>
  <Card title="Free Providers" icon="infinity" href="/providers/free/openrouter">
    Browse all 13 always-free providers
  </Card>

  <Card title="Trial Credits" icon="gift" href="/providers/trial/fireworks">
    Explore providers offering trial credits
  </Card>

  <Card title="Best Practices" icon="lightbulb" href="/guides/best-practices">
    Learn tips for optimal API usage
  </Card>

  <Card title="Choosing a Provider" icon="compass" href="/guides/choosing-provider">
    Find the best provider for your needs
  </Card>
</CardGroup>

<Note>
  **Pro Tip:** Start with multiple providers and implement fallback logic. If one hits rate limits, automatically switch to another!
</Note>
