authentication.mdx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. ---
  2. title: "Authentication"
  3. sidebarTitle: "Authentication"
  4. description: "How to authenticate with the Cline API using API keys or account tokens."
  5. ---
  6. Every request to the Cline API requires authentication via a Bearer token in the `Authorization` header.
  7. ## Authentication Methods
  8. There are two ways to authenticate:
  9. | Method | Use case | How to get it |
  10. |--------|----------|---------------|
  11. | **API key** | Direct API calls, scripts, CI/CD | Create at [app.cline.bot](https://app.cline.bot) Settings > API Keys |
  12. | **Account auth token** | Cline extension and CLI | Generated automatically when you sign in |
  13. Both methods use the same header format:
  14. ```bash
  15. Authorization: Bearer YOUR_TOKEN
  16. ```
  17. ## API Keys
  18. API keys are the recommended authentication method for programmatic access.
  19. ### Creating a Key
  20. <Steps>
  21. <Step title="Sign in">
  22. Go to [app.cline.bot](https://app.cline.bot) and sign in.
  23. </Step>
  24. <Step title="Open API Keys">
  25. Navigate to **Settings** > **API Keys**.
  26. </Step>
  27. <Step title="Create and copy">
  28. Create a new key. Copy it immediately as you will not be able to see it again.
  29. </Step>
  30. </Steps>
  31. ### Deleting a Key
  32. You can revoke an API key at any time from the same Settings > API Keys page. Deleted keys stop working immediately.
  33. You can also manage keys programmatically through the [Enterprise API](/enterprise-solutions/api-reference#api-keys):
  34. ```bash
  35. # List your keys
  36. curl https://api.cline.bot/api/v1/api-keys \
  37. -H "Authorization: Bearer YOUR_TOKEN"
  38. # Delete a key
  39. curl -X DELETE https://api.cline.bot/api/v1/api-keys/KEY_ID \
  40. -H "Authorization: Bearer YOUR_TOKEN"
  41. ```
  42. ## Account Auth Tokens
  43. When you sign in to the Cline extension (VS Code, JetBrains) or CLI, an account auth token is generated and managed automatically. You do not need to handle these tokens manually.
  44. The Cline CLI uses these tokens when you authenticate via:
  45. ```bash
  46. # Interactive sign-in
  47. cline auth
  48. # Or quick setup with an API key
  49. cline auth -p cline -k "YOUR_API_KEY" -m anthropic/claude-sonnet-4-6
  50. ```
  51. See the [CLI Reference](/cline-cli/cli-reference#cline-auth) for all auth options.
  52. ## Security Best Practices
  53. **Do:**
  54. - Store API keys in environment variables or a secrets manager
  55. - Use different keys for development and production
  56. - Rotate keys periodically
  57. - Delete keys you no longer use
  58. **Do not:**
  59. - Commit keys to version control
  60. - Share keys in chat or email
  61. - Embed keys in client-side code (browsers, mobile apps)
  62. - Log keys in application output
  63. ### Using Environment Variables
  64. ```bash
  65. # Set the key
  66. export CLINE_API_KEY="your_api_key_here"
  67. # Use it in requests
  68. curl -X POST https://api.cline.bot/api/v1/chat/completions \
  69. -H "Authorization: Bearer $CLINE_API_KEY" \
  70. -H "Content-Type: application/json" \
  71. -d '{"model": "anthropic/claude-sonnet-4-6", "messages": [{"role": "user", "content": "Hello"}]}'
  72. ```
  73. ### Using a .env File
  74. ```bash
  75. # .env (add to .gitignore)
  76. CLINE_API_KEY=your_api_key_here
  77. ```
  78. ```python
  79. import os
  80. from openai import OpenAI
  81. client = OpenAI(
  82. base_url="https://api.cline.bot/api/v1",
  83. api_key=os.environ["CLINE_API_KEY"],
  84. )
  85. ```
  86. ## Custom Headers
  87. The Cline API accepts optional headers for tracking and identification:
  88. | Header | Description |
  89. |--------|-------------|
  90. | `HTTP-Referer` | Your application's URL. Helps with usage tracking. |
  91. | `X-Title` | Your application's name. Appears in usage logs. |
  92. | `X-Task-ID` | A unique task identifier. Used internally by the Cline extension. |
  93. ## Related
  94. <CardGroup cols={2}>
  95. <Card title="Getting Started" icon="rocket" href="/api/getting-started">
  96. Create your first API key and make a request.
  97. </Card>
  98. <Card title="Enterprise API Keys" icon="building" href="/enterprise-solutions/api-reference#api-keys">
  99. Manage API keys programmatically.
  100. </Card>
  101. </CardGroup>