reference.mdx 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. ---
  2. title: "Cline API Reference"
  3. sidebarTitle: "API Reference"
  4. description: "Reference for the Cline Chat Completions API, an OpenAI-compatible endpoint for programmatic access."
  5. ---
  6. The Cline API provides an OpenAI-compatible Chat Completions endpoint. You can use it from the Cline extension, the CLI, or any HTTP client that speaks the OpenAI format.
  7. ## Base URL
  8. ```
  9. https://api.cline.bot/api/v1
  10. ```
  11. ## Authentication
  12. All requests require a Bearer token in the `Authorization` header. You can use either:
  13. - **API key** created at [app.cline.bot](https://app.cline.bot) (Settings > API Keys)
  14. - **Account auth token** (used automatically by the Cline extension and CLI when you sign in)
  15. ```bash
  16. Authorization: Bearer YOUR_API_KEY
  17. ```
  18. ### Getting an API Key
  19. <Steps>
  20. <Step title="Go to app.cline.bot">
  21. Open [app.cline.bot](https://app.cline.bot) and sign in.
  22. </Step>
  23. <Step title="Open Settings > API Keys">
  24. Navigate to **Settings**, then **API Keys**.
  25. </Step>
  26. <Step title="Create and copy your key">
  27. Create a new key and copy it. Store it securely. You will not be able to see it again.
  28. </Step>
  29. </Steps>
  30. ## Chat Completions
  31. Create a chat completion with streaming support. This endpoint follows the [OpenAI Chat Completions](https://platform.openai.com/docs/api-reference/chat/create) format.
  32. ### Request
  33. ```
  34. POST /chat/completions
  35. ```
  36. **Headers:**
  37. | Header | Required | Description |
  38. |--------|----------|-------------|
  39. | `Authorization` | Yes | `Bearer YOUR_API_KEY` |
  40. | `Content-Type` | Yes | `application/json` |
  41. | `HTTP-Referer` | No | Your application URL |
  42. | `X-Title` | No | Your application name |
  43. **Body parameters:**
  44. | Parameter | Type | Required | Description |
  45. |-----------|------|----------|-------------|
  46. | `model` | string | Yes | Model ID in `provider/model` format (e.g., `anthropic/claude-sonnet-4-6`) |
  47. | `messages` | array | Yes | Array of message objects with `role` and `content` |
  48. | `stream` | boolean | No | Enable SSE streaming (default: `true`) |
  49. | `tools` | array | No | Tool definitions in OpenAI function calling format |
  50. | `temperature` | number | No | Sampling temperature |
  51. ### Example Request
  52. ```bash
  53. curl -X POST https://api.cline.bot/api/v1/chat/completions \
  54. -H "Authorization: Bearer YOUR_API_KEY" \
  55. -H "Content-Type: application/json" \
  56. -d '{
  57. "model": "anthropic/claude-sonnet-4-6",
  58. "messages": [
  59. {"role": "system", "content": "You are a helpful assistant."},
  60. {"role": "user", "content": "Explain what a context window is in 2 sentences."}
  61. ],
  62. "stream": true
  63. }'
  64. ```
  65. ### Response (Streaming)
  66. When `stream: true`, the response is a series of [Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-Sent_Events). Each event contains a JSON chunk:
  67. ```json
  68. data: {"id":"gen-abc123","choices":[{"delta":{"content":"A context"},"index":0}],"model":"anthropic/claude-sonnet-4-6"}
  69. data: {"id":"gen-abc123","choices":[{"delta":{"content":" window is"},"index":0}],"model":"anthropic/claude-sonnet-4-6"}
  70. data: [DONE]
  71. ```
  72. The final chunk includes a `usage` object with token counts and cost:
  73. ```json
  74. {
  75. "usage": {
  76. "prompt_tokens": 25,
  77. "completion_tokens": 42,
  78. "prompt_tokens_details": {
  79. "cached_tokens": 0
  80. },
  81. "cost": 0.000315
  82. }
  83. }
  84. ```
  85. ### Response (Non-Streaming)
  86. When `stream: false`, the response is a single JSON object:
  87. ```json
  88. {
  89. "id": "gen-abc123",
  90. "model": "anthropic/claude-sonnet-4-6",
  91. "choices": [
  92. {
  93. "message": {
  94. "role": "assistant",
  95. "content": "A context window is the maximum amount of text..."
  96. },
  97. "finish_reason": "stop",
  98. "index": 0
  99. }
  100. ],
  101. "usage": {
  102. "prompt_tokens": 25,
  103. "completion_tokens": 42
  104. }
  105. }
  106. ```
  107. ## Models
  108. Model IDs use the `provider/model-name` format, the same format used by [OpenRouter](https://openrouter.ai). Some examples:
  109. | Model ID | Description |
  110. |----------|-------------|
  111. | `anthropic/claude-sonnet-4-6` | Claude Sonnet 4.6 |
  112. | `anthropic/claude-sonnet-4-5` | Claude Sonnet 4.5 |
  113. | `google/gemini-2.5-pro` | Gemini 2.5 Pro |
  114. | `openai/gpt-4o` | GPT-4o |
  115. ### Free Models
  116. The following models are available at no cost:
  117. | Model ID | Provider |
  118. |----------|----------|
  119. | `minimax/minimax-m2.5` | MiniMax |
  120. | `kwaipilot/kat-coder-pro` | Kwaipilot |
  121. | `z-ai/glm-5` | Z-AI |
  122. <Note>
  123. Model availability and pricing may change. Check [app.cline.bot](https://app.cline.bot) for the latest list.
  124. </Note>
  125. ## Error Handling
  126. Errors follow the OpenAI error format:
  127. ```json
  128. {
  129. "error": {
  130. "code": 401,
  131. "message": "Invalid API key",
  132. "metadata": {}
  133. }
  134. }
  135. ```
  136. Common error codes:
  137. | Code | Meaning |
  138. |------|---------|
  139. | `401` | Invalid or missing API key |
  140. | `402` | Insufficient credits |
  141. | `429` | Rate limit exceeded |
  142. | `500` | Server error |
  143. | `error` (finish_reason) | Mid-stream error from the upstream model provider |
  144. ## Using with Cline
  145. The easiest way to use the Cline API is through the Cline extension or CLI, which handle authentication and streaming for you.
  146. ### VS Code / JetBrains
  147. Select **Cline** as your provider in the model picker dropdown. Sign in with your Cline account and your API key is managed automatically.
  148. ### Cline CLI
  149. Configure the CLI with your API key in one command:
  150. ```bash
  151. cline auth -p cline -k "YOUR_API_KEY" -m anthropic/claude-sonnet-4-6
  152. ```
  153. Then run tasks normally:
  154. ```bash
  155. cline "Write a one-line hello world in Python."
  156. ```
  157. See the [CLI Reference](/cline-cli/cli-reference) for all available commands and options.
  158. ## Using with Other Tools
  159. Because the Cline API is OpenAI-compatible, you can use it with any library or tool that supports custom OpenAI endpoints.
  160. ### Python (OpenAI SDK)
  161. ```python
  162. from openai import OpenAI
  163. client = OpenAI(
  164. base_url="https://api.cline.bot/api/v1",
  165. api_key="YOUR_API_KEY",
  166. )
  167. response = client.chat.completions.create(
  168. model="anthropic/claude-sonnet-4-6",
  169. messages=[{"role": "user", "content": "Hello!"}],
  170. )
  171. print(response.choices[0].message.content)
  172. ```
  173. ### Node.js (OpenAI SDK)
  174. ```typescript
  175. import OpenAI from "openai"
  176. const client = new OpenAI({
  177. baseURL: "https://api.cline.bot/api/v1",
  178. apiKey: "YOUR_API_KEY",
  179. })
  180. const response = await client.chat.completions.create({
  181. model: "anthropic/claude-sonnet-4-6",
  182. messages: [{ role: "user", content: "Hello!" }],
  183. })
  184. console.log(response.choices[0].message.content)
  185. ```
  186. ## Related
  187. <CardGroup cols={2}>
  188. <Card title="CLI Reference" icon="terminal" href="/cline-cli/cli-reference">
  189. Full command reference for the Cline CLI, including auth setup.
  190. </Card>
  191. <Card title="Enterprise API" icon="building" href="/enterprise-solutions/api-reference">
  192. Admin endpoints for user management, organizations, billing, and API keys.
  193. </Card>
  194. </CardGroup>