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

# OpenAI SDK

> Use the OpenAI Python or JavaScript SDK with Concentrate Responses and Chat Completions.

Set the official OpenAI SDK's key to your Concentrate API key and its base URL to `https://api.concentrate.ai/v1`. You can then call the [Responses API](/docs/api-reference/endpoint/create-response) or [Chat Completions API](/docs/api-reference/endpoint/chat-completions) with Concentrate model IDs.

## Install

<CodeGroup>
  ```bash Python theme={null}
  pip install openai
  ```

  ```bash JavaScript theme={null}
  npm install openai
  ```
</CodeGroup>

Set `CONCENTRATE_API_KEY` in your environment. Keep it on your server; do not expose it in browser code.

## Make a response

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

  client = OpenAI(
      api_key=os.environ["CONCENTRATE_API_KEY"],
      base_url="https://api.concentrate.ai/v1",
  )

  response = client.responses.create(
      model="deepseek-v4-1-flash",
      input="Say hello in one sentence.",
  )
  print(response.output_text)
  ```

  ```javascript JavaScript theme={null}
  import OpenAI from "openai";

  const client = new OpenAI({
    apiKey: process.env.CONCENTRATE_API_KEY,
    baseURL: "https://api.concentrate.ai/v1",
  });

  const response = await client.responses.create({
    model: "deepseek-v4-1-flash",
    input: "Say hello in one sentence.",
  });
  console.log(response.output_text);
  ```
</CodeGroup>

The examples below reuse the `client` configured above.

## Stream text

<CodeGroup>
  ```python Python theme={null}
  stream = client.responses.create(
      model="deepseek-v4-1-flash",
      input="Tell me a short story.",
      stream=True,
  )
  for event in stream:
      if event.type == "response.output_text.delta":
          print(event.delta, end="", flush=True)
  ```

  ```javascript JavaScript theme={null}
  const stream = await client.responses.create({
    model: "deepseek-v4-1-flash",
    input: "Tell me a short story.",
    stream: true,
  });
  for await (const event of stream) {
    if (event.type === "response.output_text.delta") {
      process.stdout.write(event.delta);
    }
  }
  ```
</CodeGroup>

## Call a function

Define a function and ask the model to call it. Your app reads the arguments and runs the function.

<CodeGroup>
  ```python Python theme={null}
  import json

  response = client.responses.create(
      model="deepseek-v4-1-flash",
      input="Use get_weather for Paris.",
      tools=[{
          "type": "function",
          "name": "get_weather",
          "description": "Get weather for a city",
          "parameters": {
              "type": "object",
              "properties": {"city": {"type": "string"}},
              "required": ["city"],
          },
      }],
      tool_choice={"type": "function", "name": "get_weather"},
  )
  call = next(item for item in response.output if item.type == "function_call")
  print(json.loads(call.arguments)["city"])
  ```

  ```javascript JavaScript theme={null}
  const response = await client.responses.create({
    model: "deepseek-v4-1-flash",
    input: "Use get_weather for Paris.",
    tools: [{
      type: "function",
      name: "get_weather",
      description: "Get weather for a city",
      parameters: {
        type: "object",
        properties: { city: { type: "string" } },
        required: ["city"],
      },
    }],
    tool_choice: { type: "function", name: "get_weather" },
  });
  const call = response.output.find((item) => item.type === "function_call");
  console.log(JSON.parse(call.arguments).city);
  ```
</CodeGroup>

See [tool calling](/docs/api-reference/endpoint/tool-calling) for sending a function result back to the model.

## Get structured JSON

<CodeGroup>
  ```python Python theme={null}
  import json

  response = client.responses.create(
      model="deepseek-v4-1-flash",
      input="Return JSON with status set to ready.",
      text={"format": {
          "type": "json_schema",
          "name": "status_result",
          "strict": True,
          "schema": {
              "type": "object",
              "properties": {"status": {"type": "string"}},
              "required": ["status"],
              "additionalProperties": False,
          },
      }},
  )
  print(json.loads(response.output_text)["status"])
  ```

  ```javascript JavaScript theme={null}
  const response = await client.responses.create({
    model: "deepseek-v4-1-flash",
    input: "Return JSON with status set to ready.",
    text: { format: {
      type: "json_schema",
      name: "status_result",
      strict: true,
      schema: {
        type: "object",
        properties: { status: { type: "string" } },
        required: ["status"],
        additionalProperties: false,
      },
    } },
  });
  console.log(JSON.parse(response.output_text).status);
  ```
</CodeGroup>

## Explore more

* Use `client.chat.completions.create(...)` if your app uses [Chat Completions](/docs/api-reference/endpoint/chat-completions).
* Send images with [multimodal input](/docs/api-reference/endpoint/multi-modal).
* Discover model IDs with [List models](/docs/api-reference/endpoint/list-models).
