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

# Chat completions

> Send messages to AI models and get responses

This is the core endpoint for all AI-powered features — summarization, extraction, analysis, drafting.

```bash title="Endpoint" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
POST /llm/v1/chat/completions
```

<CodeGroup>
  ```bash title="cURL" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  curl -X POST https://api.case.dev/llm/v1/chat/completions \
    -H "Authorization: Bearer sk_case_YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "anthropic/claude-sonnet-4.5",
      "messages": [
        {"role": "user", "content": "Summarize this deposition in 3 bullet points."}
      ]
    }'
  ```

  ```bash title="CLI" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  casedev llm:v1:chat create-completion \
    --model anthropic/claude-sonnet-4.5 \
    --message '{role: user, content: "Summarize this deposition in 3 bullet points."}'
  ```

  ```typescript title="Typescript" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  import Casedev from 'casedev';

  const client = new Casedev({ apiKey: 'sk_case_YOUR_API_KEY' });

  const response = await client.llm.v1.chat.createCompletion({
    model: 'anthropic/claude-sonnet-4.5',
    messages: [
      { role: 'user', content: 'Summarize this deposition in 3 bullet points.' }
    ]
  });

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

  ```python title="Python" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  import casedev

  client = casedev.Casedev(api_key='sk_case_YOUR_API_KEY')

  response = client.llm.v1.chat.create_completion(
      model='anthropic/claude-sonnet-4.5',
      messages=[
          {'role': 'user', 'content': 'Summarize this deposition in 3 bullet points.'}
      ]
  )

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

  ```go title="Go" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  resp, _ := client.Llm.V1.Chat.NewCompletion(ctx, casedev.LlmV1ChatNewCompletionParams{
  	Model: casedev.F("anthropic/claude-sonnet-4.5"),
  	Messages: casedev.F([]casedev.LlmV1ChatNewCompletionParamsMessage{{
  		Role:    casedev.F(casedev.LlmV1ChatNewCompletionParamsMessagesRoleUser),
  		Content: casedev.F("Summarize this deposition in 3 bullet points."),
  	}}),
  })
  fmt.Println(resp.Choices[0].Message.Content)
  ```
</CodeGroup>

```json title="Response" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
{
  "id": "gen_01K972J7KV4Y0MJZ3SRTA6YYMH",
  "object": "chat.completion",
  "model": "anthropic/claude-sonnet-4.5",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Here are the key points:\n\n• Witness testified that...\n• Documents reviewed include...\n• Timeline established from..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 245,
    "completion_tokens": 87,
    "total_tokens": 332,
    "cost": 0.000105
  }
}
```

## Parameters

### Required

| Parameter  | Type  | Description                                                |
| ---------- | ----- | ---------------------------------------------------------- |
| `messages` | array | The conversation. Each message has a `role` and `content`. |

### Optional

| Parameter     | Type    | Default               | Description                                                             |
| ------------- | ------- | --------------------- | ----------------------------------------------------------------------- |
| `model`       | string  | `casemark/core-large` | Which model to use. [Browse all 195+ models →](https://case.dev/models) |
| `max_tokens`  | number  | 4096                  | Maximum tokens to generate                                              |
| `temperature` | number  | 1                     | Randomness (0-2). Use 0 for factual tasks.                              |
| `stream`      | boolean | false                 | Stream response token-by-token                                          |
| `stop`        | array   | null                  | Stop generation when these strings appear                               |

## Messages

Each message in the `messages` array:

| Field     | Type   | Description                      |
| --------- | ------ | -------------------------------- |
| `role`    | string | `system`, `user`, or `assistant` |
| `content` | string | The message text                 |

### System prompts

Set the AI's behavior with a system message:

<CodeGroup>
  ```bash title="CLI" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  casedev llm:v1:chat create-completion \
    --model anthropic/claude-sonnet-4.5 \
    --message '{role: system, content: "You are a legal assistant. Be concise. Cite case law when relevant."}' \
    --message '{role: user, content: "What are the elements of negligence?"}'
  ```

  ```typescript title="Typescript" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  const response = await client.llm.v1.chat.createCompletion({
    model: 'anthropic/claude-sonnet-4.5',
    messages: [
      {
        role: 'system',
        content: 'You are a legal assistant. Be concise. Cite case law when relevant.'
      },
      {
        role: 'user',
        content: 'What are the elements of negligence?'
      }
    ]
  });
  ```

  ```python title="Python" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  response = client.llm.v1.chat.create_completion(
      model='anthropic/claude-sonnet-4.5',
      messages=[
          {
              'role': 'system',
              'content': 'You are a legal assistant. Be concise. Cite case law when relevant.'
          },
          {
              'role': 'user',
              'content': 'What are the elements of negligence?'
          }
      ]
  )
  ```

  ```go title="Go" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  resp, _ := client.Llm.V1.Chat.NewCompletion(ctx, casedev.LlmV1ChatNewCompletionParams{
  	Model: casedev.F("anthropic/claude-sonnet-4.5"),
  	Messages: casedev.F([]casedev.LlmV1ChatNewCompletionParamsMessage{
  		{
  			Role:    casedev.F(casedev.LlmV1ChatNewCompletionParamsMessagesRoleSystem),
  			Content: casedev.F("You are a legal assistant. Be concise. Cite case law when relevant."),
  		},
  		{
  			Role:    casedev.F(casedev.LlmV1ChatNewCompletionParamsMessagesRoleUser),
  			Content: casedev.F("What are the elements of negligence?"),
  		},
  	}),
  })
  fmt.Println(resp.Choices[0].Message.Content)
  ```
</CodeGroup>

### Multi-turn conversations

Include previous messages to maintain context:

<CodeGroup>
  ```bash title="CLI" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  casedev llm:v1:chat create-completion \
    --model openai/gpt-4o \
    --message '{role: user, content: "What is a deposition?"}' \
    --message '{role: assistant, content: "A deposition is sworn testimony taken outside of court..."}' \
    --message '{role: user, content: "How long do they typically last?"}'
  ```

  ```typescript title="Typescript" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  const response = await client.llm.v1.chat.createCompletion({
    model: 'openai/gpt-4o',
    messages: [
      { role: 'user', content: 'What is a deposition?' },
      { role: 'assistant', content: 'A deposition is sworn testimony taken outside of court...' },
      { role: 'user', content: 'How long do they typically last?' }
    ]
  });
  ```

  ```python title="Python" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  response = client.llm.v1.chat.create_completion(
      model='openai/gpt-4o',
      messages=[
          {'role': 'user', 'content': 'What is a deposition?'},
          {'role': 'assistant', 'content': 'A deposition is sworn testimony taken outside of court...'},
          {'role': 'user', 'content': 'How long do they typically last?'}
      ]
  )
  ```

  ```go title="Go" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  resp, _ := client.Llm.V1.Chat.NewCompletion(ctx, casedev.LlmV1ChatNewCompletionParams{
  	Model: casedev.F("openai/gpt-4o"),
  	Messages: casedev.F([]casedev.LlmV1ChatNewCompletionParamsMessage{
  		{Role: casedev.F(casedev.LlmV1ChatNewCompletionParamsMessagesRoleUser), Content: casedev.F("What is a deposition?")},
  		{Role: casedev.F(casedev.LlmV1ChatNewCompletionParamsMessagesRoleAssistant), Content: casedev.F("A deposition is sworn testimony taken outside of court...")},
  		{Role: casedev.F(casedev.LlmV1ChatNewCompletionParamsMessagesRoleUser), Content: casedev.F("How long do they typically last?")},
  	}),
  })
  fmt.Println(resp.Choices[0].Message.Content)
  ```
</CodeGroup>

## Streaming

Get responses token-by-token as they're generated:

<CodeGroup>
  ```bash title="CLI" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  casedev llm:v1:chat create-completion \
    --model anthropic/claude-sonnet-4.5 \
    --message '{role: user, content: "Write a case summary."}' \
    --stream
  ```

  ```typescript title="Typescript" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  const stream = await client.llm.v1.chat.createCompletion({
    model: 'anthropic/claude-sonnet-4.5',
    messages: [{ role: 'user', content: 'Write a case summary.' }],
    stream: true
  });

  for await (const chunk of stream) {
    process.stdout.write(chunk.choices[0]?.delta?.content || '');
  }
  ```

  ```python title="Python" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  stream = client.llm.v1.chat.create_completion(
      model='anthropic/claude-sonnet-4.5',
      messages=[{'role': 'user', 'content': 'Write a case summary.'}],
      stream=True
  )

  for chunk in stream:
      print(chunk.choices[0].delta.content or '', end='')
  ```

  ```go title="Go" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  package main

  import (
  	"context"
  	"net/http"

  	casedev "github.com/CaseMark/casedev-go"
  	"github.com/CaseMark/casedev-go/option"
  )

  func main() {
  	client := casedev.NewClient()

  	var httpResp *http.Response
  	client.Llm.V1.Chat.NewCompletion(context.TODO(), casedev.LlmV1ChatNewCompletionParams{
  		Model: casedev.F("anthropic/claude-sonnet-4.5"),
  		Messages: casedev.F([]casedev.LlmV1ChatNewCompletionParamsMessage{{
  			Role:    casedev.F(casedev.LlmV1ChatNewCompletionParamsMessagesRoleUser),
  			Content: casedev.F("Write a case summary."),
  		}}),
  		Stream: casedev.F(true),
  	}, option.WithResponseInto(&httpResp))
  	// Read httpResp.Body as SSE stream
  }
  ```
</CodeGroup>

## Vision

Send images to models that support vision (Claude, GPT-4o):

```typescript title="Typescript" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
const response = await client.llm.v1.chat.createCompletion({
  model: 'anthropic/claude-sonnet-4.5',
  messages: [
    {
      role: 'user',
      content: [
        { type: 'text', text: 'What medical equipment is visible in this image?' },
        { type: 'image_url', image_url: { url: 'https://example.com/exhibit-a.jpg' } }
      ]
    }
  ]
});
```

## Usage and costs

Every response includes token counts and cost:

```json title="Response" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
{
  "usage": {
    "prompt_tokens": 1245,
    "completion_tokens": 387,
    "total_tokens": 1632,
    "cost": 0.004896
  }
}
```

<Info>
  **Reduce costs:** Use `temperature: 0` for factual extraction. Try cheaper models like `deepseek/deepseek-chat` or `qwen/qwen-2.5-72b-instruct` for simpler tasks.
</Info>

## Common patterns

### Deposition summary

<CodeGroup>
  ```bash title="CLI" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  casedev llm:v1:chat create-completion \
    --model anthropic/claude-sonnet-4.5 \
    --message '{role: system, content: "Summarize depositions with: 1. Key admissions 2. Timeline of events 3. Credibility issues 4. Contradictions with other testimony"}' \
    --message '{role: user, content: "<deposition text>"}' \
    --temperature 0.3 \
    --max-tokens 2000
  ```

  ```typescript title="Typescript" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  const response = await client.llm.v1.chat.createCompletion({
    model: 'anthropic/claude-sonnet-4.5',
    messages: [
      {
        role: 'system',
        content: `Summarize depositions with:
  1. Key admissions
  2. Timeline of events
  3. Credibility issues
  4. Contradictions with other testimony`
      },
      { role: 'user', content: depositionText }
    ],
    temperature: 0.3,
    max_tokens: 2000
  });
  ```

  ```python title="Python" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  response = client.llm.v1.chat.create_completion(
      model='anthropic/claude-sonnet-4.5',
      messages=[
          {
              'role': 'system',
              'content': 'Summarize depositions with:\n1. Key admissions\n2. Timeline of events\n3. Credibility issues\n4. Contradictions with other testimony'
          },
          {'role': 'user', 'content': deposition_text}
      ],
      temperature=0.3,
      max_tokens=2000
  )
  ```

  ```go title="Go" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  resp, _ := client.Llm.V1.Chat.NewCompletion(ctx, casedev.LlmV1ChatNewCompletionParams{
  	Model: casedev.F("anthropic/claude-sonnet-4.5"),
  	Messages: casedev.F([]casedev.LlmV1ChatNewCompletionParamsMessage{
  		{
  			Role:    casedev.F(casedev.LlmV1ChatNewCompletionParamsMessagesRoleSystem),
  			Content: casedev.F("Summarize depositions with:\n1. Key admissions\n2. Timeline of events\n3. Credibility issues\n4. Contradictions with other testimony"),
  		},
  		{
  			Role:    casedev.F(casedev.LlmV1ChatNewCompletionParamsMessagesRoleUser),
  			Content: casedev.F(depositionText),
  		},
  	}),
  	Temperature: casedev.F(0.3),
  	MaxTokens:   casedev.F(int64(2000)),
  })
  fmt.Println(resp.Choices[0].Message.Content)
  ```
</CodeGroup>

### Contract clause extraction

<CodeGroup>
  ```bash title="CLI" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  casedev llm:v1:chat create-completion \
    --model openai/gpt-4o \
    --message '{role: system, content: "Extract all indemnification clauses. Return JSON: [{clause_text, page, party_protected}]"}' \
    --message '{role: user, content: "<contract text>"}' \
    --temperature 0
  ```

  ```typescript title="Typescript" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  const response = await client.llm.v1.chat.createCompletion({
    model: 'openai/gpt-4o',
    messages: [
      {
        role: 'system',
        content: 'Extract all indemnification clauses. Return JSON: [{clause_text, page, party_protected}]'
      },
      { role: 'user', content: contractText }
    ],
    temperature: 0
  });
  ```

  ```python title="Python" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  response = client.llm.v1.chat.create_completion(
      model='openai/gpt-4o',
      messages=[
          {
              'role': 'system',
              'content': 'Extract all indemnification clauses. Return JSON: [{clause_text, page, party_protected}]'
          },
          {'role': 'user', 'content': contract_text}
      ],
      temperature=0
  )
  ```

  ```go title="Go" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  resp, _ := client.Llm.V1.Chat.NewCompletion(ctx, casedev.LlmV1ChatNewCompletionParams{
  	Model: casedev.F("openai/gpt-4o"),
  	Messages: casedev.F([]casedev.LlmV1ChatNewCompletionParamsMessage{
  		{
  			Role:    casedev.F(casedev.LlmV1ChatNewCompletionParamsMessagesRoleSystem),
  			Content: casedev.F("Extract all indemnification clauses. Return JSON: [{clause_text, page, party_protected}]"),
  		},
  		{
  			Role:    casedev.F(casedev.LlmV1ChatNewCompletionParamsMessagesRoleUser),
  			Content: casedev.F(contractText),
  		},
  	}),
  	Temperature: casedev.F(0.0),
  })
  fmt.Println(resp.Choices[0].Message.Content)
  ```
</CodeGroup>

### Medical record review

<CodeGroup>
  ```bash title="CLI" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  casedev llm:v1:chat create-completion \
    --model anthropic/claude-opus-4 \
    --message '{role: system, content: "You are a medical-legal expert. Identify standard-of-care deviations and timeline inconsistencies."}' \
    --message '{role: user, content: "<medical records>"}' \
    --max-tokens 5000
  ```

  ```typescript title="Typescript" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  const response = await client.llm.v1.chat.createCompletion({
    model: 'anthropic/claude-opus-4',
    messages: [
      {
        role: 'system',
        content: 'You are a medical-legal expert. Identify standard-of-care deviations and timeline inconsistencies.'
      },
      { role: 'user', content: medicalRecords }
    ],
    max_tokens: 5000
  });
  ```

  ```python title="Python" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  response = client.llm.v1.chat.create_completion(
      model='anthropic/claude-opus-4',
      messages=[
          {
              'role': 'system',
              'content': 'You are a medical-legal expert. Identify standard-of-care deviations and timeline inconsistencies.'
          },
          {'role': 'user', 'content': medical_records}
      ],
      max_tokens=5000
  )
  ```

  ```go title="Go" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  resp, _ := client.Llm.V1.Chat.NewCompletion(ctx, casedev.LlmV1ChatNewCompletionParams{
  	Model: casedev.F("anthropic/claude-opus-4"),
  	Messages: casedev.F([]casedev.LlmV1ChatNewCompletionParamsMessage{
  		{
  			Role:    casedev.F(casedev.LlmV1ChatNewCompletionParamsMessagesRoleSystem),
  			Content: casedev.F("You are a medical-legal expert. Identify standard-of-care deviations and timeline inconsistencies."),
  		},
  		{
  			Role:    casedev.F(casedev.LlmV1ChatNewCompletionParamsMessagesRoleUser),
  			Content: casedev.F(medicalRecords),
  		},
  	}),
  	MaxTokens: casedev.F(int64(5000)),
  })
  fmt.Println(resp.Choices[0].Message.Content)
  ```
</CodeGroup>
