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

# Quickstart

> Use select open-weight models hosted by Relace

## Overview

In addition to our purpose-built code models, we host our set of preferred open-weight models for coding tasks. You can hit these models directly through our **OpenAI-compatible API**. For discounted reserve rates, reach out to [info@relace.ai](mailto:info@relace.ai).

All hosted models are served from `https://models.relace.ai` and authenticate with your regular Relace API key -- no separate setup, and any OpenAI SDK works by pointing it at our base URL.

| Model                  | Slug                                 | Context | Input         | Output       | Cached Input  |
| ---------------------- | ------------------------------------ | ------- | ------------- | ------------ | ------------- |
| DeepSeek V4 Flash 0731 | `deepseek-ai/DeepSeek-V4-Flash-0731` | 1M      | \$0.065 / M   | \$0.18 / M   | \$0.016 / M   |
| Kimi K3                | `moonshotai/kimi-k3`                 | 1M      | \$3.00 / M    | \$15.00 / M  | \$0.30 / M    |
| GLM 5.3 Flash          | `z-ai/glm-5.3-flash`                 | 1M      | \$0.07125 / M | \$0.2375 / M | \$0.01425 / M |

## Prerequisites

* [Sign up](https://app.relace.ai) for a Relace account.
* Create an [API key](https://app.relace.ai/settings/api-keys).

<Steps>
  <Step title="Call Chat Completions">
    Send requests to `/v1/chat/completions` with the model ID of your choice. The endpoint is OpenAI-compatible, so you can use the OpenAI SDK directly.

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

      client = OpenAI(
          api_key="[YOUR_API_KEY]",
          base_url="https://models.relace.ai/v1",
      )

      response = client.chat.completions.create(
          model="deepseek-ai/DeepSeek-V4-Flash-0731",
          messages=[
              {"role": "user", "content": "Write a binary search in Python."}
          ],
      )

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

      ```typescript TypeScript theme={null}
      import OpenAI from "openai";

      const client = new OpenAI({
        apiKey: "[YOUR_API_KEY]",
        baseURL: "https://models.relace.ai/v1"
      });

      const response = await client.chat.completions.create({
        model: "deepseek-ai/DeepSeek-V4-Flash-0731",
        messages: [
          { role: "user", content: "Write a binary search in Python." }
        ]
      });

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

      ```bash cURL theme={null}
      curl https://models.relace.ai/v1/chat/completions \
        -H "Authorization: Bearer $RELACE_API_KEY" \
        -H "Content-Type: application/json" \
        -d '{
          "model": "deepseek-ai/DeepSeek-V4-Flash-0731",
          "messages": [
            {"role": "user", "content": "Write a binary search in Python."}
          ]
        }'
      ```
    </CodeGroup>

    Tool calling, JSON mode, structured outputs, and the standard sampling parameters (`temperature`, `top_p`, `stop`, etc.) work as they do with any OpenAI-compatible provider.
  </Step>

  <Step title="Stream Responses">
    Set `stream: true` to receive tokens as they are generated. Token usage is always reported in the final chunk of the stream.

    ```python theme={null}
    stream = client.chat.completions.create(
        model="moonshotai/kimi-k3",
        messages=[
            {"role": "user", "content": "Explain the actor model in one paragraph."}
        ],
        stream=True,
    )

    for chunk in stream:
        if chunk.choices and chunk.choices[0].delta.content:
            print(chunk.choices[0].delta.content, end="")
        if chunk.usage:
            print(f"\n\nTokens used: {chunk.usage.total_tokens}")
    ```
  </Step>
</Steps>

## Anthropic-Compatible API

The same models are also served at `/v1/messages` in the [Anthropic Messages](/api-reference/open-models/messages) dialect, so an Anthropic SDK works by pointing it at `https://models.relace.ai`. Content blocks, tool use, streaming, and extended thinking map onto the same model features as Chat Completions; pick whichever dialect your client already speaks.

<CodeGroup>
  ```python Python theme={null}
  from anthropic import Anthropic

  client = Anthropic(
      api_key="[YOUR_API_KEY]",
      base_url="https://models.relace.ai",
  )

  message = client.messages.create(
      model="deepseek-ai/DeepSeek-V4-Flash-0731",
      max_tokens=1024,
      messages=[
          {"role": "user", "content": "Write a binary search in Python."}
      ],
  )

  print(message.content[0].text)
  ```

  ```typescript TypeScript theme={null}
  import Anthropic from "@anthropic-ai/sdk";

  const client = new Anthropic({
    apiKey: "[YOUR_API_KEY]",
    baseURL: "https://models.relace.ai"
  });

  const message = await client.messages.create({
    model: "deepseek-ai/DeepSeek-V4-Flash-0731",
    max_tokens: 1024,
    messages: [
      { role: "user", content: "Write a binary search in Python." }
    ]
  });

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

  ```bash cURL theme={null}
  curl https://models.relace.ai/v1/messages \
    -H "x-api-key: $RELACE_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "deepseek-ai/DeepSeek-V4-Flash-0731",
      "max_tokens": 1024,
      "messages": [
        {"role": "user", "content": "Write a binary search in Python."}
      ]
    }'
  ```
</CodeGroup>

Prompt caching is automatic here too: hits are reported in `usage.cache_read_input_tokens`, and `metadata.user_id` plays the role of `prompt_cache_key` for session affinity.

## Prompt Caching and Session Affinity

Prompt caching is automatic: when a request's prompt shares a prefix with a recent request, the shared tokens are served from cache and billed at the **Cached Input** rate above. There are no cache breakpoints to place. Cache hits are reported in `usage.prompt_tokens_details.cached_tokens`.

Caches are per server, so hit rates depend on requests from the same session routing to the same server. By default, requests are routed on a fingerprint of the conversation's opening messages. To control routing explicitly, set `prompt_cache_key` (the same parameter as OpenAI's): requests with the same key are routed to the same server, even when their prompts differ.

<CodeGroup>
  ```python Python theme={null}
  response = client.chat.completions.create(
      model="deepseek-ai/DeepSeek-V4-Flash-0731",
      messages=messages,
      prompt_cache_key="agent-7f3:session-456",
  )
  ```

  ```typescript TypeScript theme={null}
  const response = await client.chat.completions.create({
    model: "deepseek-ai/DeepSeek-V4-Flash-0731",
    messages: messages,
    prompt_cache_key: "agent-7f3:session-456"
  });
  ```

  ```bash cURL theme={null}
  curl https://models.relace.ai/v1/chat/completions \
    -H "Authorization: Bearer $RELACE_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "deepseek-ai/DeepSeek-V4-Flash-0731",
      "messages": [
        {"role": "user", "content": "Continue our review of auth.py."}
      ],
      "prompt_cache_key": "agent-7f3:session-456"
    }'
  ```
</CodeGroup>

Guidelines:

* Use a stable value per conversation or session, such as a session ID or user ID.
* Don't use a single key for all of your traffic; that concentrates it on one server and lowers your hit rate.
* Affinity is best-effort: under failover or capacity pressure, a request may be served by a different server.

## Usage

Hosted model usage is billed per token at the rates advertised above. Usage appears in your [dashboard](https://app.relace.ai) alongside your other Relace API usage.
