chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
---
|
||||
title: "Authentication"
|
||||
sidebarTitle: "Authentication"
|
||||
description: "How to authenticate with the Cline API using API keys or account tokens."
|
||||
---
|
||||
|
||||
Every request to the Cline API requires authentication via a Bearer token in the `Authorization` header.
|
||||
|
||||
## Authentication Methods
|
||||
|
||||
There are two ways to authenticate:
|
||||
|
||||
| Method | Use case | How to get it |
|
||||
|--------|----------|---------------|
|
||||
| **API key** | Direct API calls, scripts, CI/CD | Create at [app.cline.bot](https://app.cline.bot) Settings > API Keys |
|
||||
| **Account auth token** | Cline extension and CLI | Generated automatically when you sign in |
|
||||
|
||||
Both methods use the same header format:
|
||||
|
||||
```bash
|
||||
Authorization: Bearer YOUR_TOKEN
|
||||
```
|
||||
|
||||
## API Keys
|
||||
|
||||
API keys are the recommended authentication method for programmatic access.
|
||||
|
||||
### Creating a Key
|
||||
|
||||
<Steps>
|
||||
<Step title="Sign in">
|
||||
Go to [app.cline.bot](https://app.cline.bot) and sign in.
|
||||
</Step>
|
||||
<Step title="Open API Keys">
|
||||
Navigate to **Settings** > **API Keys**.
|
||||
</Step>
|
||||
<Step title="Create and copy">
|
||||
Create a new key. Copy it immediately as you will not be able to see it again.
|
||||
</Step>
|
||||
</Steps>
|
||||
|
||||
### Deleting a Key
|
||||
|
||||
You can revoke an API key at any time from the same Settings > API Keys page. Deleted keys stop working immediately.
|
||||
|
||||
You can also manage keys programmatically through the [Enterprise API](/enterprise-solutions/api-reference#api-keys):
|
||||
|
||||
```bash
|
||||
# List your keys
|
||||
curl https://api.cline.bot/api/v1/api-keys \
|
||||
-H "Authorization: Bearer YOUR_TOKEN"
|
||||
|
||||
# Delete a key
|
||||
curl -X DELETE https://api.cline.bot/api/v1/api-keys/KEY_ID \
|
||||
-H "Authorization: Bearer YOUR_TOKEN"
|
||||
```
|
||||
|
||||
## Account Auth Tokens
|
||||
|
||||
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.
|
||||
|
||||
The Cline CLI uses these tokens when you authenticate via:
|
||||
|
||||
```bash
|
||||
# Interactive sign-in
|
||||
cline auth
|
||||
|
||||
# Or quick setup with an API key
|
||||
cline auth -p cline -k "YOUR_API_KEY" -m anthropic/claude-sonnet-4-6
|
||||
```
|
||||
|
||||
See the [CLI Reference](/cli/cli-reference#cline-auth) for all auth options.
|
||||
|
||||
## Security Best Practices
|
||||
|
||||
**Do:**
|
||||
- Store API keys in environment variables or a secrets manager
|
||||
- Use different keys for development and production
|
||||
- Rotate keys periodically
|
||||
- Delete keys you no longer use
|
||||
|
||||
**Do not:**
|
||||
- Commit keys to version control
|
||||
- Share keys in chat or email
|
||||
- Embed keys in client-side code (browsers, mobile apps)
|
||||
- Log keys in application output
|
||||
|
||||
### Using Environment Variables
|
||||
|
||||
```bash
|
||||
# Set the key
|
||||
export CLINE_API_KEY="your_api_key_here"
|
||||
|
||||
# Use it in requests
|
||||
curl -X POST https://api.cline.bot/api/v1/chat/completions \
|
||||
-H "Authorization: Bearer $CLINE_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"model": "anthropic/claude-sonnet-4-6", "messages": [{"role": "user", "content": "Hello"}]}'
|
||||
```
|
||||
|
||||
### Using a .env File
|
||||
|
||||
```bash
|
||||
# .env (add to .gitignore)
|
||||
CLINE_API_KEY=your_api_key_here
|
||||
```
|
||||
|
||||
```python
|
||||
import os
|
||||
from openai import OpenAI
|
||||
|
||||
client = OpenAI(
|
||||
base_url="https://api.cline.bot/api/v1",
|
||||
api_key=os.environ["CLINE_API_KEY"],
|
||||
)
|
||||
```
|
||||
|
||||
## Custom Headers
|
||||
|
||||
The Cline API accepts optional headers for tracking and identification:
|
||||
|
||||
| Header | Description |
|
||||
|--------|-------------|
|
||||
| `HTTP-Referer` | Your application's URL. Helps with usage tracking. |
|
||||
| `X-Title` | Your application's name. Appears in usage logs. |
|
||||
| `X-Task-ID` | A unique task identifier. Used internally by the Cline extension. |
|
||||
|
||||
## Related
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="Getting Started" icon="rocket" href="/api/getting-started">
|
||||
Create your first API key and make a request.
|
||||
</Card>
|
||||
<Card title="Enterprise API Keys" icon="building" href="/enterprise-solutions/api-reference#api-keys">
|
||||
Manage API keys programmatically.
|
||||
</Card>
|
||||
</CardGroup>
|
||||
@@ -0,0 +1,258 @@
|
||||
---
|
||||
title: "Chat Completions"
|
||||
sidebarTitle: "Chat Completions"
|
||||
description: "Full reference for the POST /chat/completions endpoint including all parameters, streaming, and tool calling."
|
||||
---
|
||||
|
||||
The Chat Completions endpoint generates model responses from a conversation. It follows the [OpenAI Chat Completions](https://platform.openai.com/docs/api-reference/chat/create) format.
|
||||
|
||||
## Endpoint
|
||||
|
||||
```
|
||||
POST https://api.cline.bot/api/v1/chat/completions
|
||||
```
|
||||
|
||||
## Request Headers
|
||||
|
||||
| Header | Required | Description |
|
||||
|--------|----------|-------------|
|
||||
| `Authorization` | Yes | `Bearer YOUR_API_KEY` |
|
||||
| `Content-Type` | Yes | `application/json` |
|
||||
| `HTTP-Referer` | No | Your application URL (for usage tracking) |
|
||||
| `X-Title` | No | Your application name (for usage logs) |
|
||||
|
||||
## Request Body
|
||||
|
||||
| Parameter | Type | Required | Default | Description |
|
||||
|-----------|------|----------|---------|-------------|
|
||||
| `model` | string | Yes | | Model ID in `provider/model` format. See [Models](/api/models). |
|
||||
| `messages` | array | Yes | | Conversation messages. Each has `role` (`system`, `user`, `assistant`) and `content`. |
|
||||
| `stream` | boolean | No | `true` | Return the response as a stream of Server-Sent Events. |
|
||||
| `tools` | array | No | | Tool/function definitions in OpenAI format. |
|
||||
| `temperature` | number | No | Model default | Sampling temperature (0.0 to 2.0). Lower values are more deterministic. |
|
||||
|
||||
### Message Format
|
||||
|
||||
Each message in the `messages` array has this structure:
|
||||
|
||||
```json
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Your message here"
|
||||
}
|
||||
```
|
||||
|
||||
**Roles:**
|
||||
|
||||
| Role | Purpose |
|
||||
|------|---------|
|
||||
| `system` | Sets the model's behavior and persona. Place first in the array. |
|
||||
| `user` | The human's input. |
|
||||
| `assistant` | Previous model responses (for multi-turn conversations). |
|
||||
|
||||
### Multi-Turn Conversation
|
||||
|
||||
Include previous messages to maintain context:
|
||||
|
||||
```json
|
||||
{
|
||||
"model": "anthropic/claude-sonnet-4-6",
|
||||
"messages": [
|
||||
{"role": "system", "content": "You are a helpful coding assistant."},
|
||||
{"role": "user", "content": "What is a closure in JavaScript?"},
|
||||
{"role": "assistant", "content": "A closure is a function that..."},
|
||||
{"role": "user", "content": "Can you show me an example?"}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## Streaming Response
|
||||
|
||||
When `stream: true` (the default), the response is a series of [Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-Sent_Events):
|
||||
|
||||
```
|
||||
data: {"id":"gen-abc123","choices":[{"delta":{"role":"assistant"},"index":0}],"model":"anthropic/claude-sonnet-4-6"}
|
||||
|
||||
data: {"id":"gen-abc123","choices":[{"delta":{"content":"The capital"},"index":0}],"model":"anthropic/claude-sonnet-4-6"}
|
||||
|
||||
data: {"id":"gen-abc123","choices":[{"delta":{"content":" of France"},"index":0}],"model":"anthropic/claude-sonnet-4-6"}
|
||||
|
||||
data: {"id":"gen-abc123","choices":[{"delta":{"content":" is Paris."},"index":0,"finish_reason":"stop"}],"model":"anthropic/claude-sonnet-4-6","usage":{"prompt_tokens":14,"completion_tokens":8,"cost":0.000066}}
|
||||
|
||||
data: [DONE]
|
||||
```
|
||||
|
||||
Each `data:` line contains a JSON chunk. Key fields:
|
||||
|
||||
| Field | Description |
|
||||
|-------|-------------|
|
||||
| `id` | Generation ID, consistent across all chunks |
|
||||
| `choices[0].delta.content` | The new text in this chunk |
|
||||
| `choices[0].delta.reasoning` | Reasoning/thinking content (for reasoning models) |
|
||||
| `choices[0].finish_reason` | `stop` when complete, `error` on failure |
|
||||
| `usage` | Token counts and cost (included in the final chunk) |
|
||||
|
||||
### Usage Object
|
||||
|
||||
The final chunk includes token usage and cost:
|
||||
|
||||
```json
|
||||
{
|
||||
"usage": {
|
||||
"prompt_tokens": 25,
|
||||
"completion_tokens": 42,
|
||||
"prompt_tokens_details": {
|
||||
"cached_tokens": 0
|
||||
},
|
||||
"cost": 0.000315
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Description |
|
||||
|-------|-------------|
|
||||
| `prompt_tokens` | Total input tokens |
|
||||
| `completion_tokens` | Total output tokens |
|
||||
| `prompt_tokens_details.cached_tokens` | Tokens served from cache (reduces cost) |
|
||||
| `cost` | Total cost in USD for this request |
|
||||
|
||||
## Non-Streaming Response
|
||||
|
||||
When `stream: false`, the response is a single JSON object:
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "gen-abc123",
|
||||
"model": "anthropic/claude-sonnet-4-6",
|
||||
"choices": [
|
||||
{
|
||||
"message": {
|
||||
"role": "assistant",
|
||||
"content": "The capital of France is Paris."
|
||||
},
|
||||
"finish_reason": "stop",
|
||||
"index": 0
|
||||
}
|
||||
],
|
||||
"usage": {
|
||||
"prompt_tokens": 14,
|
||||
"completion_tokens": 8
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Tool Calling
|
||||
|
||||
You can define tools that the model can call using the OpenAI function calling format:
|
||||
|
||||
```json
|
||||
{
|
||||
"model": "anthropic/claude-sonnet-4-6",
|
||||
"messages": [
|
||||
{"role": "user", "content": "What's the weather in San Francisco?"}
|
||||
],
|
||||
"tools": [
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "get_weather",
|
||||
"description": "Get the current weather for a location",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"location": {
|
||||
"type": "string",
|
||||
"description": "City and state, e.g. San Francisco, CA"
|
||||
}
|
||||
},
|
||||
"required": ["location"]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
When the model decides to call a tool, the response includes a `tool_calls` array:
|
||||
|
||||
```json
|
||||
{
|
||||
"choices": [
|
||||
{
|
||||
"message": {
|
||||
"role": "assistant",
|
||||
"tool_calls": [
|
||||
{
|
||||
"id": "call_abc123",
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "get_weather",
|
||||
"arguments": "{\"location\": \"San Francisco, CA\"}"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"finish_reason": "tool_calls"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
To continue the conversation after a tool call, include the tool result:
|
||||
|
||||
```json
|
||||
{
|
||||
"messages": [
|
||||
{"role": "user", "content": "What's the weather in San Francisco?"},
|
||||
{"role": "assistant", "tool_calls": [{"id": "call_abc123", "type": "function", "function": {"name": "get_weather", "arguments": "{\"location\": \"San Francisco, CA\"}"}}]},
|
||||
{"role": "tool", "tool_call_id": "call_abc123", "content": "{\"temperature\": 62, \"condition\": \"foggy\"}"},
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## Reasoning Models
|
||||
|
||||
Some models support extended thinking (reasoning). When using these models, the response may include reasoning content in the streaming delta:
|
||||
|
||||
```json
|
||||
{"choices":[{"delta":{"reasoning":"Let me think about this step by step..."}}]}
|
||||
```
|
||||
|
||||
Reasoning tokens are separate from the main content and appear in the `delta.reasoning` field. Some providers return encrypted reasoning blocks via `delta.reasoning_details` that can be passed back in subsequent requests to preserve the reasoning trace.
|
||||
|
||||
<Note>
|
||||
Not all models support reasoning. See [Models](/api/models) for which models have reasoning capabilities.
|
||||
</Note>
|
||||
|
||||
## Complete Example
|
||||
|
||||
```bash
|
||||
curl -X POST https://api.cline.bot/api/v1/chat/completions \
|
||||
-H "Authorization: Bearer YOUR_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"model": "anthropic/claude-sonnet-4-6",
|
||||
"messages": [
|
||||
{"role": "system", "content": "You are a concise assistant. Answer in one sentence."},
|
||||
{"role": "user", "content": "Explain what an API is."}
|
||||
],
|
||||
"stream": true
|
||||
}'
|
||||
```
|
||||
|
||||
## Related
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="Models" icon="brain" href="/api/models">
|
||||
Browse available models and their capabilities.
|
||||
</Card>
|
||||
<Card title="Errors" icon="triangle-exclamation" href="/api/errors">
|
||||
Handle errors and implement retry logic.
|
||||
</Card>
|
||||
<Card title="SDK Examples" icon="code" href="/api/sdk-examples">
|
||||
Use this endpoint from Python, Node.js, and more.
|
||||
</Card>
|
||||
<Card title="Authentication" icon="key" href="/api/authentication">
|
||||
API key management and security practices.
|
||||
</Card>
|
||||
</CardGroup>
|
||||
@@ -0,0 +1,152 @@
|
||||
---
|
||||
title: "Errors"
|
||||
sidebarTitle: "Errors"
|
||||
description: "Error codes, error formats, mid-stream errors, and retry strategies for the Cline API."
|
||||
---
|
||||
|
||||
The Cline API returns errors in a consistent JSON format. Understanding these errors helps you build reliable integrations.
|
||||
|
||||
## Error Format
|
||||
|
||||
All errors follow the OpenAI error format:
|
||||
|
||||
```json
|
||||
{
|
||||
"error": {
|
||||
"code": 401,
|
||||
"message": "Invalid API key",
|
||||
"metadata": {}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Type | Description |
|
||||
|-------|------|-------------|
|
||||
| `code` | number/string | HTTP status code or error identifier |
|
||||
| `message` | string | Human-readable description of the error |
|
||||
| `metadata` | object | Additional context (provider details, request IDs) |
|
||||
|
||||
## Error Codes
|
||||
|
||||
### HTTP Errors
|
||||
|
||||
These are returned as the HTTP response status code and in the error body:
|
||||
|
||||
| Code | Name | Cause | What to do |
|
||||
|------|------|-------|------------|
|
||||
| `400` | Bad Request | Malformed request body, missing required fields | Check your JSON syntax and required parameters |
|
||||
| `401` | Unauthorized | Invalid or missing API key | Verify your API key in the `Authorization` header |
|
||||
| `402` | Payment Required | Insufficient credits | Add credits at [app.cline.bot](https://app.cline.bot) |
|
||||
| `403` | Forbidden | Key does not have access to this resource | Check key permissions |
|
||||
| `404` | Not Found | Invalid endpoint or model ID | Verify the URL and model ID format |
|
||||
| `429` | Too Many Requests | Rate limit exceeded | Wait and retry with exponential backoff |
|
||||
| `500` | Internal Server Error | Server-side issue | Retry after a short delay |
|
||||
| `502` | Bad Gateway | Upstream provider error | Retry after a short delay |
|
||||
| `503` | Service Unavailable | Service temporarily down | Retry after a short delay |
|
||||
|
||||
### Mid-Stream Errors
|
||||
|
||||
When streaming, errors can occur after the response has started. These appear as a chunk with `finish_reason: "error"`:
|
||||
|
||||
```json
|
||||
{
|
||||
"choices": [
|
||||
{
|
||||
"finish_reason": "error",
|
||||
"error": {
|
||||
"code": "context_length_exceeded",
|
||||
"message": "The input exceeds the model's maximum context length."
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Common mid-stream error codes:
|
||||
|
||||
| Code | Meaning |
|
||||
|------|---------|
|
||||
| `context_length_exceeded` | Input tokens exceed the model's context window |
|
||||
| `content_filter` | Content was blocked by a safety filter |
|
||||
| `rate_limit` | Rate limit hit during generation |
|
||||
| `server_error` | Upstream provider failed during generation |
|
||||
|
||||
<Warning>
|
||||
Mid-stream errors do not produce an HTTP error code (the connection was already 200 OK). Always check `finish_reason` in your streaming handler.
|
||||
</Warning>
|
||||
|
||||
## Retry Strategies
|
||||
|
||||
### Exponential Backoff
|
||||
|
||||
For transient errors (429, 500, 502, 503), retry with exponential backoff:
|
||||
|
||||
```python
|
||||
import time
|
||||
import requests
|
||||
|
||||
def call_api_with_retry(payload, max_retries=3):
|
||||
for attempt in range(max_retries):
|
||||
response = requests.post(
|
||||
"https://api.cline.bot/api/v1/chat/completions",
|
||||
headers={
|
||||
"Authorization": "Bearer YOUR_API_KEY",
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
json=payload,
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
return response.json()
|
||||
|
||||
if response.status_code in (429, 500, 502, 503):
|
||||
delay = (2 ** attempt) + 1
|
||||
print(f"Retrying in {delay}s (attempt {attempt + 1}/{max_retries})")
|
||||
time.sleep(delay)
|
||||
continue
|
||||
|
||||
# Non-retryable error
|
||||
response.raise_for_status()
|
||||
|
||||
raise Exception("Max retries exceeded")
|
||||
```
|
||||
|
||||
### When to Retry
|
||||
|
||||
| Error | Retry? | Strategy |
|
||||
|-------|--------|----------|
|
||||
| `401 Unauthorized` | No | Fix your API key |
|
||||
| `402 Payment Required` | No | Add credits |
|
||||
| `429 Too Many Requests` | Yes | Exponential backoff (start at 1s) |
|
||||
| `500 Internal Server Error` | Yes | Retry once after 1s |
|
||||
| `502 Bad Gateway` | Yes | Retry up to 3 times with backoff |
|
||||
| `503 Service Unavailable` | Yes | Retry up to 3 times with backoff |
|
||||
| Mid-stream `error` | Depends | Retry the full request for transient errors |
|
||||
|
||||
### Rate Limits
|
||||
|
||||
If you hit rate limits frequently:
|
||||
|
||||
- Add delays between requests
|
||||
- Reduce the number of concurrent requests
|
||||
- Contact support if you need higher limits
|
||||
|
||||
## Debugging
|
||||
|
||||
When reporting issues, include:
|
||||
|
||||
1. The **error code and message** from the response
|
||||
2. The **model ID** you were using
|
||||
3. The **request ID** (from the `x-request-id` response header, if available)
|
||||
4. Whether the error was **immediate** (HTTP error) or **mid-stream** (finish_reason error)
|
||||
|
||||
## Related
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="Chat Completions" icon="message" href="/api/chat-completions">
|
||||
Endpoint reference with request and response schemas.
|
||||
</Card>
|
||||
<Card title="Authentication" icon="key" href="/api/authentication">
|
||||
Verify your API key is configured correctly.
|
||||
</Card>
|
||||
</CardGroup>
|
||||
@@ -0,0 +1,136 @@
|
||||
---
|
||||
title: "Getting Started"
|
||||
sidebarTitle: "Getting Started"
|
||||
description: "Create an API key and make your first request to the Cline API in under a minute."
|
||||
---
|
||||
|
||||
This guide walks you through creating an API key and making your first Chat Completions request.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- A Cline account at [app.cline.bot](https://app.cline.bot)
|
||||
- `curl` or any HTTP client (Python, Node.js, etc.)
|
||||
|
||||
## Create an API Key
|
||||
|
||||
<Steps>
|
||||
<Step title="Sign in to app.cline.bot">
|
||||
Go to [app.cline.bot](https://app.cline.bot) and sign in with your account.
|
||||
</Step>
|
||||
<Step title="Navigate to API Keys">
|
||||
Open **Settings** and select **API Keys**.
|
||||
</Step>
|
||||
<Step title="Create a new key">
|
||||
Click **Create API Key**. Copy the key immediately. You will not be able to see it again after leaving this page.
|
||||
</Step>
|
||||
</Steps>
|
||||
|
||||
<Warning>
|
||||
Treat your API key like a password. Do not commit it to version control or share it publicly.
|
||||
</Warning>
|
||||
|
||||
## Make Your First Request
|
||||
|
||||
Replace `YOUR_API_KEY` with the key you just created:
|
||||
|
||||
```bash
|
||||
curl -X POST https://api.cline.bot/api/v1/chat/completions \
|
||||
-H "Authorization: Bearer YOUR_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"model": "anthropic/claude-sonnet-4-6",
|
||||
"messages": [
|
||||
{"role": "user", "content": "What is the capital of France?"}
|
||||
],
|
||||
"stream": false
|
||||
}'
|
||||
```
|
||||
|
||||
## Verify the Response
|
||||
|
||||
You should get a JSON response like this:
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "gen-abc123",
|
||||
"model": "anthropic/claude-sonnet-4-6",
|
||||
"choices": [
|
||||
{
|
||||
"message": {
|
||||
"role": "assistant",
|
||||
"content": "The capital of France is Paris."
|
||||
},
|
||||
"finish_reason": "stop",
|
||||
"index": 0
|
||||
}
|
||||
],
|
||||
"usage": {
|
||||
"prompt_tokens": 14,
|
||||
"completion_tokens": 8
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The `choices[0].message.content` field contains the model's reply. The `usage` field shows how many tokens were consumed.
|
||||
|
||||
## Try Streaming
|
||||
|
||||
For real-time output, set `stream: true`. The response arrives as Server-Sent Events:
|
||||
|
||||
```bash
|
||||
curl -X POST https://api.cline.bot/api/v1/chat/completions \
|
||||
-H "Authorization: Bearer YOUR_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"model": "anthropic/claude-sonnet-4-6",
|
||||
"messages": [
|
||||
{"role": "user", "content": "Write a haiku about programming."}
|
||||
],
|
||||
"stream": true
|
||||
}'
|
||||
```
|
||||
|
||||
Each chunk arrives as a `data:` line. The stream ends with `data: [DONE]`.
|
||||
|
||||
## Try a Free Model
|
||||
|
||||
To test without spending credits, use one of the [free models](/api/models#free-models):
|
||||
|
||||
```bash
|
||||
curl -X POST https://api.cline.bot/api/v1/chat/completions \
|
||||
-H "Authorization: Bearer YOUR_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"model": "minimax/minimax-m2.5",
|
||||
"messages": [
|
||||
{"role": "user", "content": "Hello! What can you help me with?"}
|
||||
],
|
||||
"stream": false
|
||||
}'
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
| Problem | Solution |
|
||||
|---------|----------|
|
||||
| `401 Unauthorized` | Check that your API key is correct and included in the `Authorization` header |
|
||||
| `402 Payment Required` | Your account has insufficient credits. Add credits at [app.cline.bot](https://app.cline.bot) |
|
||||
| Empty response | Make sure `messages` is a non-empty array with at least one user message |
|
||||
| Connection timeout | Verify your network can reach `api.cline.bot`. Check proxy settings if on a corporate network |
|
||||
|
||||
## Next Steps
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="Authentication" icon="key" href="/api/authentication">
|
||||
Learn about API keys, token scoping, and security practices.
|
||||
</Card>
|
||||
<Card title="Chat Completions" icon="message" href="/api/chat-completions">
|
||||
Full endpoint reference with all parameters and options.
|
||||
</Card>
|
||||
<Card title="Models" icon="brain" href="/api/models">
|
||||
Browse available models and find the right one for your use case.
|
||||
</Card>
|
||||
<Card title="SDK Examples" icon="code" href="/api/sdk-examples">
|
||||
Use the API from Python, Node.js, or the Cline CLI.
|
||||
</Card>
|
||||
</CardGroup>
|
||||
@@ -0,0 +1,89 @@
|
||||
---
|
||||
title: "Models"
|
||||
sidebarTitle: "Models"
|
||||
description: "Available models, pricing tiers, free models, and how model IDs work in the Cline API."
|
||||
---
|
||||
|
||||
The Cline API gives you access to models from multiple providers through a single endpoint. Model IDs follow the `provider/model-name` format, the same convention used by [OpenRouter](https://openrouter.ai).
|
||||
|
||||
## Model ID Format
|
||||
|
||||
Every model is identified by a string in the format:
|
||||
|
||||
```
|
||||
provider/model-name
|
||||
```
|
||||
|
||||
For example:
|
||||
- `anthropic/claude-sonnet-4-6` - Claude Sonnet 4.6 from Anthropic
|
||||
- `openai/gpt-4o` - GPT-4o from OpenAI
|
||||
- `google/gemini-2.5-pro` - Gemini 2.5 Pro from Google
|
||||
|
||||
Pass this string as the `model` parameter in your [Chat Completions](/api/chat-completions) request.
|
||||
|
||||
Example:
|
||||
|
||||
```bash
|
||||
curl -X POST https://api.cline.bot/api/v1/chat/completions \
|
||||
-H "Authorization: Bearer YOUR_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"model": "minimax/minimax-m2.5",
|
||||
"messages": [{"role": "user", "content": "Hello!"}]
|
||||
}'
|
||||
```
|
||||
|
||||
## Reasoning Models
|
||||
|
||||
Some models support extended thinking, where the model reasons through a problem before responding. When using these models:
|
||||
|
||||
- Reasoning content appears in `delta.reasoning` during streaming
|
||||
- Some providers return encrypted reasoning blocks in `delta.reasoning_details`
|
||||
- Reasoning tokens are counted separately from output tokens
|
||||
|
||||
Models with reasoning support include most Claude, Gemini 2.5, and Grok 3 models. Check the model's `supportsReasoning` capability in the model catalog.
|
||||
|
||||
## Choosing a Model
|
||||
|
||||
| If you need... | Consider |
|
||||
|----------------|----------|
|
||||
| Best coding performance | `anthropic/claude-sonnet-4-6` |
|
||||
| Long document analysis | `google/gemini-2.5-pro` (1M context) |
|
||||
| Fast, cheap responses | `deepseek/deepseek-chat` |
|
||||
| Free experimentation | `minimax/minimax-m2.5` |
|
||||
| Multi-modal (text + images) | `openai/gpt-4o` or `anthropic/claude-sonnet-4-6` |
|
||||
| Complex reasoning | Any model with reasoning support |
|
||||
|
||||
For setup and account flow details, see the [Cline Provider guide](/getting-started/cline-provider).
|
||||
|
||||
## Image Support
|
||||
|
||||
Models that support images accept base64-encoded image content in the `messages` array:
|
||||
|
||||
```json
|
||||
{
|
||||
"model": "anthropic/claude-sonnet-4-6",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": [
|
||||
{"type": "text", "text": "What's in this image?"},
|
||||
{"type": "image_url", "image_url": {"url": "data:image/png;base64,..."}}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Not all models support images. Check the model's `supportsImages` capability before sending image content.
|
||||
|
||||
## Related
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="Chat Completions" icon="message" href="/api/chat-completions">
|
||||
Use these models in your API requests.
|
||||
</Card>
|
||||
<Card title="Cline Provider" icon="scale-balanced" href="/getting-started/cline-provider">
|
||||
Fastest setup path with built-in authentication and billing.
|
||||
</Card>
|
||||
</CardGroup>
|
||||
@@ -0,0 +1,58 @@
|
||||
---
|
||||
title: "Cline API"
|
||||
sidebarTitle: "Overview"
|
||||
description: "Programmatic access to AI models through an OpenAI-compatible Chat Completions API."
|
||||
---
|
||||
|
||||
Welcome to the Cline API documentation. Use the same models that power the Cline extension and CLI from any language, framework, or tool that speaks the OpenAI format.
|
||||
|
||||
## What is the Cline API?
|
||||
|
||||
The Cline API is an OpenAI-compatible Chat Completions endpoint. You authenticate once with a Cline API key and get access to models from Anthropic, OpenAI, Google, and more through a single base URL. No need to manage separate keys for each provider.
|
||||
|
||||
```
|
||||
Your App → Cline API (api.cline.bot) → Anthropic / OpenAI / Google / etc.
|
||||
```
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="Getting Started" icon="rocket" href="/api/getting-started">
|
||||
Create an API key and make your first request in under a minute.
|
||||
</Card>
|
||||
<Card title="Authentication" icon="key" href="/api/authentication">
|
||||
API keys, account tokens, key rotation, and security best practices.
|
||||
</Card>
|
||||
<Card title="Chat Completions" icon="message" href="/api/chat-completions">
|
||||
Full endpoint reference with request schemas, streaming, and tool calling.
|
||||
</Card>
|
||||
<Card title="Code Examples" icon="code" href="/api/sdk-examples">
|
||||
Ready-to-copy examples for Python, Node.js, curl, and the Cline CLI.
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
## Explore the Reference
|
||||
|
||||
<CardGroup cols={3}>
|
||||
<Card title="Models" icon="brain" href="/api/models">
|
||||
Browse available models, free tier options, reasoning support, and selection guidance.
|
||||
</Card>
|
||||
<Card title="Errors" icon="triangle-exclamation" href="/api/errors">
|
||||
Error codes, mid-stream errors, retry strategies, and debugging tips.
|
||||
</Card>
|
||||
<Card title="Enterprise API" icon="building" href="/enterprise-solutions/api-reference">
|
||||
Admin endpoints for managing users, organizations, billing, and API keys.
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
## Quick Start
|
||||
|
||||
```bash
|
||||
curl -X POST https://api.cline.bot/api/v1/chat/completions \
|
||||
-H "Authorization: Bearer YOUR_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"model": "anthropic/claude-sonnet-4-6",
|
||||
"messages": [{"role": "user", "content": "Hello!"}]
|
||||
}'
|
||||
```
|
||||
|
||||
Get your API key at [app.cline.bot](https://app.cline.bot) (Settings > API Keys), then follow the [Getting Started](/api/getting-started) guide.
|
||||
@@ -0,0 +1,275 @@
|
||||
---
|
||||
title: "Code Examples"
|
||||
sidebarTitle: "Code Examples"
|
||||
description: "Use the Cline API from Python, Node.js, curl, the Cline CLI, and the VS Code extension."
|
||||
---
|
||||
|
||||
The Cline API is OpenAI-compatible, so any library or tool that works with OpenAI also works with the Cline API. Just change the base URL and API key.
|
||||
|
||||
## curl
|
||||
|
||||
### Non-Streaming
|
||||
|
||||
```bash
|
||||
curl -X POST https://api.cline.bot/api/v1/chat/completions \
|
||||
-H "Authorization: Bearer $CLINE_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"model": "anthropic/claude-sonnet-4-6",
|
||||
"messages": [{"role": "user", "content": "What is 2+2?"}],
|
||||
"stream": false
|
||||
}'
|
||||
```
|
||||
|
||||
### Streaming
|
||||
|
||||
```bash
|
||||
curl -X POST https://api.cline.bot/api/v1/chat/completions \
|
||||
-H "Authorization: Bearer $CLINE_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"model": "anthropic/claude-sonnet-4-6",
|
||||
"messages": [{"role": "user", "content": "Write a short poem about code."}],
|
||||
"stream": true
|
||||
}'
|
||||
```
|
||||
|
||||
## Python
|
||||
|
||||
### OpenAI SDK
|
||||
|
||||
The [OpenAI Python SDK](https://github.com/openai/openai-python) works with the Cline API by setting `base_url`:
|
||||
|
||||
```python
|
||||
from openai import OpenAI
|
||||
|
||||
client = OpenAI(
|
||||
base_url="https://api.cline.bot/api/v1",
|
||||
api_key="YOUR_API_KEY",
|
||||
)
|
||||
|
||||
# Non-streaming
|
||||
response = client.chat.completions.create(
|
||||
model="anthropic/claude-sonnet-4-6",
|
||||
messages=[{"role": "user", "content": "Explain recursion in one sentence."}],
|
||||
)
|
||||
print(response.choices[0].message.content)
|
||||
```
|
||||
|
||||
### Streaming in Python
|
||||
|
||||
```python
|
||||
from openai import OpenAI
|
||||
|
||||
client = OpenAI(
|
||||
base_url="https://api.cline.bot/api/v1",
|
||||
api_key="YOUR_API_KEY",
|
||||
)
|
||||
|
||||
stream = client.chat.completions.create(
|
||||
model="anthropic/claude-sonnet-4-6",
|
||||
messages=[{"role": "user", "content": "Write a function to reverse a string in Python."}],
|
||||
stream=True,
|
||||
)
|
||||
|
||||
for chunk in stream:
|
||||
content = chunk.choices[0].delta.content
|
||||
if content:
|
||||
print(content, end="", flush=True)
|
||||
print()
|
||||
```
|
||||
|
||||
### Tool Calling in Python
|
||||
|
||||
```python
|
||||
from openai import OpenAI
|
||||
import json
|
||||
|
||||
client = OpenAI(
|
||||
base_url="https://api.cline.bot/api/v1",
|
||||
api_key="YOUR_API_KEY",
|
||||
)
|
||||
|
||||
tools = [
|
||||
{
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "get_weather",
|
||||
"description": "Get weather for a location",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"location": {"type": "string", "description": "City name"}
|
||||
},
|
||||
"required": ["location"],
|
||||
},
|
||||
},
|
||||
}
|
||||
]
|
||||
|
||||
response = client.chat.completions.create(
|
||||
model="anthropic/claude-sonnet-4-6",
|
||||
messages=[{"role": "user", "content": "What's the weather in Tokyo?"}],
|
||||
tools=tools,
|
||||
)
|
||||
|
||||
# Check if the model wants to call a tool
|
||||
choice = response.choices[0]
|
||||
if choice.message.tool_calls:
|
||||
tool_call = choice.message.tool_calls[0]
|
||||
print(f"Tool: {tool_call.function.name}")
|
||||
print(f"Args: {tool_call.function.arguments}")
|
||||
```
|
||||
|
||||
### Using requests
|
||||
|
||||
If you prefer not to use the OpenAI SDK:
|
||||
|
||||
```python
|
||||
import requests
|
||||
|
||||
response = requests.post(
|
||||
"https://api.cline.bot/api/v1/chat/completions",
|
||||
headers={
|
||||
"Authorization": "Bearer YOUR_API_KEY",
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
json={
|
||||
"model": "anthropic/claude-sonnet-4-6",
|
||||
"messages": [{"role": "user", "content": "Hello!"}],
|
||||
"stream": False,
|
||||
},
|
||||
)
|
||||
|
||||
data = response.json()
|
||||
print(data["choices"][0]["message"]["content"])
|
||||
```
|
||||
|
||||
## Node.js / TypeScript
|
||||
|
||||
### OpenAI SDK
|
||||
|
||||
The [OpenAI Node.js SDK](https://github.com/openai/openai-node) works with the Cline API by setting `baseURL`:
|
||||
|
||||
```typescript
|
||||
import OpenAI from "openai"
|
||||
|
||||
const client = new OpenAI({
|
||||
baseURL: "https://api.cline.bot/api/v1",
|
||||
apiKey: "YOUR_API_KEY",
|
||||
})
|
||||
|
||||
// Non-streaming
|
||||
const response = await client.chat.completions.create({
|
||||
model: "anthropic/claude-sonnet-4-6",
|
||||
messages: [{ role: "user", content: "Explain async/await in one sentence." }],
|
||||
})
|
||||
console.log(response.choices[0].message.content)
|
||||
```
|
||||
|
||||
### Streaming in Node.js
|
||||
|
||||
```typescript
|
||||
import OpenAI from "openai"
|
||||
|
||||
const client = new OpenAI({
|
||||
baseURL: "https://api.cline.bot/api/v1",
|
||||
apiKey: "YOUR_API_KEY",
|
||||
})
|
||||
|
||||
const stream = await client.chat.completions.create({
|
||||
model: "anthropic/claude-sonnet-4-6",
|
||||
messages: [{ role: "user", content: "Write a haiku about TypeScript." }],
|
||||
stream: true,
|
||||
})
|
||||
|
||||
for await (const chunk of stream) {
|
||||
const content = chunk.choices[0]?.delta?.content
|
||||
if (content) {
|
||||
process.stdout.write(content)
|
||||
}
|
||||
}
|
||||
console.log()
|
||||
```
|
||||
|
||||
### Using fetch
|
||||
|
||||
```typescript
|
||||
const response = await fetch("https://api.cline.bot/api/v1/chat/completions", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: "Bearer YOUR_API_KEY",
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
model: "anthropic/claude-sonnet-4-6",
|
||||
messages: [{ role: "user", content: "Hello!" }],
|
||||
stream: false,
|
||||
}),
|
||||
})
|
||||
|
||||
const data = await response.json()
|
||||
console.log(data.choices[0].message.content)
|
||||
```
|
||||
|
||||
## Cline CLI
|
||||
|
||||
The [Cline CLI](/cli/cli-reference) is the fastest way to use the Cline API from your terminal. It handles authentication, streaming, and tool execution for you.
|
||||
|
||||
### Setup
|
||||
|
||||
```bash
|
||||
# Install
|
||||
npm install -g @anthropic-ai/cline
|
||||
|
||||
# Authenticate with a Cline API key
|
||||
cline auth -p cline -k "YOUR_API_KEY" -m anthropic/claude-sonnet-4-6
|
||||
```
|
||||
|
||||
### Run Tasks
|
||||
|
||||
```bash
|
||||
# Simple prompt
|
||||
cline "Explain what a REST API is."
|
||||
|
||||
# Pipe input
|
||||
cat README.md | cline "Summarize this document."
|
||||
|
||||
# Use a specific model
|
||||
cline -m google/gemini-2.5-pro "Analyze this codebase."
|
||||
|
||||
# YOLO mode for automation
|
||||
cline -y "Run tests and fix failures."
|
||||
```
|
||||
|
||||
See the [CLI Reference](/cli/cli-reference) for all commands and options.
|
||||
|
||||
## VS Code / JetBrains
|
||||
|
||||
The Cline extension handles the API integration for you:
|
||||
|
||||
1. Open the Cline panel in your editor
|
||||
2. Select **Cline** as the provider in the model picker
|
||||
3. Sign in with your Cline account
|
||||
4. Start chatting or give Cline a task
|
||||
|
||||
Your API key is managed automatically. No manual configuration needed.
|
||||
|
||||
For setup instructions, see [Installing Cline](/getting-started/installing-cline) and [Authorizing with Cline](/getting-started/authorizing-with-cline).
|
||||
|
||||
## Related
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="Chat Completions" icon="message" href="/api/chat-completions">
|
||||
Full endpoint reference with all parameters.
|
||||
</Card>
|
||||
<Card title="Authentication" icon="key" href="/api/authentication">
|
||||
API key management and security practices.
|
||||
</Card>
|
||||
<Card title="Models" icon="brain" href="/api/models">
|
||||
Browse available models.
|
||||
</Card>
|
||||
<Card title="CLI Reference" icon="terminal" href="/cli/cli-reference">
|
||||
Complete Cline CLI command reference.
|
||||
</Card>
|
||||
</CardGroup>
|
||||
Reference in New Issue
Block a user