> For the complete documentation index, see [llms.txt](https://docs.kodesage.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.kodesage.ai/api/implementation-examples.md).

# Implementation Examples

See real-world implementation examples for the Kodesage Chat API including sample code in multiple languages and integration patterns.

**Example 1:** Simple question

<sup>**Request:**</sup>

```
curl -X POST "https://your-kodesage-instance.com/api/projects/01K5BQSXND0N595C18DJMVN4VA/v1/chat/completions" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
    "messages": [
      {
        "role": "user",
        "content": "How is user authentication implemented?"
      }
  ]
}'
```

<sup>**Response:**</sup>

<pre><code>{
    "choices": [
      {
        "index": 0,
        "message": {
<strong>          "role": "assistant",
</strong>          "content": "According to WebSecurityConfig.java, the project uses Spring Security with a custom CosmossAuthenticationProvider..."
         }
      }
   ]
}
</code></pre>

**Example 2:** Multi-turn conversation

<sup>**Request:**</sup>

```
curl -X POST "https://your-kodesage-instance.com/api/projects/01K5BQSXND0N595C18DJMVN4VA/v1/chat/completions" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
    "messages": [
     {
       "role": "user",
       "content": "What database is used?"
     },
     {
       "role": "assistant",
       "content": "The project uses PostgreSQL as described in application.properties..."
     },
     {
       "role": "user",
       "content": "What is the connection pool configuration?"
     }
  ]
}'
```

The API is compatible with official OpenAI client libraries. This means you can use standard OpenAI SDKs with just a custom base URL.

**Quick Start (Python and C#)**

Below you will find minimal working examples for both Python and C# using the official OpenAI SDKs.

**Python example**

```
from openai import OpenAI

client = OpenAI(
    api_key=KODESAGE_API_TOKEN",
    base_url="https://your-kodesage-instance.com/api/projects/YOUR_PROJECT_ID/v1"
)

completion = client.chat.completions.create(
    model="not-used", # Model parameter is ignored by Kodesage
    messages=[
        {"role": "user","content": "What programming languages are used in this project?"}
    ]
)

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

**C# (.NET) Example**

```
using OpenAI;
using OpenAI.Chat;

ChatClient client = new(
    model: "not-used", // Model parameter is ignored by Kodesage
    credential: new ApiKeyCredential(Environment.GetEnvironmentVariable("KODESAGE_API_TOKEN")),
    options: new OpenAIClientOptions()
    {
        Endpoint = new Uri("https://your-kodesage-instance.com/api/projects/YOUR_PROJECT_ID/v1")
    }
);

ChatCompletion completion = client.CompleteChat("What programming languages are used in this project?");
Console.WriteLine($"[ASSISTANT]: {completion.Content[0].Text}");
```

**Error handling**

<sup>**Error Response Format**</sup>

All errors return a JSON object with an error field:

```
{
    "detail": {
        "error": {
            "message": "Error description",
            "type": "error_type",
            "code": "error_code"
        }
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.kodesage.ai/api/implementation-examples.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
