> ## Documentation Index
> Fetch the complete documentation index at: https://docs.morphllm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication

> Learn how to authenticate with Morph API using Bearer tokens

<Info>
  **Prerequisite**: You'll need an account on
  [Morph](https://morphllm.com/dashboard) to obtain an API key.
</Info>

## Authentication

All Morph API endpoints require authentication using Bearer tokens:

```bash theme={null}
Authorization: Bearer your-morph-api-key
```

To get your API key:

1. Visit the [Morph dashboard](https://morphllm.com/api-keys)
2. Create an account or sign in
3. Navigate to your API keys section
4. Generate a new API key

<Warning>
  Keep your API key secure and never expose it in client-side code or public
  repositories.
</Warning>

## Base URL

All Morph API endpoints use the following base URL:

```bash theme={null}
https://api.morphllm.com/v1
```

## Test Your API Key

Verify your setup with a simple test request:

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

  client = OpenAI(
      api_key="your-morph-api-key",
      base_url="https://api.morphllm.com/v1"
  )

  # Test the connection
  response = client.chat.completions.create(
      model="morph-v3-fast",
      messages=[{
          "role": "user",
          "content": "<code>def hello():\n    print('Hello World')</code>\n<update>def hello():\n    print('Hello Morph!')</update>"
      }]
  )

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

  ```javascript JavaScript theme={null}
  import { OpenAI } from "openai";

  const client = new OpenAI({
    apiKey: "your-morph-api-key",
    baseURL: "https://api.morphllm.com/v1",
  });

  // Test the connection
  const response = await client.chat.completions.create({
    model: "morph-v3-fast",
    messages: [
      {
        role: "user",
        content:
          "<code>def hello():\n    print('Hello World')</code>\n<update>def hello():\n    print('Hello Morph!')</update>",
      },
    ],
  });

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

  ```bash cURL theme={null}
  curl --request POST \
    --url https://api.morphllm.com/v1/chat/completions \
    --header 'Authorization: Bearer your-morph-api-key' \
    --header 'Content-Type: application/json' \
    --data '{
      "model": "morph-v3-fast",
      "messages": [{
        "role": "user",
        "content": "<code>def hello():\n    print(\"Hello World\")</code>\n<update>def hello():\n    print(\"Hello Morph!\")</update>"
      }]
    }'
  ```
</CodeGroup>

<Tip>
  If the test succeeds, you should see the updated code with "Hello Morph!"
  instead of "Hello World".
</Tip>

## Alternative Access Methods

You can also access Morph through these platforms:

<Card title="OpenRouter" icon="globe" href="https://openrouter.ai/morph/morph-v2" horizontal>
  Access Morph models through OpenRouter's unified API platform
</Card>

<Card title="MCP Integration" icon="plug" href="/guides/mcp" horizontal>
  Use Morph with Model Context Protocol servers and Claude Desktop
</Card>

## Next Steps

Now that you've tested your API key, explore Morph's specialized models:

<Card title="Apply Model" icon="code-merge" href="/models/apply" horizontal>
  Apply code changes with precision at 10,500 tokens per second and 98% accuracy
</Card>

<Card title="Embedding Model" icon="cube" href="/models/embedding" horizontal>
  Generate semantic embeddings optimized for code understanding and search
</Card>

<Card title="Rerank Model" icon="arrow-up-arrow-down" href="/models/rerank" horizontal>
  Reorder search results by relevance with code-aware ranking algorithms
</Card>

<Tip>
  For access to our latest models, self-hosting, or business inquiries, please
  contact us at [info@morphllm.com](mailto:info@morphllm.com).
</Tip>
