MCPcopy
hub / github.com/1rgs/claude-code-proxy / create_message

Function create_message

server.py:1215–1564  ·  view source on GitHub ↗
(request: MessagesRequest, raw_request: Request)

Source from the content-addressed store, hash-verified

1213
1214@app.post("/v1/messages")
1215async def create_message(request: MessagesRequest, raw_request: Request):
1216 try:
1217 # print the body here
1218 body = await raw_request.body()
1219
1220 # Parse the raw body as JSON since it's bytes
1221 body_json = json.loads(body.decode("utf-8"))
1222 original_model = body_json.get("model", "unknown")
1223
1224 # Get the display name for logging, just the model name without provider prefix
1225 display_model = original_model
1226 if "/" in display_model:
1227 display_model = display_model.split("/")[-1]
1228
1229 # Clean model name for capability check
1230 clean_model = request.model
1231 if clean_model.startswith("anthropic/"):
1232 clean_model = clean_model[len("anthropic/") :]
1233 elif clean_model.startswith("openai/"):
1234 clean_model = clean_model[len("openai/") :]
1235
1236 logger.debug(
1237 f"📊 PROCESSING REQUEST: Model={request.model}, Stream={request.stream}"
1238 )
1239
1240 # Convert Anthropic request to LiteLLM format
1241 litellm_request = convert_anthropic_to_litellm(request)
1242
1243 # Determine which API key to use based on the model
1244 if request.model.startswith("openai/"):
1245 litellm_request["api_key"] = OPENAI_API_KEY
1246 # Use custom OpenAI base URL if configured
1247 if OPENAI_BASE_URL:
1248 litellm_request["api_base"] = OPENAI_BASE_URL
1249 logger.debug(
1250 f"Using OpenAI API key and custom base URL {OPENAI_BASE_URL} for model: {request.model}"
1251 )
1252 else:
1253 logger.debug(f"Using OpenAI API key for model: {request.model}")
1254 elif request.model.startswith("gemini/"):
1255 if USE_VERTEX_AUTH:
1256 litellm_request["vertex_project"] = VERTEX_PROJECT
1257 litellm_request["vertex_location"] = VERTEX_LOCATION
1258 litellm_request["custom_llm_provider"] = "vertex_ai"
1259 logger.debug(
1260 f"Using Gemini ADC with project={VERTEX_PROJECT}, location={VERTEX_LOCATION} and model: {request.model}"
1261 )
1262 else:
1263 litellm_request["api_key"] = GEMINI_API_KEY
1264 logger.debug(f"Using Gemini API key for model: {request.model}")
1265 else:
1266 litellm_request["api_key"] = ANTHROPIC_API_KEY
1267 logger.debug(f"Using Anthropic API key for model: {request.model}")
1268
1269 # For OpenAI models - modify request format to work with limitations
1270 if "openai" in litellm_request["model"] and "messages" in litellm_request:
1271 logger.debug(f"Processing OpenAI model request: {litellm_request['model']}")
1272

Callers

nothing calls this directly

Calls 5

log_request_beautifullyFunction · 0.85
handle_streamingFunction · 0.85
sanitize_for_jsonFunction · 0.85

Tested by

no test coverage detected