Cognition

Cognition

Cognition은 SWE 코딩 모델을 OpenAI 호환 API로 제공해요.

출처: 문서

본문

개요 (Overview)

속성 설명
설명 Cognition이 OpenAI 호환 API로 SWE 코딩 모델을 서빙
LiteLLM 라우트 cognition/
공급자 문서 Cognition Documentation
기본 Base URL https://api.cognition.ai/v1
지원 작업 /chat/completions, LiteLLM의 Anthropic Messages 어댑터를 통한 /messages

Cognition은 generic OpenAI 호환 라우트가 아니라 LiteLLM에서 자체 공급자이므로, 지출이 Cognition 비용 맵 항목에서 가격이 책정되고 OpenAI 트래픽과 합쳐지지 않고 cognition으로 보고돼요.

API 키

import os

os.environ["COGNITION_API_KEY"] = "your-api-key"
os.environ["COGNITION_API_BASE"] = "https://api.cognition.ai/v1"  # optional override

모델 (Models)

모델 입력 / 1M 토큰 출력 / 1M 토큰 캐시 읽기 / 1M 토큰
cognition/swe-1.7 $0.50 $2.50 $0.20
cognition/swe-1.7-lightning $2.50 $12.50 $1.00
cognition/swe-1.6 $0.50 $2.50 $0.20

가격은 Cognition 모델 목록을 따르며, swe-1.7은 표준 등급, swe-1.7-lightning은 Cerebras 서빙 등급으로 초당 약 1000 토큰으로 답하고 5배 비용이 들어요. 계약 가격이 다르면 배포에 input_cost_per_token/output_cost_per_token을 설정하고 그 값이 비용 맵을 오버라이드해요.

LiteLLM Python SDK 사용법

Chat Completions

import os
from litellm import completion

os.environ["COGNITION_API_KEY"] = "your-api-key"

response = completion(
    model="cognition/swe-1.7",
    messages=[{"role": "user", "content": "Write a python function that reverses a string"}],
)
print(response.choices[0].message.content)

스트리밍

import os
from litellm import completion

os.environ["COGNITION_API_KEY"] = "your-api-key"

response = completion(
    model="cognition/swe-1.7",
    messages=[{"role": "user", "content": "Explain a binary search in two sentences"}],
    stream=True,
)

for chunk in response:
    print(chunk)

Tool Calling

import os
from litellm import completion

os.environ["COGNITION_API_KEY"] = "your-api-key"

tools = [
    {
        "type": "function",
        "function": {
            "name": "run_tests",
            "description": "Run the test suite for a package",
            "parameters": {
                "type": "object",
                "properties": {"package": {"type": "string", "description": "Package name"}},
                "required": ["package"],
            },
        },
    }
]

response = completion(
    model="cognition/swe-1.7",
    messages=[{"role": "user", "content": "Run the tests for the billing package"}],
    tools=tools,
    tool_choice="auto",
)
print(response.choices[0].message.tool_calls)

LiteLLM Proxy 사용법

config.yaml:

model_list:
  - model_name: swe-1.7
    litellm_params:
      model: cognition/swe-1.7
      api_key: os.environ/COGNITION_API_KEY

general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY

Proxy 시작:

export COGNITION_API_KEY="your-api-key"
export LITELLM_MASTER_KEY="sk-…"
litellm --config config.yaml --port 4000
# RUNNING on http://0.0.0.0:4000

OpenAI SDK:

from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:4000",
    api_key="sk-…",
)

response = client.chat.completions.create(
    model="swe-1.7",
    messages=[{"role": "user", "content": "hello from litellm"}],
)
print(response.choices[0].message.content)

cURL:

curl http://localhost:4000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $LITEL..._KEY" \
  -d '{
    "model": "swe-1.7",
    "messages": [{"role": "user", "content": "hello from litellm"}]
  }'

Admin UI에서도 추가할 수 있어요: Models → Add Model → 공급자로 Cognition 선택 → cognition/ 모델 중 하나 선택 → 키 붙여넣기.

Anthropic Messages 호환성

LiteLLM은 Anthropic Messages 형태의 요청을 SDK facade와 proxy의 /v1/messages 엔드포인트를 모두 통해 Cognition chat completions로 변환해요.

curl http://localhost:4000/v1/messages \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $LITEL..._KEY" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "swe-1.7",
    "max_tokens": 128,
    "messages": [{"role": "user", "content": "hello from litellm"}]
  }'

비용 추적 (Cost Tracking)

cognition/ 모델은 LiteLLM의 모델 비용 맵에 등록돼 있으므로 요청별 지출이 자동 계산되고 x-litellm-response-cost 응답 헤더로 반환되며 provider cognition 아래 spend 로그에 기록돼요. OpenAI에 대해 구성된 할인과 보고서는 이 트래픽에 적용되지 않아요.

사용자 지정 엔드포인트를 쓰려면:

model_list:
  - model_name: swe-1.7
    litellm_params:
      model: cognition/swe-1.7
      api_base: https://your-cognition-endpoint/v1
      api_key: os.environ/COGNITION_API_KEY

더 알아보기 (Learn more)